diff --git a/3d-viewer/3d_draw.cpp b/3d-viewer/3d_draw.cpp index fe5488c67e..df70f24b43 100644 --- a/3d-viewer/3d_draw.cpp +++ b/3d-viewer/3d_draw.cpp @@ -92,7 +92,9 @@ void Pcb3D_GLCanvas::Redraw( bool finish ) glRotatef( g_Parm_3D_Visu.m_Rot[2], 0.0, 0.0, 1.0 ); if( m_gllist ) + { glCallList( m_gllist ); + } else { CreateDrawGL_List(); @@ -146,9 +148,8 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List() for( ii = 0; ii < 32; ii++ ) { if( ii < g_Parm_3D_Visu.m_Layers ) - g_Parm_3D_Visu.m_LayerZcoord[ii] = - g_Parm_3D_Visu.m_Epoxy_Width - * ii / (g_Parm_3D_Visu.m_Layers - 1); + g_Parm_3D_Visu.m_LayerZcoord[ii] = g_Parm_3D_Visu.m_Epoxy_Width + * ii / (g_Parm_3D_Visu.m_Layers - 1); else g_Parm_3D_Visu.m_LayerZcoord[ii] = g_Parm_3D_Visu.m_Epoxy_Width; } @@ -277,16 +278,20 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List() for( ii = 0; ii < pcb->GetAreaCount(); ii++ ) { ZONE_CONTAINER* zone = pcb->GetArea( ii ); + if( zone->m_FilledPolysList.size() == 0 ) continue; + if( zone->m_ZoneMinThickness <= 1 ) continue; + int imax = zone->m_FilledPolysList.size() - 1; CPolyPt* firstcorner = &zone->m_FilledPolysList[0]; CPolyPt* begincorner = firstcorner; SEGZONE dummysegment( pcb ); dummysegment.SetLayer( zone->GetLayer() ); dummysegment.m_Width = zone->m_ZoneMinThickness; + for( int ic = 1; ic <= imax; ic++ ) { CPolyPt* endcorner = &zone->m_FilledPolysList[ic]; @@ -312,13 +317,16 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List() Draw3D_Track( &dummysegment ); } + ic++; + if( ic < imax - 1 ) - begincorner = firstcorner = - &zone->m_FilledPolysList[ic]; + begincorner = firstcorner = &zone->m_FilledPolysList[ic]; } else + { begincorner = endcorner; + } } } } @@ -345,6 +353,7 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List() /* draw footprints */ MODULE* Module = pcb->m_Modules; + for( ; Module != NULL; Module = Module->Next() ) { Module->Draw3D( this ); @@ -373,6 +382,7 @@ void Pcb3D_GLCanvas::Draw3D_Track( TRACK* track ) if( layer == LAST_COPPER_LAYER ) layer = g_Parm_3D_Visu.m_Layers - 1; + zpos = g_Parm_3D_Visu.m_LayerZcoord[layer]; SetGLColor( color ); @@ -404,6 +414,7 @@ void Pcb3D_GLCanvas::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone ) if( layer == LAST_COPPER_LAYER ) layer = g_Parm_3D_Visu.m_Layers - 1; + zpos = g_Parm_3D_Visu.m_LayerZcoord[layer]; g_Parm_3D_Visu.m_ActZpos = zpos; @@ -471,16 +482,16 @@ void Pcb3D_GLCanvas::Draw3D_Via( SEGVIA* via ) 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 ) + if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) == false ) continue; + color = g_ColorsSettings.GetLayerColor( layer ); } else { - if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( LAYER_N_FRONT ) == - false ) + if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( LAYER_N_FRONT ) == false ) continue; + color = g_ColorsSettings.GetLayerColor( LAYER_N_FRONT ); } @@ -488,11 +499,14 @@ void Pcb3D_GLCanvas::Draw3D_Via( SEGVIA* via ) // SetGLColor( LIGHTGRAY ); glNormal3f( 0.0, 0.0, (layer == LAYER_N_BACK) ? -1.0 : 1.0 ); + if( layer == LAYER_N_BACK ) zpos = zpos - 5 * g_Parm_3D_Visu.m_BoardScale; else zpos = zpos + 5 * g_Parm_3D_Visu.m_BoardScale; + Draw3D_FilledCircle( x, -y, r, hole, zpos ); + if( layer >= top_layer ) break; } @@ -500,10 +514,8 @@ void Pcb3D_GLCanvas::Draw3D_Via( SEGVIA* via ) // Drawing hole: color = g_ColorsSettings.GetItemColor( VIAS_VISIBLE + via->m_Shape ); SetGLColor( color ); - height = g_Parm_3D_Visu.m_LayerZcoord[top_layer] - - g_Parm_3D_Visu.m_LayerZcoord[bottom_layer]; - Draw3D_FilledCylinder( x, -y, hole, height, - g_Parm_3D_Visu.m_LayerZcoord[bottom_layer] ); + height = g_Parm_3D_Visu.m_LayerZcoord[top_layer] - g_Parm_3D_Visu.m_LayerZcoord[bottom_layer]; + Draw3D_FilledCylinder( x, -y, hole, height, g_Parm_3D_Visu.m_LayerZcoord[bottom_layer] ); } @@ -553,6 +565,7 @@ void Pcb3D_GLCanvas::Draw3D_DrawSegment( DRAWSEGMENT* segment ) { glNormal3f( 0.0, 0.0, Get3DLayerSide( layer ) ); zpos = g_Parm_3D_Visu.m_LayerZcoord[layer]; + if( Get3DLayerEnable( layer ) ) { switch( segment->m_Shape ) @@ -591,8 +604,7 @@ static void Draw3dTextSegm( int x0, int y0, int xf, int yf ) double endx = xf * g_Parm_3D_Visu.m_BoardScale; double endy = yf * g_Parm_3D_Visu.m_BoardScale; - Draw3D_FilledSegment( startx, -starty, endx, -endy, - s_Text3DWidth, s_Text3DZPos ); + Draw3D_FilledSegment( startx, -starty, endx, -endy, s_Text3DWidth, s_Text3DZPos ); } @@ -605,14 +617,15 @@ void Pcb3D_GLCanvas::Draw3D_DrawText( TEXTE_PCB* text ) int color = g_ColorsSettings.GetLayerColor( layer ); - SetGLColor( color ); s_Text3DZPos = g_Parm_3D_Visu.m_LayerZcoord[layer]; s_Text3DWidth = text->m_Thickness * g_Parm_3D_Visu.m_BoardScale; glNormal3f( 0.0, 0.0, Get3DLayerSide( layer ) ); wxSize size = text->m_Size; + if( text->m_Mirror ) NEGATE( size.x ); + if( text->m_MultilineAllowed ) { wxPoint pos = text->m_Pos; @@ -622,6 +635,7 @@ void Pcb3D_GLCanvas::Draw3D_DrawText( TEXTE_PCB* text ) offset.y = text->GetInterline(); RotatePoint( &offset, text->m_Orient ); + for( unsigned i = 0; iCount(); i++ ) { wxString txt = list->Item( i ); @@ -636,12 +650,14 @@ void Pcb3D_GLCanvas::Draw3D_DrawText( TEXTE_PCB* text ) delete (list); } else + { DrawGraphicText( NULL, NULL, text->m_Pos, (EDA_Colors) color, text->m_Text, text->m_Orient, size, text->m_HJustify, text->m_VJustify, text->m_Thickness, text->m_Italic, true, Draw3dTextSegm ); + } } @@ -652,6 +668,7 @@ void MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas ) /* Draw pads */ glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glNormal3f( 0.0, 0.0, 1.0 ); // Normal is Z axis + for( ; pad != NULL; pad = pad->Next() ) { pad->Draw3D( glcanvas ); @@ -679,6 +696,7 @@ void MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas ) glRotatef( 180.0, 0.0, 1.0, 0.0 ); glRotatef( 180.0, 0.0, 0.0, 1.0 ); } + DataScale3D = g_Parm_3D_Visu.m_BoardScale * UNITS3D_TO_UNITSPCB; for( ; Struct3D != NULL; Struct3D = Struct3D->Next() ) @@ -789,7 +807,7 @@ void EDGE_MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas ) default: s.Printf( wxT( "Error: Shape nr %d not implemented!\n" ), m_Shape ); D( printf( "%s", TO_UTF8( s ) ); ) - break; + break; } } } @@ -837,7 +855,7 @@ void EDGE_MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas ) default: s.Printf( wxT( "Error: Shape nr %d not implemented!\n" ), m_Shape ); D( printf( "%s", TO_UTF8( s ) ); ) - break; + break; } } } @@ -889,8 +907,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_Masque_Layer & LAYER_BACK) ? TRUE : FALSE; - Oncmp = (m_Masque_Layer & 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 ) @@ -899,29 +917,35 @@ void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas ) x = xc * scale; y = yc * scale; r = (double) dx * scale; + for( layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; layer++ ) { if( layer && (layer == nlmax) ) layer = LAYER_N_FRONT; + if( (layer == LAYER_N_FRONT) && !Oncmp ) continue; + if( (layer == LAYER_N_BACK) && !Oncu ) continue; - if( (layer > FIRST_COPPER_LAYER) && (layer < LAST_COPPER_LAYER) - && !Both ) + + if( (layer > FIRST_COPPER_LAYER) && (layer < LAST_COPPER_LAYER) && !Both ) continue; + color = g_ColorsSettings.GetLayerColor( layer ); - if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) == - false ) + + if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) == false ) continue; SetGLColor( color ); glNormal3f( 0.0, 0.0, (layer == LAYER_N_BACK) ? -1.0 : 1.0 ); zpos = g_Parm_3D_Visu.m_LayerZcoord[layer]; + if( layer == LAYER_N_BACK ) zpos = zpos - 5 * g_Parm_3D_Visu.m_BoardScale; else zpos = zpos + 5 * g_Parm_3D_Visu.m_BoardScale; + Draw3D_FilledCircle( x, -y, r, hole, zpos ); } @@ -940,42 +964,48 @@ void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas ) delta_cy = dy - dx; w = m_Size.x * scale; } + RotatePoint( &delta_cx, &delta_cy, angle ); + { double ox, oy, fx, fy; ox = (double) ( ux0 + delta_cx ) * scale; oy = (double) ( uy0 + delta_cy ) * scale; fx = (double) ( ux0 - delta_cx ) * scale; fy = (double) ( uy0 - delta_cy ) * scale; - for( layer = FIRST_COPPER_LAYER; - layer <= LAST_COPPER_LAYER; - layer++ ) + + for( layer = FIRST_COPPER_LAYER; layer <= LAST_COPPER_LAYER; layer++ ) { if( layer && (layer == nlmax) ) layer = LAYER_N_FRONT; + if( (layer == LAYER_N_FRONT) && !Oncmp ) continue; + if( (layer == LAYER_N_BACK) && !Oncu ) continue; - if( (layer > FIRST_COPPER_LAYER) - && (layer < LAST_COPPER_LAYER) && !Both ) + + if( (layer > FIRST_COPPER_LAYER) && (layer < LAST_COPPER_LAYER) && !Both ) continue; + color = g_ColorsSettings.GetLayerColor( layer ); glNormal3f( 0.0, 0.0, (layer == LAYER_N_BACK) ? -1.0 : 1.0 ); - if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) == - false ) + + if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) == false ) continue; SetGLColor( color ); zpos = g_Parm_3D_Visu.m_LayerZcoord[layer]; + if( layer == LAYER_N_BACK ) zpos = zpos - 5 * g_Parm_3D_Visu.m_BoardScale; else zpos = zpos + 5 * g_Parm_3D_Visu.m_BoardScale; - Draw3D_FilledSegmentWithHole( ox, -oy, fx, -fy, w, drillx, - -drilly, hole, zpos ); + + Draw3D_FilledSegmentWithHole( ox, -oy, fx, -fy, w, drillx, -drilly, hole, zpos ); } } + break; case PAD_RECT: @@ -984,6 +1014,7 @@ void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas ) wxPoint coord[5]; wxRealPoint fcoord[8], f_hole_coord[8]; BuildPadPolygon( coord, wxSize(0,0), angle ); + for( ii = 0; ii < 4; ii++ ) { coord[ii].x += ux0; @@ -996,8 +1027,10 @@ void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas ) for( ii = 0; ii < 7; ii += 2 ) { ll = ii + 2; + if( ll > 7 ) ll -= 8; + fcoord[ii + 1].x = (fcoord[ii].x + fcoord[ll].x) / 2; fcoord[ii + 1].y = (fcoord[ii].y + fcoord[ll].y) / 2; } @@ -1015,26 +1048,32 @@ void D_PAD::Draw3D( Pcb3D_GLCanvas* glcanvas ) { if( layer && (layer == nlmax) ) layer = LAYER_N_FRONT; + if( (layer == LAYER_N_FRONT) && !Oncmp ) continue; + if( (layer == LAYER_N_BACK) && !Oncu ) continue; - if( (layer > FIRST_COPPER_LAYER) && (layer < LAST_COPPER_LAYER) - && !Both ) + + if( (layer > FIRST_COPPER_LAYER) && (layer < LAST_COPPER_LAYER) && !Both ) continue; + color = g_ColorsSettings.GetLayerColor( layer ); glNormal3f( 0.0, 0.0, (layer == LAYER_N_BACK) ? -1.0 : 1.0 ); - if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) == - false ) + + if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( layer ) == false ) continue; SetGLColor( color ); zpos = g_Parm_3D_Visu.m_LayerZcoord[layer]; + if( layer == LAYER_N_BACK ) zpos = zpos - 5 * g_Parm_3D_Visu.m_BoardScale; else zpos = zpos + 5 * g_Parm_3D_Visu.m_BoardScale; + glBegin( GL_QUAD_STRIP ); + for( ii = 0; ii < 8; ii++ ) { glVertex3f( f_hole_coord[ii].x, -f_hole_coord[ii].y, zpos ); @@ -1073,6 +1112,7 @@ static void Draw3D_FilledCircle( double posx, double posy, double x, y; glBegin( GL_QUAD_STRIP ); + for( ii = 0; ii <= slice; ii++ ) { x = hole; @@ -1151,6 +1191,7 @@ static void Draw3D_FilledSegment( double startx, double starty, double endx, x += dx; RotatePoint( &x, &y, -angle ); glVertex3f( startx + x, starty + y, zpos ); + if( ii == 0 ) { firstx = startx + x; @@ -1217,6 +1258,7 @@ static void Draw3D_FilledSegmentWithHole( double startx, double starty, RotatePoint( &xin, &yin, -angle ); glVertex3f( startx + xin, starty + yin, zpos ); glVertex3f( startx + x, starty + y, zpos ); + if( ii == 0 ) { firstx = startx + x; @@ -1263,8 +1305,10 @@ static void Draw3D_ArcSegment( double startx, double starty, double centrex, // Calculate the number of segments to approximate this arc int imax = (int) ( (double) arc_angle * slice / 3600.0 ); + if( imax < 0 ) imax = -imax; + if( imax == 0 ) imax = 1; @@ -1273,6 +1317,7 @@ static void Draw3D_ArcSegment( double startx, double starty, double centrex, double delta_angle = (double) arc_angle / imax; glBegin( GL_QUAD_STRIP ); + for( ii = 0; ii <= imax; ii++ ) { double angle = (double) ii * delta_angle; @@ -1301,6 +1346,7 @@ static void Draw3D_CircleSegment( double startx, double starty, double endx, hole = rayon - width; glBegin( GL_QUAD_STRIP ); + for( ii = 0; ii <= slice; ii++ ) { x = hole; y = 0.0; @@ -1339,6 +1385,7 @@ void Pcb3D_GLCanvas::Draw3D_Polygon( std::vector& aCornersList, double // Draw solid polygon gluTessBeginPolygon( tess, NULL ); gluTessBeginContour( tess ); + for( unsigned ii = 0; ii < aCornersList.size(); ii++ ) { v_data[0] = aCornersList[ii].x * g_Parm_3D_Visu.m_BoardScale; @@ -1361,12 +1408,16 @@ static int Get3DLayerEnable( int act_layer ) bool enablelayer; enablelayer = TRUE; + if( act_layer == DRAW_N && !g_Parm_3D_Visu.m_Draw3DDrawings ) enablelayer = FALSE; + if( act_layer == COMMENT_N && !g_Parm_3D_Visu.m_Draw3DComments ) enablelayer = FALSE; + if( act_layer == ECO1_N && !g_Parm_3D_Visu.m_Draw3DEco1 ) enablelayer = FALSE; + if( act_layer == ECO2_N && !g_Parm_3D_Visu.m_Draw3DEco2 ) enablelayer = FALSE; @@ -1379,6 +1430,7 @@ static GLfloat Get3DLayerSide( int act_layer ) GLfloat nZ; nZ = 1.0; + if( ( act_layer <= LAST_COPPER_LAYER - 1 ) || ( act_layer == ADHESIVE_N_BACK ) || ( act_layer == SOLDERPASTE_N_BACK ) diff --git a/cvpcb/setvisu.cpp b/cvpcb/setvisu.cpp index b365e15b13..d3e305b4fb 100644 --- a/cvpcb/setvisu.cpp +++ b/cvpcb/setvisu.cpp @@ -136,12 +136,12 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDrawMode, const wxPoin * but they must exist because they appear in some classes. * Do nothing in CvPcb. */ -TRACK* Marque_Une_Piste( BOARD* aPcb, - TRACK* aStartSegm, - int* aSegmCount, - int* aTrackLen, - int* aLenDie, - bool aReorder ) +TRACK* MarkTrace( BOARD* aPcb, + TRACK* aStartSegm, + int* aSegmCount, + int* aTrackLen, + int* aLenDie, + bool aReorder ) { return NULL; } diff --git a/gerbview/draw_gerber_screen.cpp b/gerbview/draw_gerber_screen.cpp index 386e33cbd5..f267bc047e 100644 --- a/gerbview/draw_gerber_screen.cpp +++ b/gerbview/draw_gerber_screen.cpp @@ -420,12 +420,12 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER&, int ) * but they must exist because they appear in some classes, and here, no nothing. */ -TRACK* Marque_Une_Piste( BOARD* aPcb, - TRACK* aStartSegm, - int* aSegmCount, - int* aTrackLen, - int* aLenDie, - bool aReorder ) +TRACK* MarkTrace( BOARD* aPcb, + TRACK* aStartSegm, + int* aSegmCount, + int* aTrackLen, + int* aLenDie, + bool aReorder ) { return NULL; } diff --git a/include/base_struct.h b/include/base_struct.h index 0c184b1b10..2766636d49 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -1,6 +1,7 @@ -/*********************************************************************/ -/* base_struct.h : Basic classes for most kicad item descriptions */ -/*********************************************************************/ +/** + * @file base_struct.h + * @brief Basic classes for most kicad items. + */ #ifndef BASE_STRUCT_H #define BASE_STRUCT_H @@ -41,7 +42,7 @@ enum KICAD_T { // copper layer) TYPE_MARKER_PCB, // a marker used to show something TYPE_DIMENSION, // a dimension (graphic item) - TYPE_MIRE, // a target (graphic item) + PCB_TARGET_T, // a target (graphic item) TYPE_ZONE_EDGE_CORNER, // in zone outline: a point to define an outline TYPE_ZONE_CONTAINER, // a zone area TYPE_BOARD_ITEM_LIST, // a list of board items diff --git a/include/wxPcbStruct.h b/include/wxPcbStruct.h index 560fd8c547..aa31cc9c82 100644 --- a/include/wxPcbStruct.h +++ b/include/wxPcbStruct.h @@ -28,7 +28,7 @@ class SEGZONE; class SEGVIA; class D_PAD; class TEXTE_MODULE; -class MIREPCB; +class PCB_TARGET; class DIMENSION; class EDGE_MODULE; class DRC; @@ -830,8 +830,8 @@ public: * the case where DRC would not allow a via. */ bool Other_Layer_Route( TRACK* track, wxDC* DC ); - void Affiche_PadsNoConnect( wxDC* DC ); - void Affiche_Status_Net( wxDC* DC ); + void HighlightUnconnectedPads( wxDC* DC ); + void DisplayNetStatus( wxDC* DC ); TRACK* Delete_Segment( wxDC* DC, TRACK* Track ); void Delete_Track( wxDC* DC, TRACK* Track ); void Delete_net( wxDC* DC, TRACK* Track ); @@ -910,7 +910,6 @@ public: void Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC ); void SwitchLayer( wxDC* DC, int layer ); bool Add_45_degrees_Segment( wxDC* DC ); - bool Genere_Pad_Connexion( wxDC* DC, int layer ); /** * Function EraseRedundantTrack @@ -1085,11 +1084,11 @@ public: void Start_Move_Zone_Outlines( wxDC* DC, ZONE_CONTAINER* zone_container ); // Target handling - MIREPCB* Create_Mire( wxDC* DC ); - void Delete_Mire( MIREPCB* MirePcb, wxDC* DC ); - void StartMove_Mire( MIREPCB* MirePcb, wxDC* DC ); - void Place_Mire( MIREPCB* MirePcb, wxDC* DC ); - void InstallMireOptionsFrame( MIREPCB* MirePcb, wxDC* DC ); + PCB_TARGET* CreateTarget( wxDC* DC ); + void DeleteTarget( PCB_TARGET* aTarget, wxDC* DC ); + void BeginMoveTarget( PCB_TARGET* aTarget, wxDC* DC ); + void PlaceTarget( PCB_TARGET* aTarget, wxDC* DC ); + void ShowTargetOptionsDialog( PCB_TARGET* aTarget, wxDC* DC ); // Graphic segments type DRAWSEGMENT handling: DRAWSEGMENT* Begin_DrawSegment( DRAWSEGMENT* Segment, int shape, wxDC* DC ); diff --git a/include/xnode.h b/include/xnode.h index de5b5988bd..7fd3413e40 100644 --- a/include/xnode.h +++ b/include/xnode.h @@ -53,6 +53,12 @@ public: { } + XNODE( XNODE* aParent, wxXmlNodeType aType, const wxString& aName, + const wxString& aContent = wxEmptyString, wxXmlProperty* aProperties = NULL ) : + wxXmlNode( aParent, aType, aName, aContent, aProperties ) + { + } + /** * Function Format * writes this object as UTF8 out to an OUTPUTFORMATTER as an S-expression. diff --git a/pcbnew/attribut.cpp b/pcbnew/attribut.cpp index 5afd30c459..309d092a6e 100644 --- a/pcbnew/attribut.cpp +++ b/pcbnew/attribut.cpp @@ -39,8 +39,8 @@ void PCB_EDIT_FRAME::Attribut_Track( TRACK* track, wxDC* DC, bool Flag_On ) return; DrawPanel->CrossHairOff( DC ); // Erase cursor shape - Track = Marque_Une_Piste( GetBoard(), track, &nb_segm, NULL, NULL, true ); - Trace_Une_Piste( DrawPanel, DC, Track, nb_segm, GR_OR | GR_SURBRILL ); + Track = MarkTrace( GetBoard(), track, &nb_segm, NULL, NULL, true ); + DrawTraces( DrawPanel, DC, Track, nb_segm, GR_OR | GR_SURBRILL ); for( ; (Track != NULL) && (nb_segm > 0); nb_segm-- ) { @@ -74,6 +74,7 @@ void PCB_EDIT_FRAME::Attribut_net( wxDC* DC, int net_code, bool Flag_On ) } DrawPanel->CrossHairOff( DC ); // Erase cursor shape + while( Track ) /* Flag change */ { if( (net_code >= 0 ) && (net_code != Track->GetNet()) ) diff --git a/pcbnew/automove.cpp b/pcbnew/automove.cpp index cda447d3ad..fb1a0b6295 100644 --- a/pcbnew/automove.cpp +++ b/pcbnew/automove.cpp @@ -46,24 +46,32 @@ void PCB_EDIT_FRAME::AutoPlace( wxCommandEvent& event ) { case ID_TOOLBARH_PCB_MODE_MODULE: on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_MODE_MODULE ); + if( on_state ) { - m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_MODE_TRACKS, FALSE ); + m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_MODE_TRACKS, false ); m_HTOOL_current_state = ID_TOOLBARH_PCB_MODE_MODULE; } else + { m_HTOOL_current_state = 0; + } + return; case ID_TOOLBARH_PCB_MODE_TRACKS: on_state = m_HToolBar->GetToolState( ID_TOOLBARH_PCB_MODE_TRACKS ); + if( on_state ) { - m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_MODE_MODULE, FALSE ); + m_HToolBar->ToggleTool( ID_TOOLBARH_PCB_MODE_MODULE, false ); m_HTOOL_current_state = ID_TOOLBARH_PCB_MODE_TRACKS; } else + { m_HTOOL_current_state = 0; + } + return; @@ -75,11 +83,11 @@ void PCB_EDIT_FRAME::AutoPlace( wxCommandEvent& event ) return; case ID_POPUP_PCB_AUTOPLACE_FREE_MODULE: - LockModule( (MODULE*) GetScreen()->GetCurItem(), FALSE ); + LockModule( (MODULE*) GetScreen()->GetCurItem(), false ); return; case ID_POPUP_PCB_AUTOPLACE_FREE_ALL_MODULES: - LockModule( NULL, FALSE ); + LockModule( NULL, false ); return; case ID_POPUP_PCB_AUTOPLACE_FIXE_ALL_MODULES: @@ -91,6 +99,7 @@ void PCB_EDIT_FRAME::AutoPlace( wxCommandEvent& event ) { DrawPanel->m_endMouseCaptureCallback( DrawPanel, &dc ); } + break; default: // Abort a current command (if any) @@ -101,13 +110,13 @@ void PCB_EDIT_FRAME::AutoPlace( wxCommandEvent& event ) /* Erase ratsnest if needed */ if( GetBoard()->IsElementVisible(RATSNEST_VISIBLE) ) DrawGeneralRatsnest( &dc ); + GetBoard()->m_Status_Pcb |= DO_NOT_SHOW_GENERAL_RASTNEST; switch( id ) { case ID_POPUP_PCB_AUTOPLACE_CURRENT_MODULE: - AutoPlaceModule( (MODULE*) GetScreen()->GetCurItem(), - PLACE_1_MODULE, &dc ); + AutoPlaceModule( (MODULE*) GetScreen()->GetCurItem(), PLACE_1_MODULE, &dc ); break; case ID_POPUP_PCB_AUTOPLACE_ALL_MODULES: @@ -123,7 +132,7 @@ void PCB_EDIT_FRAME::AutoPlace( wxCommandEvent& event ) break; case ID_POPUP_PCB_AUTOMOVE_ALL_MODULES: - AutoMoveModulesOnPcb( FALSE ); + AutoMoveModulesOnPcb( false ); break; case ID_POPUP_PCB_AUTOMOVE_NEW_MODULES: @@ -194,11 +203,13 @@ void PCB_EDIT_FRAME::AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb ) // Build sorted footprints list (sort by decreasing size ) MODULE* Module = GetBoard()->m_Modules; + for( ; Module != NULL; Module = Module->Next() ) { - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); moduleList.push_back(Module); } + sort( moduleList.begin(), moduleList.end(), sortModulesbySize ); /* to move modules outside the board, the cursor is placed below @@ -216,14 +227,17 @@ void PCB_EDIT_FRAME::AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb ) /* calculate the area needed by footprints */ surface = 0.0; + for( unsigned ii = 0; ii < moduleList.size(); ii++ ) { Module = moduleList[ii]; + if( PlaceModulesHorsPcb && edgesExists ) { if( GetBoard()->m_BoundaryBox.Contains( Module->m_Pos ) ) continue; } + surface += Module->m_Surface; } @@ -235,6 +249,7 @@ void PCB_EDIT_FRAME::AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb ) for( unsigned ii = 0; ii < moduleList.size(); ii++ ) { Module = moduleList[ii]; + if( Module->IsLocked() ) continue; @@ -253,6 +268,7 @@ void PCB_EDIT_FRAME::AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb ) GetScreen()->SetCrossHairPosition( current + Module->m_Pos - Module->m_BoundaryBox.GetPosition() ); + Ymax_size = MAX( Ymax_size, Module->m_BoundaryBox.GetHeight() ); Place_Module( Module, NULL, true ); @@ -264,8 +280,7 @@ void PCB_EDIT_FRAME::AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb ) } -/* Set or reset (true or FALSE) Lock attribute of aModule - * or all modules if aModule == NULL +/* Set or reset (true or false) Lock attribute of aModule or all modules if aModule == NULL */ void PCB_EDIT_FRAME::LockModule( MODULE* aModule, bool aLocked ) { @@ -279,10 +294,10 @@ void PCB_EDIT_FRAME::LockModule( MODULE* aModule, bool aLocked ) else { aModule = GetBoard()->m_Modules; + for( ; aModule != NULL; aModule = aModule->Next() ) { - if( WildCompareString( ModulesMaskSelection, - aModule->m_Reference->m_Text ) ) + if( WildCompareString( ModulesMaskSelection, aModule->m_Reference->m_Text ) ) { aModule->SetLocked( aLocked ); OnModify(); @@ -296,4 +311,3 @@ static bool sortModulesbySize( MODULE* ref, MODULE* compare ) { return compare->m_Surface < ref->m_Surface; } - diff --git a/pcbnew/autoplac.cpp b/pcbnew/autoplac.cpp index 05e306362d..e01dbfdb42 100644 --- a/pcbnew/autoplac.cpp +++ b/pcbnew/autoplac.cpp @@ -56,7 +56,7 @@ static void TracePenaliteRectangle( BOARD* Pcb, int uy1, int marge, int Penalite, - int masque_layer ); + int aLayerMask ); static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC ); @@ -86,8 +86,10 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) { case PLACE_1_MODULE: ThisModule = Module; + if( ThisModule == NULL ) return; + ThisModule->m_ModuleStatus &= ~(MODULE_is_PLACED | MODULE_to_PLACE); break; @@ -97,11 +99,13 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) case PLACE_ALL: if( !IsOK( this, _( "Footprints NOT LOCKED will be moved" ) ) ) return; + break; case PLACE_INCREMENTAL: if( !IsOK( this, _( "Footprints NOT PLACED will be moved" ) ) ) return; + break; } @@ -118,9 +122,10 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) /* Compute module parmeters used in auto place */ Module = GetBoard()->m_Modules; NbTotalModules = 0; + for( ; Module != NULL; Module = Module->Next() ) { - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); NbTotalModules ++; } @@ -128,6 +133,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) return; Module = GetBoard()->m_Modules; + for( ; Module != NULL; Module = Module->Next() ) { Module->m_ModuleStatus &= ~MODULE_to_PLACE; @@ -141,16 +147,21 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) case PLACE_OUT_OF_BOARD: Module->m_ModuleStatus &= ~MODULE_is_PLACED; + if( Module->m_ModuleStatus & MODULE_is_LOCKED ) break; + if( !GetBoard()->m_BoundaryBox.Contains( Module->m_Pos ) ) Module->m_ModuleStatus |= MODULE_to_PLACE; + break; case PLACE_ALL: Module->m_ModuleStatus &= ~MODULE_is_PLACED; + if( Module->m_ModuleStatus & MODULE_is_LOCKED ) break; + Module->m_ModuleStatus |= MODULE_to_PLACE; break; @@ -159,8 +170,10 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) { Module->m_ModuleStatus &= ~MODULE_is_PLACED; break; } + if( !(Module->m_ModuleStatus & MODULE_is_PLACED) ) Module->m_ModuleStatus |= MODULE_to_PLACE; + break; } @@ -181,6 +194,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) if( NbModules ) Pas = 100.0 / (float) NbModules; + while( ( Module = PickModule( this, DC ) ) != NULL ) { float BestScore; @@ -192,6 +206,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) error = RecherchePlacementModule( Module, DC ); BestScore = MinCout; PosOK = CurrPosition; + if( error == ESC ) goto end_of_tst; @@ -202,9 +217,10 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) { int Angle_Rot_Module = 1800; Rotate_Module( DC, Module, Angle_Rot_Module, false ); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); error = RecherchePlacementModule( Module, DC ); MinCout *= OrientPenality[ii]; + if( BestScore > MinCout ) /* This orientation is best. */ { PosOK = CurrPosition; @@ -215,18 +231,21 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) Angle_Rot_Module = -1800; Rotate_Module( DC, Module, Angle_Rot_Module, false ); } + if( error == ESC ) goto end_of_tst; } /* Determine if the best orientation of a module is 90. */ ii = Module->m_CntRot90 & 0x0F; + if( ii != 0 ) { int Angle_Rot_Module = 900; Rotate_Module( DC, Module, Angle_Rot_Module, false ); error = RecherchePlacementModule( Module, DC ); MinCout *= OrientPenality[ii]; + if( BestScore > MinCout ) /* This orientation is best. */ { PosOK = CurrPosition; @@ -237,18 +256,21 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) Angle_Rot_Module = -900; Rotate_Module( DC, Module, Angle_Rot_Module, false ); } + if( error == ESC ) goto end_of_tst; } /* Determine if the best orientation of a module is 270. */ ii = (Module->m_CntRot90 >> 4 ) & 0x0F; + if( ii != 0 ) { int Angle_Rot_Module = 2700; Rotate_Module( DC, Module, Angle_Rot_Module, false ); error = RecherchePlacementModule( Module, DC ); MinCout *= OrientPenality[ii]; + if( BestScore > MinCout ) /* This orientation is best. */ { PosOK = CurrPosition; @@ -259,6 +281,7 @@ void PCB_EDIT_FRAME::AutoPlaceModule( MODULE* Module, int place_mode, wxDC* DC ) Angle_Rot_Module = -2700; Rotate_Module( DC, Module, Angle_Rot_Module, false ); } + if( error == ESC ) goto end_of_tst; } @@ -274,7 +297,7 @@ end_of_tst: Place_Module( Module, DC ); GetScreen()->SetCrossHairPosition( CurrPosition ); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); GenModuleOnBoard( Module ); Module->m_ModuleStatus |= MODULE_is_PLACED; @@ -289,15 +312,15 @@ end_of_tst: Route_Layer_BOTTOM = lay_tmp_BOTTOM; Module = GetBoard()->m_Modules; + for( ; Module != NULL; Module = Module->Next() ) { - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); } GetBoard()->m_Status_Pcb = 0; Compile_Ratsnest( DC, true ); DrawPanel->ReDraw( DC, true ); - DrawPanel->m_AbortEnable = false; } @@ -309,14 +332,14 @@ void PCB_EDIT_FRAME::DrawInfoPlace( wxDC* DC ) MATRIX_CELL top_state, bottom_state; GRSetDrawMode( DC, GR_COPY ); + for( ii = 0; ii < Board.m_Nrows; ii++ ) { oy = GetBoard()->m_BoundaryBox.m_Pos.y + ( ii * Board.m_GridRouting ); for( jj = 0; jj < Board.m_Ncols; jj++ ) { - ox = GetBoard()->m_BoundaryBox.m_Pos.x + - (jj * Board.m_GridRouting); + ox = GetBoard()->m_BoundaryBox.m_Pos.x + (jj * Board.m_GridRouting); color = BLACK; top_state = GetCell( ii, jj, TOP ); @@ -328,12 +351,10 @@ void PCB_EDIT_FRAME::DrawInfoPlace( wxDC* DC ) /* obstacles */ if( ( top_state & CELL_is_EDGE ) || ( bottom_state & CELL_is_EDGE ) ) color = WHITE; - else if( top_state & ( HOLE | CELL_is_MODULE ) ) color = LIGHTRED; else if( bottom_state & (HOLE | CELL_is_MODULE) ) color = LIGHTGREEN; - else /* Display the filling and keep out regions. */ { if( GetDist( ii, jj, TOP ) || GetDist( ii, jj, BOTTOM ) ) @@ -419,8 +440,10 @@ int PCB_EDIT_FRAME::GenPlaceBoard() MsgPanel->SetMessage( 24, wxT( "Mem(Kb)" ), msg, CYAN ); Route_Layer_BOTTOM = LAYER_N_FRONT; + if( Nb_Sides == TWO_SIDES ) Route_Layer_BOTTOM = LAYER_N_BACK; + Route_Layer_TOP = LAYER_N_FRONT; /* Place the edge layer segments */ @@ -430,6 +453,7 @@ int PCB_EDIT_FRAME::GenPlaceBoard() TmpSegm.SetLayer( -1 ); TmpSegm.SetNet( -1 ); TmpSegm.m_Width = Board.m_GridRouting / 2; + for( ; PtStruct != NULL; PtStruct = PtStruct->Next() ) { DRAWSEGMENT* DrawSegm; @@ -438,6 +462,7 @@ int PCB_EDIT_FRAME::GenPlaceBoard() { case TYPE_DRAWSEGMENT: DrawSegm = (DRAWSEGMENT*) PtStruct; + if( DrawSegm->GetLayer() != EDGE_N ) break; @@ -485,7 +510,7 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module ) { int ox, oy, fx, fy, Penalite; int marge = Board.m_GridRouting / 2; - int masque_layer; + int layerMask; D_PAD* Pad; ox = Module->m_BoundaryBox.m_Pos.x - marge; @@ -495,31 +520,37 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module ) if( ox < GetBoard()->m_BoundaryBox.m_Pos.x ) ox = GetBoard()->m_BoundaryBox.m_Pos.x; + if( ox > GetBoard()->m_BoundaryBox.GetRight() ) ox = GetBoard()->m_BoundaryBox.GetRight(); if( fx < GetBoard()->m_BoundaryBox.m_Pos.x ) fx = GetBoard()->m_BoundaryBox.m_Pos.x; + if( fx > GetBoard()->m_BoundaryBox.GetRight() ) fx = GetBoard()->m_BoundaryBox.GetRight(); if( oy < GetBoard()->m_BoundaryBox.m_Pos.y ) oy = GetBoard()->m_BoundaryBox.m_Pos.y; + if( oy > GetBoard()->m_BoundaryBox.GetBottom() ) oy = GetBoard()->m_BoundaryBox.GetBottom(); if( fy < GetBoard()->m_BoundaryBox.m_Pos.y ) fy = GetBoard()->m_BoundaryBox.m_Pos.y; + if( fy > GetBoard()->m_BoundaryBox.GetBottom() ) fy = GetBoard()->m_BoundaryBox.GetBottom(); - masque_layer = 0; - if( Module->GetLayer() == LAYER_N_FRONT ) - masque_layer = LAYER_FRONT; - if( Module->GetLayer() == LAYER_N_BACK ) - masque_layer = LAYER_BACK; + layerMask = 0; - TraceFilledRectangle( GetBoard(), ox, oy, fx, fy, masque_layer, + if( Module->GetLayer() == LAYER_N_FRONT ) + layerMask = LAYER_FRONT; + + if( Module->GetLayer() == LAYER_N_BACK ) + layerMask = LAYER_BACK; + + TraceFilledRectangle( GetBoard(), ox, oy, fx, fy, layerMask, CELL_is_MODULE, WRITE_OR_CELL ); int trackWidth = GetBoard()->m_NetClasses.GetDefault()->GetTrackWidth(); @@ -530,15 +561,13 @@ void PCB_EDIT_FRAME::GenModuleOnBoard( MODULE* Module ) for( Pad = Module->m_Pads; Pad != NULL; Pad = Pad->Next() ) { - Place_1_Pad_Board( GetBoard(), Pad, CELL_is_MODULE, marge, - WRITE_OR_CELL ); + Place_1_Pad_Board( GetBoard(), Pad, CELL_is_MODULE, marge, WRITE_OR_CELL ); } /* Trace clearance. */ - marge = (Board.m_GridRouting * Module->m_PadNum ) / GAIN; + marge = ( Board.m_GridRouting * Module->m_PadNum ) / GAIN; Penalite = PENALITE; - TracePenaliteRectangle( GetBoard(), ox, oy, fx, fy, marge, Penalite, - masque_layer ); + TracePenaliteRectangle( GetBoard(), ox, oy, fx, fy, marge, Penalite, layerMask ); } @@ -588,23 +617,25 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC ) * appearing on the other side. */ TstOtherSide = false; + if( Nb_Sides == TWO_SIDES ) { - D_PAD* Pad; int masque_otherlayer; - masque_otherlayer = LAYER_BACK; + D_PAD* Pad; + int otherLayerMask = LAYER_BACK; + if( Module->GetLayer() == LAYER_N_BACK ) - masque_otherlayer = LAYER_FRONT; + otherLayerMask = LAYER_FRONT; for( Pad = Module->m_Pads; Pad != NULL; Pad = Pad->Next() ) { - if( ( Pad->m_Masque_Layer & masque_otherlayer ) == 0 ) + if( ( Pad->m_layerMask & otherLayerMask ) == 0 ) continue; + TstOtherSide = true; break; } } - DrawModuleOutlines( DrawPanel, DC, Module ); mincout = -1.0; @@ -614,6 +645,7 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC ) CurrPosition.x += Board.m_GridRouting ) { wxYield(); + if( DrawPanel->m_AbortRequest ) { if( IsOK( this, _( "Ok to abort?" ) ) ) @@ -640,8 +672,10 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC ) { /* Erase traces. */ DrawModuleOutlines( DrawPanel, DC, Module ); + if( DisplayChevelu ) Compute_Ratsnest_PlaceModule( DC ); + DisplayChevelu = 0; Module->m_BoundaryBox.m_Pos.x = ox + CurrPosition.x; Module->m_BoundaryBox.m_Pos.y = oy + CurrPosition.y; @@ -649,6 +683,7 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC ) g_Offset_Module.y = cy - CurrPosition.y; DrawModuleOutlines( DrawPanel, DC, Module ); Penalite = TstModuleOnBoard( GetBoard(), Module, TstOtherSide ); + if( Penalite >= 0 ) /* c a d if the module can be placed. */ { error = 0; @@ -669,13 +704,16 @@ int PCB_EDIT_FRAME::RecherchePlacementModule( MODULE* Module, wxDC* DC ) SetStatusText( msg ); } } + if( DisplayChevelu ) Compute_Ratsnest_PlaceModule( DC ); + DisplayChevelu = 0; } } DrawModuleOutlines( DrawPanel, DC, Module ); /* erasing the last traces */ + if( DisplayChevelu ) Compute_Ratsnest_PlaceModule( DC ); @@ -711,18 +749,24 @@ int TstRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, int side ) row_max = uy1 / Board.m_GridRouting; col_max = ux1 / Board.m_GridRouting; row_min = uy0 / Board.m_GridRouting; + if( uy0 > row_min * Board.m_GridRouting ) row_min++; + col_min = ux0 / Board.m_GridRouting; + if( ux0 > col_min * Board.m_GridRouting ) col_min++; if( row_min < 0 ) row_min = 0; + if( row_max >= ( Nrows - 1 ) ) row_max = Nrows - 1; + if( col_min < 0 ) col_min = 0; + if( col_max >= ( Ncols - 1 ) ) col_max = Ncols - 1; @@ -731,8 +775,10 @@ int TstRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, int side ) for( col = col_min; col <= col_max; col++ ) { data = GetCell( row, col, side ); + if( ( data & CELL_is_ZONE ) == 0 ) return OUT_OF_BOARD; + if( data & CELL_is_MODULE ) return OCCUPED_By_MODULE; } @@ -761,22 +807,29 @@ unsigned int CalculePenaliteRectangle( BOARD* Pcb, int ux0, int uy0, row_max = uy1 / Board.m_GridRouting; col_max = ux1 / Board.m_GridRouting; row_min = uy0 / Board.m_GridRouting; + if( uy0 > row_min * Board.m_GridRouting ) row_min++; + col_min = ux0 / Board.m_GridRouting; + if( ux0 > col_min * Board.m_GridRouting ) col_min++; if( row_min < 0 ) row_min = 0; + if( row_max >= ( Nrows - 1 ) ) row_max = Nrows - 1; + if( col_min < 0 ) col_min = 0; + if( col_max >= ( Ncols - 1 ) ) col_max = Ncols - 1; Penalite = 0; + for( row = row_min; row <= row_max; row++ ) { for( col = col_min; col <= col_max; col++ ) @@ -799,6 +852,7 @@ int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide ) int error, Penalite, marge, side, otherside; side = TOP; otherside = BOTTOM; + if( Module->GetLayer() == LAYER_N_BACK ) { side = BOTTOM; otherside = TOP; @@ -810,12 +864,14 @@ int TstModuleOnBoard( BOARD* Pcb, MODULE* Module, bool TstOtherSide ) fy = Module->m_BoundaryBox.GetBottom(); error = TstRectangle( Pcb, ox, oy, fx, fy, side ); + if( error < 0 ) return error; if( TstOtherSide ) { error = TstRectangle( Pcb, ox, oy, fx, fy, otherside ); + if( error < 0 ) return error; } @@ -843,15 +899,18 @@ float PCB_EDIT_FRAME::Compute_Ratsnest_PlaceModule( wxDC* DC ) if( ( GetBoard()->m_Status_Pcb & RATSNEST_ITEM_LOCAL_OK ) == 0 ) return -1; + cout = 0; int color = g_ColorsSettings.GetItemColor(RATSNEST_VISIBLE); if( AutoPlaceShowAll ) GRSetDrawMode( DC, GR_XOR ); + for( unsigned ii = 0; ii < GetBoard()->m_LocalRatsnest.size(); ii++ ) { RATSNEST_ITEM* pt_local_chevelu = &GetBoard()->m_LocalRatsnest[ii]; + if( !( pt_local_chevelu->m_Status & LOCAL_RATSNEST_ITEM ) ) { ox = pt_local_chevelu->m_PadStart->GetPosition().x - @@ -863,8 +922,7 @@ float PCB_EDIT_FRAME::Compute_Ratsnest_PlaceModule( wxDC* DC ) if( AutoPlaceShowAll ) { - GRLine( &DrawPanel->m_ClipBox, DC, ox, oy, fx, fy, - 0, color ); + GRLine( &DrawPanel->m_ClipBox, DC, ox, oy, fx, fy, 0, color ); } /* Cost of the ratsnest. */ @@ -901,7 +959,7 @@ float PCB_EDIT_FRAME::Compute_Ratsnest_PlaceModule( wxDC* DC ) * Cell outside this rectangle, but inside the rectangle * x0,y0 -marge to x1,y1 + marge sont incrementede by a decreasing value * (Penalite ... 0). The decreasing value de pends on the distance to the first rectangle - * Therefore the cost is hight in rect x0,y0 a x1,y1, and decrease outside this rectangle + * Therefore the cost is high in rect x0,y0 a x1,y1, and decrease outside this rectangle */ static void TracePenaliteRectangle( BOARD* Pcb, int ux0, @@ -910,7 +968,7 @@ static void TracePenaliteRectangle( BOARD* Pcb, int uy1, int marge, int Penalite, - int masque_layer ) + int aLayerMask ) { int row, col; int row_min, row_max, col_min, col_max, pmarge; @@ -918,10 +976,10 @@ static void TracePenaliteRectangle( BOARD* Pcb, DIST_CELL data, LocalPenalite; int lgain, cgain; - if( masque_layer & g_TabOneLayerMask[Route_Layer_BOTTOM] ) + if( aLayerMask & g_TabOneLayerMask[Route_Layer_BOTTOM] ) trace = 1; /* Trace on bottom layer. */ - if( ( masque_layer & g_TabOneLayerMask[Route_Layer_TOP] ) && Nb_Sides ) + if( ( aLayerMask & g_TabOneLayerMask[Route_Layer_TOP] ) && Nb_Sides ) trace |= 2; /* Trace on top layer. */ if( trace == 0 ) @@ -942,24 +1000,31 @@ static void TracePenaliteRectangle( BOARD* Pcb, row_max = uy1 / Board.m_GridRouting; col_max = ux1 / Board.m_GridRouting; row_min = uy0 / Board.m_GridRouting; + if( uy0 > row_min * Board.m_GridRouting ) row_min++; + col_min = ux0 / Board.m_GridRouting; + if( ux0 > col_min * Board.m_GridRouting ) col_min++; if( row_min < 0 ) row_min = 0; + if( row_max >= (Nrows - 1) ) row_max = Nrows - 1; + if( col_min < 0 ) col_min = 0; + if( col_max >= (Ncols - 1) ) col_max = Ncols - 1; for( row = row_min; row <= row_max; row++ ) { lgain = 256; + if( row < pmarge ) lgain = ( 256 * row ) / pmarge; else if( row > row_max - pmarge ) @@ -969,19 +1034,23 @@ static void TracePenaliteRectangle( BOARD* Pcb, { cgain = 256; LocalPenalite = Penalite; + if( col < pmarge ) cgain = ( 256 * col ) / pmarge; else if( col > col_max - pmarge ) cgain = ( 256 * ( col_max - col ) ) / pmarge; cgain = ( cgain * lgain ) / 256; + if( cgain != 256 ) LocalPenalite = ( LocalPenalite * cgain ) / 256; + if( trace & 1 ) { data = GetDist( row, col, BOTTOM ) + LocalPenalite; SetDist( row, col, BOTTOM, data ); } + if( trace & 2 ) { data = GetDist( row, col, TOP ); @@ -1025,27 +1094,29 @@ static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) // Build sorted footprints list (sort by decreasing size ) Module = pcbframe->GetBoard()->m_Modules; + for( ; Module != NULL; Module = Module->Next() ) { - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); moduleList.push_back(Module); } + sort( moduleList.begin(), moduleList.end(), Tri_PlaceModules ); for( unsigned ii = 0; ii < moduleList.size(); ii++ ) { Module = moduleList[ii]; Module->flag = 0; + if( !( Module->m_ModuleStatus & MODULE_to_PLACE ) ) continue; + pcbframe->GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK; Module->DisplayInfo( pcbframe ); pcbframe->build_ratsnest_module( Module ); /* Calculate external ratsnet. */ - for( unsigned ii = 0; - ii < pcbframe->GetBoard()->m_LocalRatsnest.size(); - ii++ ) + for( unsigned ii = 0; ii < pcbframe->GetBoard()->m_LocalRatsnest.size(); ii++ ) { if( ( pcbframe->GetBoard()->m_LocalRatsnest[ii].m_Status & LOCAL_RATSNEST_ITEM ) == 0 ) @@ -1060,14 +1131,19 @@ static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) /* Search for "best" module. */ MODULE* bestModule = NULL; MODULE* altModule = NULL; + for( unsigned ii = 0; ii < moduleList.size(); ii++ ) { Module = moduleList[ii]; + if( !( Module->m_ModuleStatus & MODULE_to_PLACE ) ) continue; + altModule = Module; + if( Module->flag == 0 ) continue; + bestModule = Module; break; } @@ -1079,10 +1155,6 @@ static MODULE* PickModule( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) } -/********************************************/ -int Propagation( PCB_EDIT_FRAME* frame ) -/********************************************/ - /** * Function Propagation * Used now only in autoplace calculations @@ -1107,6 +1179,7 @@ int Propagation( PCB_EDIT_FRAME* frame ) * Iterations are made until no cell is added to the zone. * @return: added cells count (i.e. which the attribute CELL_is_ZONE is set) */ +int Propagation( PCB_EDIT_FRAME* frame ) { int row, col, nn; long current_cell, old_cell_H; @@ -1125,22 +1198,25 @@ int Propagation( PCB_EDIT_FRAME* frame ) /* search 1 : from left to right and top to bottom */ memset( pt_cell_V, 0, nn ); + for( row = 0; row < Nrows; row++ ) { old_cell_H = 0; + for( col = 0; col < Ncols; col++ ) { current_cell = GetCell( row, col, BOTTOM ) & NO_CELL_ZONE; + if( current_cell == 0 ) /* a free cell is found */ { - if( (old_cell_H & CELL_is_ZONE) - || (pt_cell_V[col] & CELL_is_ZONE) ) + if( (old_cell_H & CELL_is_ZONE) || (pt_cell_V[col] & CELL_is_ZONE) ) { OrCell( row, col, BOTTOM, CELL_is_ZONE ); current_cell = CELL_is_ZONE; nbpoints++; } } + pt_cell_V[col] = old_cell_H = current_cell; } } @@ -1148,22 +1224,24 @@ int Propagation( PCB_EDIT_FRAME* frame ) /* search 2 : from right to left and top to bottom */ frame->MsgPanel->SetMessage( -1, wxEmptyString, wxT( "2" ), CYAN ); memset( pt_cell_V, 0, nn ); + for( row = 0; row < Nrows; row++ ) { old_cell_H = 0; for( col = Ncols - 1; col >= 0; col-- ) { current_cell = GetCell( row, col, BOTTOM ) & NO_CELL_ZONE; + if( current_cell == 0 ) /* a free cell is found */ { - if( (old_cell_H & CELL_is_ZONE) - || (pt_cell_V[col] & CELL_is_ZONE) ) + if( (old_cell_H & CELL_is_ZONE) || (pt_cell_V[col] & CELL_is_ZONE) ) { OrCell( row, col, BOTTOM, CELL_is_ZONE ); current_cell = CELL_is_ZONE; nbpoints++; } } + pt_cell_V[col] = old_cell_H = current_cell; } } @@ -1171,22 +1249,25 @@ int Propagation( PCB_EDIT_FRAME* frame ) /* search 3 : from bottom to top and right to left balayage */ frame->MsgPanel->SetMessage( -1, wxEmptyString, wxT( "3" ), CYAN ); memset( pt_cell_V, 0, nn ); + for( col = Ncols - 1; col >= 0; col-- ) { old_cell_H = 0; + for( row = Nrows - 1; row >= 0; row-- ) { current_cell = GetCell( row, col, BOTTOM ) & NO_CELL_ZONE; + if( current_cell == 0 ) /* a free cell is found */ { - if( (old_cell_H & CELL_is_ZONE) - || (pt_cell_V[row] & CELL_is_ZONE) ) + if( (old_cell_H & CELL_is_ZONE) || (pt_cell_V[row] & CELL_is_ZONE) ) { OrCell( row, col, BOTTOM, CELL_is_ZONE ); current_cell = CELL_is_ZONE; nbpoints++; } } + pt_cell_V[row] = old_cell_H = current_cell; } } @@ -1198,19 +1279,21 @@ int Propagation( PCB_EDIT_FRAME* frame ) for( col = 0; col < Ncols; col++ ) { old_cell_H = 0; + for( row = Nrows - 1; row >= 0; row-- ) { current_cell = GetCell( row, col, BOTTOM ) & NO_CELL_ZONE; + if( current_cell == 0 ) /* a free cell is found */ { - if( (old_cell_H & CELL_is_ZONE) - || (pt_cell_V[row] & CELL_is_ZONE) ) + if( (old_cell_H & CELL_is_ZONE) || (pt_cell_V[row] & CELL_is_ZONE) ) { OrCell( row, col, BOTTOM, CELL_is_ZONE ); current_cell = CELL_is_ZONE; nbpoints++; } } + pt_cell_V[row] = old_cell_H = current_cell; } } @@ -1219,4 +1302,3 @@ int Propagation( PCB_EDIT_FRAME* frame ) return nbpoints; } - diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index ecb9503118..07a9fe4185 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -69,7 +69,7 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( wxWindow* father, m_DisplayModEdge = FILLED; // How to display module drawings (line/ filled / sketch) m_DisplayModText = FILLED; // How to display module texts (line/ filled / sketch) - m_DisplayPcbTrackFill = true; /* FALSE = sketch , true = filled */ + m_DisplayPcbTrackFill = true; /* false = sketch , true = filled */ m_Draw3DFrame = NULL; // Display Window in 3D mode (OpenGL) m_ModuleEditFrame = NULL; // Frame for footprint edition diff --git a/pcbnew/block.cpp b/pcbnew/block.cpp index 361ba69e9a..68db54fda7 100644 --- a/pcbnew/block.cpp +++ b/pcbnew/block.cpp @@ -378,7 +378,7 @@ bool PCB_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) */ void PCB_EDIT_FRAME::Block_SelectItems() { - int masque_layer; + int layerMask; GetScreen()->m_BlockLocate.Normalize(); @@ -388,8 +388,7 @@ void PCB_EDIT_FRAME::Block_SelectItems() // Add modules if( blockIncludeModules ) { - for( MODULE* module = m_Pcb->m_Modules; module != NULL; - module = module->Next() ) + for( MODULE* module = m_Pcb->m_Modules; module != NULL; module = module->Next() ) { int layer = module->GetLayer(); @@ -409,8 +408,7 @@ void PCB_EDIT_FRAME::Block_SelectItems() // Add tracks and vias if( blockIncludeTracks ) { - for( TRACK* pt_segm = m_Pcb->m_Track; pt_segm != NULL; - pt_segm = pt_segm->Next() ) + for( TRACK* pt_segm = m_Pcb->m_Track; pt_segm != NULL; pt_segm = pt_segm->Next() ) { if( pt_segm->HitTest( GetScreen()->m_BlockLocate ) ) { @@ -425,16 +423,15 @@ void PCB_EDIT_FRAME::Block_SelectItems() } // Add graphic items - masque_layer = EDGE_LAYER; + layerMask = EDGE_LAYER; if( blockIncludeItemsOnTechLayers ) - masque_layer = ALL_LAYERS; + layerMask = ALL_LAYERS; if( !blockIncludeBoardOutlineLayer ) - masque_layer &= ~EDGE_LAYER; + layerMask &= ~EDGE_LAYER; - for( BOARD_ITEM* PtStruct = m_Pcb->m_Drawings; PtStruct != NULL; - PtStruct = PtStruct->Next() ) + for( BOARD_ITEM* PtStruct = m_Pcb->m_Drawings; PtStruct != NULL; PtStruct = PtStruct->Next() ) { if( !m_Pcb->IsLayerVisible( PtStruct->GetLayer() ) && ! blockIncludeItemsOnInvisibleLayers) continue; @@ -442,7 +439,7 @@ void PCB_EDIT_FRAME::Block_SelectItems() switch( PtStruct->Type() ) { case TYPE_DRAWSEGMENT: - if( (g_TabOneLayerMask[PtStruct->GetLayer()] & masque_layer) == 0 ) + if( (g_TabOneLayerMask[PtStruct->GetLayer()] & layerMask) == 0 ) break; if( !PtStruct->HitTest( GetScreen()->m_BlockLocate ) ) @@ -459,21 +456,23 @@ void PCB_EDIT_FRAME::Block_SelectItems() select_me = true; // This item is in bloc: select it break; - case TYPE_MIRE: - if( ( g_TabOneLayerMask[PtStruct->GetLayer()] & masque_layer ) == 0 ) + case PCB_TARGET_T: + if( ( g_TabOneLayerMask[PtStruct->GetLayer()] & layerMask ) == 0 ) break; if( !PtStruct->HitTest( GetScreen()->m_BlockLocate ) ) break; + select_me = true; // This item is in bloc: select it break; case TYPE_DIMENSION: - if( ( g_TabOneLayerMask[PtStruct->GetLayer()] & masque_layer ) == 0 ) + if( ( g_TabOneLayerMask[PtStruct->GetLayer()] & layerMask ) == 0 ) break; if( !PtStruct->HitTest( GetScreen()->m_BlockLocate ) ) break; + select_me = true; // This item is in bloc: select it break; @@ -517,9 +516,11 @@ static void drawPickedItems( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint aOffset PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent(); g_Offset_Module = -aOffset; + for( unsigned ii = 0; ii < itemsList->GetCount(); ii++ ) { BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii ); + switch( item->Type() ) { case TYPE_MODULE: @@ -531,7 +532,7 @@ static void drawPickedItems( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint aOffset case TYPE_TEXTE: case TYPE_TRACK: case TYPE_VIA: - case TYPE_MIRE: + case PCB_TARGET_T: case TYPE_DIMENSION: // Currently markers are not affected by block commands case TYPE_MARKER_PCB: item->Draw( aPanel, aDC, GR_XOR, aOffset ); @@ -600,6 +601,7 @@ void PCB_EDIT_FRAME::Block_Delete() { BOARD_ITEM* item = (BOARD_ITEM*) itemsList->GetPickedItem( ii ); itemsList->SetPickedItemStatus( UR_DELETED, ii ); + switch( item->Type() ) { case TYPE_MODULE: @@ -620,7 +622,7 @@ void PCB_EDIT_FRAME::Block_Delete() case TYPE_TRACK: // a track segment (segment on a copper layer) case TYPE_VIA: // a via (like atrack segment on a copper layer) case TYPE_DIMENSION: // a dimension (graphic item) - case TYPE_MIRE: // a target (graphic item) + case PCB_TARGET_T: // a target (graphic item) item->UnLink(); break; @@ -671,6 +673,7 @@ void PCB_EDIT_FRAME::Block_Rotate() wxASSERT( item ); itemsList->SetPickedItemStatus( UR_ROTATED, ii ); item->Rotate( centre, rotAngle ); + switch( item->Type() ) { case TYPE_MODULE: @@ -687,7 +690,7 @@ void PCB_EDIT_FRAME::Block_Rotate() case TYPE_ZONE_CONTAINER: case TYPE_DRAWSEGMENT: case TYPE_TEXTE: - case TYPE_MIRE: + case PCB_TARGET_T: case TYPE_DIMENSION: break; @@ -736,6 +739,7 @@ void PCB_EDIT_FRAME::Block_Flip() wxASSERT( item ); itemsList->SetPickedItemStatus( UR_FLIPPED, ii ); item->Flip( center ); + switch( item->Type() ) { case TYPE_MODULE: @@ -752,7 +756,7 @@ void PCB_EDIT_FRAME::Block_Flip() case TYPE_ZONE_CONTAINER: case TYPE_DRAWSEGMENT: case TYPE_TEXTE: - case TYPE_MIRE: + case PCB_TARGET_T: case TYPE_DIMENSION: break; @@ -812,7 +816,7 @@ void PCB_EDIT_FRAME::Block_Move() case TYPE_ZONE_CONTAINER: case TYPE_DRAWSEGMENT: case TYPE_TEXTE: - case TYPE_MIRE: + case PCB_TARGET_T: case TYPE_DIMENSION: break; @@ -890,8 +894,7 @@ void PCB_EDIT_FRAME::Block_Duplicate() case TYPE_ZONE_CONTAINER: { - ZONE_CONTAINER* new_zone = - new ZONE_CONTAINER( (BOARD*) item->GetParent() ); + ZONE_CONTAINER* new_zone = new ZONE_CONTAINER( (BOARD*) item->GetParent() ); new_zone->Copy( (ZONE_CONTAINER*) item ); new_zone->m_TimeStamp = GetTimeStamp(); newitem = new_zone; @@ -917,12 +920,12 @@ void PCB_EDIT_FRAME::Block_Duplicate() } break; - case TYPE_MIRE: + case PCB_TARGET_T: { - MIREPCB* new_mire = new MIREPCB( m_Pcb ); - new_mire->Copy( (MIREPCB*) item ); - m_Pcb->Add( new_mire ); - newitem = new_mire; + PCB_TARGET* target = new PCB_TARGET( m_Pcb ); + target->Copy( (PCB_TARGET*) item ); + m_Pcb->Add( target ); + newitem = target; } break; @@ -941,12 +944,12 @@ void PCB_EDIT_FRAME::Block_Duplicate() } if( newitem ) - { - newitem->Move( MoveVector ); - picker.m_PickedItem = newitem; - picker.m_PickedItemType = newitem->Type(); - newList.PushItem( picker ); - } + { + newitem->Move( MoveVector ); + picker.m_PickedItem = newitem; + picker.m_PickedItemType = newitem->Type(); + newList.PushItem( picker ); + } } if( newList.GetCount() ) diff --git a/pcbnew/block_module_editor.cpp b/pcbnew/block_module_editor.cpp index 76712c0575..6e18cace3b 100644 --- a/pcbnew/block_module_editor.cpp +++ b/pcbnew/block_module_editor.cpp @@ -114,13 +114,13 @@ bool FOOTPRINT_EDIT_FRAME::HandleBlockEnd( wxDC* DC ) if( DrawPanel->IsMouseCaptured() ) { - DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, FALSE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false ); DrawPanel->m_mouseCaptureCallback = DrawMovingBlockOutlines; - DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, FALSE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false ); } GetScreen()->m_BlockLocate.m_State = STATE_BLOCK_MOVE; - DrawPanel->Refresh( TRUE ); + DrawPanel->Refresh( true ); } break; @@ -215,7 +215,7 @@ void FOOTPRINT_EDIT_FRAME::HandleBlockPlace( wxDC* DC ) GetScreen()->m_BlockLocate.ClearItemsList(); SaveCopyInUndoList( currentModule, UR_MODEDIT ); MoveMarkedItems( currentModule, GetScreen()->m_BlockLocate.m_MoveVector ); - DrawPanel->Refresh( TRUE ); + DrawPanel->Refresh( true ); break; case BLOCK_COPY: /* Copy */ @@ -366,6 +366,7 @@ void CopyMarkedItems( MODULE* module, wxPoint offset ) { if( pad->m_Selected == 0 ) continue; + pad->m_Selected = 0; D_PAD* NewPad = new D_PAD( module ); NewPad->Copy( pad ); diff --git a/pcbnew/board.cpp b/pcbnew/board.cpp index ba5c8af53c..c7864f5722 100644 --- a/pcbnew/board.cpp +++ b/pcbnew/board.cpp @@ -81,16 +81,19 @@ int MATRIX_ROUTING_HEAD::InitBoard() /* allocate Board & initialize everything to empty */ m_BoardSide[kk] = (MATRIX_CELL*) MyZMalloc( ii * sizeof(MATRIX_CELL) ); + if( m_BoardSide[kk] == NULL ) return -1; /***** allocate Distances *****/ m_DistSide[kk] = (DIST_CELL*) MyZMalloc( ii * sizeof(DIST_CELL) ); + if( m_DistSide[kk] == NULL ) return -1; /***** allocate Dir (chars) *****/ m_DirSide[kk] = (char*) MyZMalloc( ii ); + if( m_DirSide[kk] == NULL ) return -1; } @@ -146,7 +149,7 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) { int ux0 = 0, uy0 = 0, ux1, uy1, dx, dy; int marge, via_marge; - int masque_layer; + int layerMask; // use the default NETCLASS? NETCLASS* nc = aPcb->m_NetClasses.GetDefault(); @@ -167,12 +170,14 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) { Place_1_Pad_Board( aPcb, pad, HOLE, marge, WRITE_CELL ); } + Place_1_Pad_Board( aPcb, pad, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); } // Place outlines of modules on matrix routing, if they are on a copper layer // or on the edge layer TRACK tmpSegm( NULL ); // A dummy track used to create segments. + for( MODULE* module = aPcb->m_Modules; module; module = module->Next() ) { for( BOARD_ITEM* item = module->m_Drawings; item; item = item->Next() ) @@ -184,6 +189,7 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) EDGE_MODULE* edge = (EDGE_MODULE*) item; tmpSegm.SetLayer( edge->GetLayer() ); + if( tmpSegm.GetLayer() == EDGE_N ) tmpSegm.SetLayer( -1 ); @@ -195,8 +201,7 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) tmpSegm.SetNet( -1 ); TraceSegmentPcb( aPcb, &tmpSegm, HOLE, marge, WRITE_CELL ); - TraceSegmentPcb( aPcb, &tmpSegm, VIA_IMPOSSIBLE, via_marge, - WRITE_OR_CELL ); + TraceSegmentPcb( aPcb, &tmpSegm, VIA_IMPOSSIBLE, via_marge, WRITE_OR_CELL ); } break; @@ -218,6 +223,7 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) int type_cell = HOLE; DrawSegm = (DRAWSEGMENT*) item; tmpSegm.SetLayer( DrawSegm->GetLayer() ); + if( DrawSegm->GetLayer() == EDGE_N ) { tmpSegm.SetLayer( -1 ); @@ -258,16 +264,16 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) ux0 -= dx; uy0 -= dy; - masque_layer = g_TabOneLayerMask[PtText->GetLayer()]; + layerMask = g_TabOneLayerMask[PtText->GetLayer()]; TraceFilledRectangle( aPcb, ux0 - marge, uy0 - marge, ux1 + marge, uy1 + marge, (int) (PtText->m_Orient), - masque_layer, HOLE, WRITE_CELL ); + layerMask, HOLE, WRITE_CELL ); TraceFilledRectangle( aPcb, ux0 - via_marge, uy0 - via_marge, ux1 + via_marge, uy1 + via_marge, (int) (PtText->m_Orient), - masque_layer, VIA_IMPOSSIBLE, WRITE_OR_CELL ); + layerMask, VIA_IMPOSSIBLE, WRITE_OR_CELL ); } break; @@ -299,6 +305,7 @@ int Build_Work( BOARD* Pcb ) InitWork(); /* clear work list */ Ntotal = 0; + for( unsigned ii = 0; ii < Pcb->GetRatsnestsCount(); ii++ ) { pt_rats = &Pcb->m_FullRatsnest[ii]; @@ -308,10 +315,13 @@ int Build_Work( BOARD* Pcb ) */ if( (pt_rats->m_Status & CH_ACTIF) == 0 ) continue; + if( pt_rats->m_Status & CH_UNROUTABLE ) continue; + if( (pt_rats->m_Status & CH_ROUTE_REQ) == 0 ) continue; + pt_pad = pt_rats->m_PadStart; current_net_code = pt_pad->GetNet(); @@ -319,6 +329,7 @@ int Build_Work( BOARD* Pcb ) r1 = ( pt_pad->GetPosition().y - Pcb->m_BoundaryBox.m_Pos.y + demi_pas ) / Board.m_GridRouting; + if( r1 < 0 || r1 >= Nrows ) { msg.Printf( wxT( "error : row = %d ( padY %d pcbY %d) " ), r1, @@ -326,8 +337,10 @@ int Build_Work( BOARD* Pcb ) wxMessageBox( msg ); return 0; } + c1 = ( pt_pad->GetPosition().x - Pcb->m_BoundaryBox.m_Pos.x + demi_pas ) / Board.m_GridRouting; + if( c1 < 0 || c1 >= Ncols ) { msg.Printf( wxT( "error : col = %d ( padX %d pcbX %d) " ), c1, @@ -340,6 +353,7 @@ int Build_Work( BOARD* Pcb ) r2 = ( pt_pad->GetPosition().y - Pcb->m_BoundaryBox.m_Pos.y + demi_pas ) / Board.m_GridRouting; + if( r2 < 0 || r2 >= Nrows ) { msg.Printf( wxT( "error : row = %d ( padY %d pcbY %d) " ), r2, @@ -347,8 +361,10 @@ int Build_Work( BOARD* Pcb ) wxMessageBox( msg ); return 0; } + c2 = ( pt_pad->GetPosition().x - Pcb->m_BoundaryBox.m_Pos.x + demi_pas ) / Board.m_GridRouting; + if( c2 < 0 || c2 >= Ncols ) { msg.Printf( wxT( "error : col = %d ( padX %d pcbX %d) " ), c2, diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index 83d57a3946..9da9797922 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -46,9 +46,10 @@ void TransformArcToPolygon( std::vector & aCornerBuffer, int aCircleToSegmentsCount, int aWidth ) { wxPoint arc_start, arc_end; - int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree + int delta = 3600 / aCircleToSegmentsCount; // rotate angle in 0.1 degree arc_end = arc_start = aStart; + if( aArcAngle != 3600 ) { RotatePoint( &arc_end, aCentre, -aArcAngle ); @@ -63,12 +64,13 @@ void TransformArcToPolygon( std::vector & aCornerBuffer, // Compute the ends of segments and creates poly wxPoint curr_end = arc_start; wxPoint curr_start = arc_start; + for( int ii = delta; ii < aArcAngle; ii += delta ) { curr_end = arc_start; RotatePoint( &curr_end, aCentre, -ii ); - TransformRoundedEndsSegmentToPolygon( aCornerBuffer, - curr_start, curr_end, aCircleToSegmentsCount, aWidth ); + TransformRoundedEndsSegmentToPolygon( aCornerBuffer, curr_start, curr_end, + aCircleToSegmentsCount, aWidth ); curr_start = curr_end; } @@ -90,11 +92,10 @@ void TransformArcToPolygon( std::vector & aCornerBuffer, * clearance when the circle is approximated by segment bigger or equal * to the real clearance value (usually near from 1.0) */ -void TEXTE_PCB::TransformShapeWithClearanceToPolygon( - std::vector & aCornerBuffer, - int aClearanceValue, - int aCircleToSegmentsCount, - double aCorrectionFactor ) +void TEXTE_PCB::TransformShapeWithClearanceToPolygon( std::vector & aCornerBuffer, + int aClearanceValue, + int aCircleToSegmentsCount, + double aCorrectionFactor ) { if( GetLength() == 0 ) return; @@ -115,9 +116,7 @@ void TEXTE_PCB::TransformShapeWithClearanceToPolygon( for( int ii = 0; ii < 4; ii++ ) { // Rotate polygon - RotatePoint( &corners[ii].x, &corners[ii].y, - m_Pos.x, m_Pos.y, - m_Orient ); + RotatePoint( &corners[ii].x, &corners[ii].y, m_Pos.x, m_Pos.y, m_Orient ); aCornerBuffer.push_back( corners[ii] ); } @@ -137,32 +136,31 @@ void TEXTE_PCB::TransformShapeWithClearanceToPolygon( * clearance when the circle is approxiamted by segment bigger or equal * to the real clearance value (usually near from 1.0) */ -void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( - std::vector & aCornerBuffer, - int aClearanceValue, - int aCircleToSegmentsCount, - double aCorrectionFactor ) +void DRAWSEGMENT::TransformShapeWithClearanceToPolygon( std::vector & aCornerBuffer, + int aClearanceValue, + int aCircleToSegmentsCount, + double aCorrectionFactor ) { switch( m_Shape ) { case S_CIRCLE: TransformArcToPolygon( aCornerBuffer, m_Start, // Circle centre - m_End, 3600, - aCircleToSegmentsCount, - m_Width + (2 * aClearanceValue) ); + m_End, 3600, + aCircleToSegmentsCount, + m_Width + (2 * aClearanceValue) ); break; case S_ARC: TransformArcToPolygon( aCornerBuffer, m_Start, - m_End, m_Angle, - aCircleToSegmentsCount, - m_Width + (2 * aClearanceValue) ); + m_End, m_Angle, + aCircleToSegmentsCount, + m_Width + (2 * aClearanceValue) ); break; default: - TransformRoundedEndsSegmentToPolygon( - aCornerBuffer, m_Start, m_End, - aCircleToSegmentsCount, m_Width + (2 * aClearanceValue) ); + TransformRoundedEndsSegmentToPolygon( aCornerBuffer, m_Start, m_End, + aCircleToSegmentsCount, + m_Width + (2 * aClearanceValue) ); break; } } @@ -188,17 +186,17 @@ void TRACK:: TransformShapeWithClearanceToPolygon( std:: vector < CPolyPt>& aCor wxPoint corner_position; int ii, angle; int dx = (m_Width / 2) + aClearanceValue; - int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree + int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree switch( Type() ) { case TYPE_VIA: dx = (int) ( dx * aCorrectionFactor ); + for( ii = 0; ii < aCircleToSegmentsCount; ii++ ) { corner_position = wxPoint( dx, 0 ); - RotatePoint( &corner_position.x, &corner_position.y, - (1800 / aCircleToSegmentsCount) ); + RotatePoint( &corner_position.x, &corner_position.y, (1800 / aCircleToSegmentsCount) ); angle = ii * delta; RotatePoint( &corner_position.x, &corner_position.y, angle ); corner_position.x += m_Start.x; @@ -211,11 +209,10 @@ void TRACK:: TransformShapeWithClearanceToPolygon( std:: vector < CPolyPt>& aCor break; default: - TransformRoundedEndsSegmentToPolygon( - aCornerBuffer, - m_Start, m_End, - aCircleToSegmentsCount, - m_Width + ( 2 * aClearanceValue) ); + TransformRoundedEndsSegmentToPolygon( aCornerBuffer, + m_Start, m_End, + aCircleToSegmentsCount, + m_Width + ( 2 * aClearanceValue) ); break; } } @@ -228,7 +225,7 @@ void TransformRoundedEndsSegmentToPolygon( std::vector & aCornerBuffer, int aCircleToSegmentsCount, int aWidth ) { - int rayon = aWidth / 2; + int radius = aWidth / 2; wxPoint endp = aEnd - aStart; // end point coordinate for the same segment starting at (0,0) wxPoint startp = aStart; wxPoint corner; @@ -241,20 +238,21 @@ void TransformRoundedEndsSegmentToPolygon( std::vector & aCornerBuffer, endp = aStart - aEnd; startp = aEnd; } + int delta_angle = ArcTangente( endp.y, endp.x ); // delta_angle is in 0.1 degrees seg_len = (int) sqrt( ( (double) endp.y * endp.y ) + ( (double) endp.x * endp.x ) ); int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree // Compute the outlines of the segment, and creates a polygon - corner = wxPoint( 0, rayon ); + corner = wxPoint( 0, radius ); RotatePoint( &corner, -delta_angle ); corner += startp; polypoint.x = corner.x; polypoint.y = corner.y; aCornerBuffer.push_back( polypoint ); - corner = wxPoint( seg_len, rayon ); + corner = wxPoint( seg_len, radius ); RotatePoint( &corner, -delta_angle ); corner += startp; polypoint.x = corner.x; @@ -264,7 +262,7 @@ void TransformRoundedEndsSegmentToPolygon( std::vector & aCornerBuffer, // add right rounded end: for( int ii = delta; ii < 1800; ii += delta ) { - corner = wxPoint( 0, rayon ); + corner = wxPoint( 0, radius ); RotatePoint( &corner, ii ); corner.x += seg_len; RotatePoint( &corner, -delta_angle ); @@ -274,14 +272,14 @@ void TransformRoundedEndsSegmentToPolygon( std::vector & aCornerBuffer, aCornerBuffer.push_back( polypoint ); } - corner = wxPoint( seg_len, -rayon ); + corner = wxPoint( seg_len, -radius ); RotatePoint( &corner, -delta_angle ); corner += startp; polypoint.x = corner.x; polypoint.y = corner.y; aCornerBuffer.push_back( polypoint ); - corner = wxPoint( 0, -rayon ); + corner = wxPoint( 0, -radius ); RotatePoint( &corner, -delta_angle ); corner += startp; polypoint.x = corner.x; @@ -291,7 +289,7 @@ void TransformRoundedEndsSegmentToPolygon( std::vector & aCornerBuffer, // add left rounded end: for( int ii = delta; ii < 1800; ii += delta ) { - corner = wxPoint( 0, -rayon ); + corner = wxPoint( 0, -radius ); RotatePoint( &corner, ii ); RotatePoint( &corner, -delta_angle ); corner += startp; @@ -326,17 +324,18 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( std:: vector < CPolyPt>& aCor int dx = (m_Size.x / 2) + aClearanceValue; int dy = (m_Size.y / 2) + aClearanceValue; - int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree - wxPoint PadShapePos = ReturnShapePos(); /* Note: for pad having a shape offset, - * the pad position is NOT the shape position */ - wxSize psize = m_Size; /* pad size unsed in RECT and TRAPEZOIDAL pads - * trapezoidal pads are considered as rect pad shape having they boudary box size - */ + int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree + wxPoint PadShapePos = ReturnShapePos(); /* Note: for pad having a shape offset, + * the pad position is NOT the shape position */ + wxSize psize = m_Size; /* pad size unsed in RECT and TRAPEZOIDAL pads + * trapezoidal pads are considered as rect + * pad shape having they boudary box size */ switch( m_PadShape ) { case PAD_CIRCLE: dx = (int) ( dx * aCorrectionFactor ); + for( ii = 0; ii < aCircleToSegmentsCount; ii++ ) { corner_position = wxPoint( dx, 0 ); @@ -360,7 +359,8 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( std:: vector < CPolyPt>& aCor dy = (int) ( dy * aCorrectionFactor ); int angle_pg; // Polygon angle wxPoint shape_offset = wxPoint( 0, dy - dx ); - RotatePoint( &shape_offset, angle ); // Rotating shape offset vector with component + + RotatePoint( &shape_offset, angle ); // Rotating shape offset vector with component for( ii = 0; ii < aCircleToSegmentsCount / 2 + 1; ii++ ) // Half circle end cap... { @@ -434,10 +434,13 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( std:: vector < CPolyPt>& aCor psize.y += ABS( m_DeltaSize.x ); // fall through - case PAD_RECT: // Easy implementation for rectangular cutouts with rounded corners // Easy implementation for rectangular cutouts with rounded corners + case PAD_RECT: + // Easy implementation for rectangular cutouts with rounded corners angle = m_Orient; - int rounding_radius = (int) ( aClearanceValue * aCorrectionFactor ); // Corner rounding radius - int angle_pg; // Polygon increment angle + + // Corner rounding radius + int rounding_radius = (int) ( aClearanceValue * aCorrectionFactor ); + int angle_pg; // Polygon increment angle for( int i = 0; i < aCircleToSegmentsCount / 4 + 1; i++ ) { @@ -449,11 +452,11 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( std:: vector < CPolyPt>& aCor RotatePoint( &corner_position, angle_pg ); // Rounding vector rotation - corner_position -= psize / 2; // Rounding vector + Pad corner offset + corner_position -= psize / 2; // Rounding vector + Pad corner offset RotatePoint( &corner_position, angle ); // Rotate according to module orientation - corner_position += PadShapePos; // Shift origin to position + corner_position += PadShapePos; // Shift origin to position CPolyPt polypoint( corner_position.x, corner_position.y ); aCornerBuffer.push_back( polypoint ); } @@ -471,9 +474,7 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( std:: vector < CPolyPt>& aCor aCornerBuffer.push_back( polypoint ); } - for( int i = 0; - i < aCircleToSegmentsCount / 4 + 1; - i++ ) + for( int i = 0; i < aCircleToSegmentsCount / 4 + 1; i++ ) { corner_position = wxPoint( 0, rounding_radius ); RotatePoint( &corner_position, (1800 / aCircleToSegmentsCount) ); @@ -533,7 +534,8 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( std:: vector < CPolyPt>& aCor * And * nothing else between holes * And - * angles less than 90 deg between 2 consecutive lines in hole outline (sometime occurs without this condition) + * angles less than 90 deg between 2 consecutive lines in hole outline (sometime occurs without + * this condition) * And * a hole above the identical holes * @@ -547,8 +549,8 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( std:: vector < CPolyPt>& aCor * * Note 2: * Trapezoidal pads are not considered here because they are very special case - * and are used in microwave applications and they *DO NOT* have a thermal relief that change the shape - * by creating stubs and destroy their properties. + * and are used in microwave applications and they *DO NOT* have a thermal relief that + * change the shape by creating stubs and destroy their properties. */ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, D_PAD& aPad, @@ -579,6 +581,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, * with a thickness of aMinThicknessValue will increase real thickness by aMinThicknessValue */ aCopperThickness -= aMinThicknessValue; + if( aCopperThickness < 0 ) aCopperThickness = 0; @@ -611,17 +614,20 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, // Crosspoint of thermal spoke sides, the first point of polygon buffer corners_buffer.push_back( wxPoint( copper_thickness.x / 2, copper_thickness.y / 2 ) ); - // Add an intermediate point on spoke sides, to allow a > 90 deg angle between side and first seg of arc approx + // Add an intermediate point on spoke sides, to allow a > 90 deg angle between side + // and first seg of arc approx corner.x = copper_thickness.x / 2; int y = outer_radius - (aThermalGap / 4); corner.y = (int) sqrt( ( ( (double) y * y ) - (double) corner.x * corner.x ) ); + if( aThermalRot != 0 ) corners_buffer.push_back( corner ); // calculate the starting point of the outter arc corner.x = copper_thickness.x / 2; - double dtmp = - sqrt( ( (double) outer_radius * outer_radius ) - ( (double) corner.x * corner.x ) ); + + double dtmp = sqrt( ( (double) outer_radius * outer_radius ) - + ( (double) corner.x * corner.x ) ); corner.y = (int) dtmp; RotatePoint( &corner, 90 ); @@ -638,7 +644,8 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, corners_buffer.push_back( corner_end ); - /* add an intermediate point, to avoid angles < 90 deg between last arc approx line and radius line + /* add an intermediate point, to avoid angles < 90 deg between last arc approx line + * and radius line */ corner.x = corners_buffer[1].y; corner.y = corners_buffer[1].x; @@ -649,10 +656,12 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, // bad filled polygon on some cases, when pads are on a same vertical line // this seems a bug in kbool polygon (exists in 2.0 kbool version) // aThermalRot = 450 (45.0 degrees orientation) seems work fine. - // aThermalRot = 0 with thermal shapes without angle < 90 deg has problems in rare circumstances + // aThermalRot = 0 with thermal shapes without angle < 90 deg has problems in rare + // circumstances. // Note: with the 2 step build ( thermal shapes added after areas are built), 0 seems work int angle_pad = aPad.m_Orient; // Pad orientation int th_angle = aThermalRot; + for( unsigned ihole = 0; ihole < 4; ihole++ ) { for( unsigned ii = 0; ii < corners_buffer.size(); ii++ ) @@ -682,12 +691,14 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, // We want to calculate an oval shape with dx > dy. // if this is not the case, exchange dx and dy, and rotate the shape 90 deg. int supp_angle = 0; + if( dx < dy ) { EXCHG( dx, dy ); supp_angle = 900; EXCHG( copper_thickness.x, copper_thickness.y ); } + int deltasize = dx - dy; // = distance between shape position and the 2 demi-circle ends centre // here we have dx > dy // Radius of outer arcs of the shape: @@ -703,9 +714,8 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, if( copper_thickness.x > deltasize ) // If copper thickness is more than shape offset, we need to calculate arc intercept point. { corner.x = copper_thickness.x / 2; - corner.y = - (int) sqrt( ( (double) outer_radius * outer_radius ) - - ( (double) ( corner.x - delta ) * ( corner.x - deltasize ) ) ); + corner.y = (int) sqrt( ( (double) outer_radius * outer_radius ) - + ( (double) ( corner.x - delta ) * ( corner.x - deltasize ) ) ); corner.x -= deltasize; /* creates an intermediate point, to have a > 90 deg angle @@ -724,7 +734,8 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, corner.x = ( deltasize - copper_thickness.x ) / 2; } - // Add an intermediate point on spoke sides, to allow a > 90 deg angle between side and first seg of arc approx + // Add an intermediate point on spoke sides, to allow a > 90 deg angle between side + // and first seg of arc approx wxPoint last_corner; last_corner.y = copper_thickness.y / 2; int px = outer_radius - (aThermalGap / 4); @@ -745,13 +756,14 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, RotatePoint( &corner, delta ); } - //corners_buffer.push_back(corner + shape_offset); // TODO: about one mil geometry error forms somewhere. + //corners_buffer.push_back(corner + shape_offset); // TODO: about one mil geometry error forms somewhere. corners_buffer.push_back( corner_end + shape_offset ); corners_buffer.push_back( last_corner + shape_offset ); // Enabling the line above shows intersection point. /* Create 2 holes, rotated by pad rotation. */ int angle = aPad.m_Orient + supp_angle; + for( int irect = 0; irect < 2; irect++ ) { for( unsigned ic = 0; ic < corners_buffer.size(); ic++ ) @@ -764,6 +776,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, aCornerBuffer.back().end_contour = true; angle += 1800; // this is calculate hole 3 + if( angle >= 3600 ) angle -= 3600; } @@ -778,6 +791,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, // Now add corner 4 and 2 (2 is the corner 4 rotated by 180 deg angle = aPad.m_Orient + supp_angle; + for( int irect = 0; irect < 2; irect++ ) { for( unsigned ic = 0; ic < corners_buffer.size(); ic++ ) @@ -790,6 +804,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, aCornerBuffer.back().end_contour = true; angle += 1800; + if( angle >= 3600 ) angle -= 3600; } @@ -818,15 +833,17 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, // | | // 1 -------4 - // Modified rectangles with one corner rounded. TODO: merging with oval thermals and possibly round too. + // Modified rectangles with one corner rounded. TODO: merging with oval thermals + // and possibly round too. std::vector corners_buffer; // Polygon buffer as vector int dx = (aPad.m_Size.x / 2) + aThermalGap; // Cutout radius x int dy = (aPad.m_Size.y / 2) + aThermalGap; // Cutout radius y - // The first point of polygon buffer is left lower corner, second the crosspoint of thermal spoke sides, - // the third is upper right corner and the rest are rounding vertices going anticlockwise. Note the inveted Y-axis in CG. + // The first point of polygon buffer is left lower corner, second the crosspoint of + // thermal spoke sides, the third is upper right corner and the rest are rounding + // vertices going anticlockwise. Note the inveted Y-axis in CG. corners_buffer.push_back( wxPoint( -dx, -(aThermalGap / 4 + copper_thickness.y / 2) ) ); // Adds small miters to zone corners_buffer.push_back( wxPoint( -(dx - aThermalGap / 4), -copper_thickness.y / 2 ) ); // fill and spoke corner corners_buffer.push_back( wxPoint( -copper_thickness.x / 2, -copper_thickness.y / 2 ) ); @@ -852,13 +869,14 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, for( unsigned ic = 0; ic < corners_buffer.size(); ic++ ) { wxPoint cpos = corners_buffer[ic]; - RotatePoint( &cpos, angle ); // Rotate according to module orientation - cpos += PadShapePos; // Shift origin to position + RotatePoint( &cpos, angle ); // Rotate according to module orientation + cpos += PadShapePos; // Shift origin to position aCornerBuffer.push_back( CPolyPt( cpos.x, cpos.y ) ); } aCornerBuffer.back().end_contour = true; angle += 1800; // this is calculate hole 3 + if( angle >= 3600 ) angle -= 3600; } @@ -884,6 +902,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, aCornerBuffer.back().end_contour = true; angle += 1800; + if( angle >= 3600 ) angle -= 3600; } diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index 5604cf9ef4..995ae73135 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -16,7 +16,8 @@ * Each PICKED_ITEMS_LIST handle a std::vector of pickers (class ITEM_PICKER), * that store the list of schematic items that are concerned by the command to undo or redo * and is created for each command to undo (handle also a command to redo). - * each picker has a pointer pointing to an item to undo or redo (in fact: deleted, added or modified), + * each picker has a pointer pointing to an item to undo or redo (in fact: deleted, added or + * modified), * and has a pointer to a copy of this item, when this item has been modified * (the old values of parameters are therefore saved) * @@ -49,9 +50,11 @@ * => the copy of item(s) is moved in Undo list * * - add item(s) command - * => The list of item(s) is used to create a deleted list in undo list(same as a delete command) + * => The list of item(s) is used to create a deleted list in undo list(same as a delete + * command) * - * Some block operations that change items can be undoed without memorise items, just the coordiantes of the transform: + * Some block operations that change items can be undoed without memorise items, just the + * coordiantes of the transform: * move list of items (undo/redo is made by moving with the opposite move vector) * mirror (Y) and flip list of items (undo/redo is made by mirror or flip items) * so they are handled specifically. @@ -106,10 +109,6 @@ static bool TestForExistingItem( BOARD* aPcb, BOARD_ITEM* aItem ) } -/**************************************************************/ -void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) -/***************************************************************/ - /** * Function SwapData * Used in undo / redo command: @@ -119,6 +118,7 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) * @param aItem = the item * @param aImage = a copy of the item */ +void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) { if( aItem == NULL || aImage == NULL ) { @@ -173,16 +173,22 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) EXCHG( track->m_Width, image->m_Width ); EXCHG( track->m_Shape, image->m_Shape ); int atmp = track->GetDrillValue(); + if( track->IsDrillDefault() ) atmp = -1; + int itmp = image->GetDrillValue(); + if( image->IsDrillDefault() ) itmp = -1; + EXCHG(itmp, atmp ); + if( atmp > 0 ) track->SetDrillValue( atmp ); else track->SetDrillDefault(); + if( itmp > 0 ) image->SetDrillValue( itmp ); else @@ -203,11 +209,11 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) EXCHG( ( (TEXTE_PCB*) aItem )->m_VJustify, ( (TEXTE_PCB*) aImage )->m_VJustify ); break; - case TYPE_MIRE: - EXCHG( ( (MIREPCB*) aItem )->m_Pos, ( (MIREPCB*) aImage )->m_Pos ); - EXCHG( ( (MIREPCB*) aItem )->m_Width, ( (MIREPCB*) aImage )->m_Width ); - EXCHG( ( (MIREPCB*) aItem )->m_Size, ( (MIREPCB*) aImage )->m_Size ); - EXCHG( ( (MIREPCB*) aItem )->m_Shape, ( (MIREPCB*) aImage )->m_Shape ); + case PCB_TARGET_T: + EXCHG( ( (PCB_TARGET*) aItem )->m_Pos, ( (PCB_TARGET*) aImage )->m_Pos ); + EXCHG( ( (PCB_TARGET*) aItem )->m_Width, ( (PCB_TARGET*) aImage )->m_Width ); + EXCHG( ( (PCB_TARGET*) aItem )->m_Size, ( (PCB_TARGET*) aImage )->m_Size ); + EXCHG( ( (PCB_TARGET*) aItem )->m_Shape, ( (PCB_TARGET*) aImage )->m_Shape ); break; case TYPE_DIMENSION: @@ -217,8 +223,10 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) ( (DIMENSION*) aImage )->SetText( txt ); EXCHG( ( (DIMENSION*) aItem )->m_Width, ( (DIMENSION*) aImage )->m_Width ); EXCHG( ( (DIMENSION*) aItem )->m_Text->m_Size, ( (DIMENSION*) aImage )->m_Text->m_Size ); - EXCHG( ( (DIMENSION*) aItem )->m_Text->m_Thickness, ( (DIMENSION*) aImage )->m_Text->m_Thickness ); - EXCHG( ( (DIMENSION*) aItem )->m_Text->m_Mirror, ( (DIMENSION*) aImage )->m_Text->m_Mirror ); + EXCHG( ( (DIMENSION*) aItem )->m_Text->m_Thickness, + ( (DIMENSION*) aImage )->m_Text->m_Thickness ); + EXCHG( ( (DIMENSION*) aItem )->m_Text->m_Mirror, + ( (DIMENSION*) aImage )->m_Text->m_Mirror ); } break; @@ -230,13 +238,10 @@ void SwapData( BOARD_ITEM* aItem, BOARD_ITEM* aImage ) } -/************************************************************/ -BOARD_ITEM* DuplicateStruct( BOARD_ITEM* aItem ) -/************************************************************/ - /* Routine to create a new copy of given struct. * The new object is not put in list (not linked) */ +BOARD_ITEM* DuplicateStruct( BOARD_ITEM* aItem ) { if( aItem == NULL ) { @@ -295,11 +300,11 @@ BOARD_ITEM* DuplicateStruct( BOARD_ITEM* aItem ) } break; - case TYPE_MIRE: + case PCB_TARGET_T: { - MIREPCB* new_mire = new MIREPCB( aItem->GetParent() ); - new_mire->Copy( (MIREPCB*) aItem ); - return new_mire; + PCB_TARGET* target = new PCB_TARGET( aItem->GetParent() ); + target->Copy( (PCB_TARGET*) aItem ); + return target; } break; @@ -413,6 +418,7 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, { BOARD_ITEM* item = (BOARD_ITEM*) commandToUndo->GetPickedItem( ii ); UNDO_REDO_T command = commandToUndo->GetPickedItemStatus( ii ); + if( command == UR_UNSPECIFIED ) { command = aTypeCommand; @@ -461,7 +467,9 @@ void PCB_EDIT_FRAME::SaveCopyInUndoList( PICKED_ITEMS_LIST& aItemsList, GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList ); } else // Should not occur + { delete commandToUndo; + } } @@ -555,9 +563,8 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed default: { wxString msg; - msg.Printf( wxT( - "PutDataInPreviousState() error (unknown code %X)" ), - aList->GetPickedItemStatus( ii ) ); + msg.Printf( wxT( "PutDataInPreviousState() error (unknown code %X)" ), + aList->GetPickedItemStatus( ii ) ); wxMessageBox( msg ); } break; @@ -573,10 +580,6 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed } -/**********************************************************/ -void PCB_EDIT_FRAME::GetBoardFromUndoList( wxCommandEvent& event ) -/**********************************************************/ - /** * Function GetBoardFromUndoList * Undo the last edition: @@ -584,6 +587,7 @@ void PCB_EDIT_FRAME::GetBoardFromUndoList( wxCommandEvent& event ) * - Get an old version of the board state from Undo list * @return none */ +void PCB_EDIT_FRAME::GetBoardFromUndoList( wxCommandEvent& event ) { if( GetScreen()->GetUndoCommandCount() <= 0 ) return; @@ -630,10 +634,6 @@ void PCB_EDIT_FRAME::GetBoardFromRedoList( wxCommandEvent& event ) } -/***********************************************************************************/ -void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ) -/**********************************************************************************/ - /** * Function ClearUndoORRedoList * free the undo or redo list from List element @@ -645,11 +645,13 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount * items (commands stored in list) are removed from the beginning of the list. * So this function can be called to remove old commands */ +void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ) { if( aItemCount == 0 ) return; unsigned icnt = aList.m_CommandsList.size(); + if( aItemCount > 0 ) icnt = aItemCount; @@ -657,6 +659,7 @@ void PCB_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount { if( aList.m_CommandsList.size() == 0 ) break; + PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0]; aList.m_CommandsList.erase( aList.m_CommandsList.begin() ); diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 85624fba8d..efe493b69b 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -39,8 +39,7 @@ BOARD::BOARD( EDA_ITEM* parent, PCB_BASE_FRAME* frame ) : // progress m_NetInfo = new NETINFO_LIST( this ); // handle nets info list (name, // design constraints .. - m_NetInfo->BuildListOfNets(); // prepare pads and nets lists - // containers. + m_NetInfo->BuildListOfNets(); // prepare pads and nets lists containers. for( int layer = 0; layer < NB_COPPER_LAYERS; ++layer ) { @@ -54,8 +53,7 @@ BOARD::BOARD( EDA_ITEM* parent, PCB_BASE_FRAME* frame ) : // Should user eventually load a board from a disk file, then these // defaults // will get overwritten during load. - m_NetClasses.GetDefault()->SetDescription( - _( "This is the default net class." ) ); + m_NetClasses.GetDefault()->SetDescription( _( "This is the default net class." ) ); m_ViaSizeSelector = 0; m_TrackWidthSelector = 0; @@ -88,6 +86,7 @@ BOARD::~BOARD() delete m_NetInfo; } + /* * Function PushHightLight * save current hight light info for later use @@ -97,6 +96,7 @@ void BOARD::PushHightLight() m_hightLightPrevious = m_hightLight; } + /* * Function PopHightLight * retrieve a previously saved hight light info @@ -107,6 +107,7 @@ void BOARD::PopHightLight() m_hightLightPrevious.Clear(); } + /** * Function SetCurrentNetClass * Must be called after a netclass selection (or after a netclass parameter @@ -134,6 +135,7 @@ bool BOARD::SetCurrentNetClass( const wxString& aNetClassName ) lists_sizes_modified = true; m_ViasDimensionsList.push_back( viadim ); } + if( m_TrackWidthList.size() == 0 ) { lists_sizes_modified = true; @@ -145,14 +147,17 @@ bool BOARD::SetCurrentNetClass( const wxString& aNetClassName ) */ if( m_ViasDimensionsList[0].m_Diameter != netClass->GetViaDiameter() ) lists_sizes_modified = true; + m_ViasDimensionsList[0].m_Diameter = netClass->GetViaDiameter(); if( m_TrackWidthList[0] != netClass->GetTrackWidth() ) lists_sizes_modified = true; + m_TrackWidthList[0] = netClass->GetTrackWidth(); if( m_ViaSizeSelector >= m_ViasDimensionsList.size() ) m_ViaSizeSelector = m_ViasDimensionsList.size(); + if( m_TrackWidthSelector >= m_TrackWidthList.size() ) m_TrackWidthSelector = m_TrackWidthList.size(); @@ -169,9 +174,7 @@ int BOARD::GetBiggestClearanceValue() int clearance = m_NetClasses.GetDefault()->GetClearance(); //Read list of Net Classes - for( NETCLASSES::const_iterator nc = m_NetClasses.begin(); - nc != m_NetClasses.end(); - nc++ ) + for( NETCLASSES::const_iterator nc = m_NetClasses.begin(); nc != m_NetClasses.end(); nc++ ) { NETCLASS* netclass = nc->second; clearance = MAX( clearance, netclass->GetClearance() ); @@ -291,8 +294,7 @@ bool BOARD::SetLayerName( int aLayerIndex, const wxString& aLayerName ) { for( int i = 0; i < NB_COPPER_LAYERS; i++ ) { - if( i != aLayerIndex && IsLayerEnabled( i ) - && NameTemp == m_Layer[i].m_Name ) + if( i != aLayerIndex && IsLayerEnabled( i ) && NameTemp == m_Layer[i].m_Name ) return false; } @@ -314,6 +316,7 @@ LAYER_T BOARD::GetLayerType( int aLayerIndex ) const // in the layer sequence. if( IsLayerEnabled( aLayerIndex ) ) return m_Layer[aLayerIndex].m_Type; + return LT_SIGNAL; } @@ -330,6 +333,7 @@ bool BOARD::SetLayerType( int aLayerIndex, LAYER_T aLayerType ) m_Layer[aLayerIndex].m_Type = aLayerType; return true; } + return false; } @@ -430,6 +434,7 @@ void BOARD::SetVisibleElements( int aMask ) void BOARD::SetVisibleAlls( ) { SetVisibleLayers( FULL_LAYERS ); + /* Call SetElementVisibility for each item, * to ensure specific calculations that can be needed by some items */ @@ -461,14 +466,15 @@ void BOARD::SetElementVisibility( int aPCB_VISIBLE, bool isEnabled ) // so the hide/show option is a per item selection if( IsElementVisible(RATSNEST_VISIBLE) ) { - for( unsigned ii = 0; ii < GetRatsnestsCount(); ii++ ) - m_FullRatsnest[ii].m_Status |= CH_VISIBLE; + for( unsigned ii = 0; ii < GetRatsnestsCount(); ii++ ) + m_FullRatsnest[ii].m_Status |= CH_VISIBLE; } else { for( unsigned ii = 0; ii < GetRatsnestsCount(); ii++ ) m_FullRatsnest[ii].m_Status &= ~CH_VISIBLE; } + break; @@ -541,6 +547,7 @@ int BOARD::GetLayerColor( int aLayer ) return GetColorsSettings()->GetLayerColor( aLayer ); } + /** * Function IsModuleLayerVisible * expects either of the two layers on which a module can reside, and returns @@ -552,10 +559,8 @@ bool BOARD::IsModuleLayerVisible( int layer ) { if( layer==LAYER_N_FRONT ) return IsElementVisible( PCB_VISIBLE(MOD_FR_VISIBLE) ); - else if( layer==LAYER_N_BACK ) return IsElementVisible( PCB_VISIBLE(MOD_BK_VISIBLE) ); - else return true; } @@ -612,6 +617,7 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) m_Modules.PushBack( (MODULE*) aBoardItem ); else m_Modules.PushFront( (MODULE*) aBoardItem ); + aBoardItem->SetParent( this ); // Because the list of pads has changed, reset the status @@ -624,11 +630,12 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) case TYPE_DRAWSEGMENT: case TYPE_TEXTE: case TYPE_EDGE_MODULE: - case TYPE_MIRE: + case PCB_TARGET_T: if( aControl & ADD_APPEND ) m_Drawings.PushBack( aBoardItem ); else m_Drawings.PushFront( aBoardItem ); + aBoardItem->SetParent( this ); break; @@ -636,9 +643,8 @@ void BOARD::Add( BOARD_ITEM* aBoardItem, int aControl ) default: { wxString msg; - msg.Printf( - wxT( "BOARD::Add() needs work: BOARD_ITEM type (%d) not handled" ), - aBoardItem->Type() ); + msg.Printf( wxT( "BOARD::Add() needs work: BOARD_ITEM type (%d) not handled" ), + aBoardItem->Type() ); wxFAIL_MSG( msg ); } break; @@ -697,7 +703,7 @@ BOARD_ITEM* BOARD::Remove( BOARD_ITEM* aBoardItem ) case TYPE_DRAWSEGMENT: case TYPE_TEXTE: case TYPE_EDGE_MODULE: - case TYPE_MIRE: + case PCB_TARGET_T: m_Drawings.Remove( aBoardItem ); break; @@ -774,6 +780,7 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) area = item->GetBoundingBox(); else area.Merge( item->GetBoundingBox() ); + hasItems = true; } @@ -786,6 +793,7 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) area = module->GetBoundingBox(); else area.Merge( module->GetBoundingBox() ); + hasItems = true; } @@ -796,6 +804,7 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) area = track->GetBoundingBox(); else area.Merge( track->GetBoundingBox() ); + hasItems = true; } @@ -806,6 +815,7 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) area = track->GetBoundingBox(); else area.Merge( track->GetBoundingBox() ); + hasItems = true; } @@ -818,6 +828,7 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) area = aZone->GetBoundingBox(); else area.Merge( aZone->GetBoundingBox() ); + area.Merge( aZone->GetBoundingBox() ); hasItems = true; } @@ -836,7 +847,7 @@ bool BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) area.SetOrigin( -m_PcbFrame->GetScreen()->ReturnPageSize().x / 2, -m_PcbFrame->GetScreen()->ReturnPageSize().y / 2 ); area.SetEnd( m_PcbFrame->GetScreen()->ReturnPageSize().x / 2, - m_PcbFrame->GetScreen()->ReturnPageSize().y / 2 ); + m_PcbFrame->GetScreen()->ReturnPageSize().y / 2 ); } } @@ -858,6 +869,7 @@ void BOARD::DisplayInfo( EDA_DRAW_FRAME* frame ) int viasCount = 0; int trackSegmentsCount = 0; + for( BOARD_ITEM* item = m_Track; item; item = item->Next() ) { if( item->Type() == TYPE_VIA ) @@ -914,6 +926,7 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR* inspector, const void* testData, while( !done ) { stype = *p; + switch( stype ) { case TYPE_PCB: @@ -960,7 +973,7 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR* inspector, const void* testData, case TYPE_DRAWSEGMENT: case TYPE_TEXTE: case TYPE_DIMENSION: - case TYPE_MIRE: + case PCB_TARGET_T: result = IterateForward( m_Drawings, inspector, testData, p ); // skip over any types handled in the above call. @@ -971,7 +984,7 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR* inspector, const void* testData, case TYPE_DRAWSEGMENT: case TYPE_TEXTE: case TYPE_DIMENSION: - case TYPE_MIRE: + case PCB_TARGET_T: continue; default: @@ -1041,6 +1054,7 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR* inspector, const void* testData, for( unsigned i = 0; iVisit( inspector, testData, p ); + if( result == SEARCH_QUIT ) break; } @@ -1053,9 +1067,8 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR* inspector, const void* testData, // TYPE_ZONE_CONTAINER are in the m_ZoneDescriptorList std::vector for( unsigned i = 0; i< m_ZoneDescriptorList.size(); ++i ) { - result = m_ZoneDescriptorList[i]->Visit( inspector, - testData, - p ); + result = m_ZoneDescriptorList[i]->Visit( inspector, testData, p ); + if( result == SEARCH_QUIT ) break; } @@ -1108,7 +1121,7 @@ SEARCH_RESULT BOARD::Visit( INSPECTOR* inspector, const void* testData, * D_PAD* pad = (D_PAD*) item; * if( pad->HitTest( refPos ) ) * { - * if( layer_mask & pad->m_Masque_Layer ) + * if( layer_mask & pad->m_layerMask ) * { * found = item; * return SEARCH_QUIT; @@ -1211,6 +1224,7 @@ NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname ) const for( int ii = 1; ii < ncount; ii++ ) { NETINFO_ITEM* item = m_NetInfo->GetNetItem( ii ); + if( item && item->GetNetname() == aNetname ) { return item; @@ -1225,6 +1239,7 @@ NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname ) const // NETINFO_LIST::Build_Pads_Full_List() int imax = ncount - 1; int index = imax; + while( ncount > 0 ) { int ii = ncount; @@ -1234,26 +1249,34 @@ NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname ) const ncount++; NETINFO_ITEM* item = m_NetInfo->GetNetItem( index ); + if( item == NULL ) return NULL; + int icmp = item->GetNetname().Cmp( aNetname ); if( icmp == 0 ) // found ! { return item; } + if( icmp < 0 ) // must search after item { index += ncount; + if( index > imax ) index = imax; + continue; } + if( icmp > 0 ) // must search before item { index -= ncount; + if( index < 1 ) index = 1; + continue; } } @@ -1281,6 +1304,7 @@ MODULE* BOARD::FindModuleByReference( const wxString& aReference ) const found = module; return SEARCH_QUIT; } + return SEARCH_CONTINUE; } } inspector; @@ -1310,8 +1334,7 @@ static bool s_SortByNodes( const NETINFO_ITEM* a, const NETINFO_ITEM* b ) * (i.e. leave the sort by net names) * @return int - net names count. */ -int BOARD::ReturnSortedNetnamesList( wxArrayString& aNames, - bool aSortbyPadsCount ) +int BOARD::ReturnSortedNetnamesList( wxArrayString& aNames, bool aSortbyPadsCount ) { if( m_NetInfo->GetCount() == 0 ) return 0; @@ -1362,18 +1385,18 @@ bool BOARD::Save( FILE* aFile ) const { case TYPE_TEXTE: case TYPE_DRAWSEGMENT: - case TYPE_MIRE: + case PCB_TARGET_T: case TYPE_DIMENSION: if( !item->Save( aFile ) ) goto out; + break; default: // future: throw exception here #if defined(DEBUG) - printf( "BOARD::Save() ignoring m_Drawings type %d\n", - item->Type() ); + printf( "BOARD::Save() ignoring m_Drawings type %d\n", item->Type() ); #endif break; } @@ -1391,6 +1414,7 @@ bool BOARD::Save( FILE* aFile ) const // save the zones fprintf( aFile, "$ZONE\n" ); + for( item = m_Zone; item; item = item->Next() ) if( !item->Save( aFile ) ) goto out; @@ -1427,6 +1451,7 @@ void BOARD::RedrawAreasOutlines( EDA_DRAW_PANEL* panel, wxDC* aDC, int aDrawMode for( int ii = 0; ii < GetAreaCount(); ii++ ) { ZONE_CONTAINER* edge_zone = GetArea( ii ); + if( (aLayer < 0) || ( aLayer == edge_zone->GetLayer() ) ) edge_zone->Draw( panel, aDC, aDrawMode ); } @@ -1445,6 +1470,7 @@ void BOARD::RedrawFilledAreas( EDA_DRAW_PANEL* panel, wxDC* aDC, int aDrawMode, for( int ii = 0; ii < GetAreaCount(); ii++ ) { ZONE_CONTAINER* edge_zone = GetArea( ii ); + if( (aLayer < 0) || ( aLayer == edge_zone->GetLayer() ) ) edge_zone->DrawFilledArea( panel, aDC, aDrawMode ); } @@ -1469,6 +1495,7 @@ ZONE_CONTAINER* BOARD::HitTestForAnyFilledArea( const wxPoint& aRefPos, { if( aEndLayer < 0 ) aEndLayer = aStartLayer; + if( aEndLayer < aStartLayer ) EXCHG( aEndLayer, aStartLayer ); @@ -1476,11 +1503,14 @@ ZONE_CONTAINER* BOARD::HitTestForAnyFilledArea( const wxPoint& aRefPos, { ZONE_CONTAINER* area = m_ZoneDescriptorList[ia]; int layer = area->GetLayer(); + if( (layer < aStartLayer) || (layer > aEndLayer) ) continue; + if( area->GetState( BUSY ) ) // In locate functions we must skip // tagged items with BUSY flag set. continue; + if( area->HitTestFilledArea( aRefPos ) ) return area; } @@ -1514,10 +1544,10 @@ int BOARD::SetAreasNetCodesFromNetNames( void ) continue; } - if( GetArea( ii )->GetNet() != 0 ) // i.e. if this zone is - // connected to a net + if( GetArea( ii )->GetNet() != 0 ) // i.e. if this zone is connected to a net { const NETINFO_ITEM* net = FindNet( GetArea( ii )->m_Netname ); + if( net ) { GetArea( ii )->SetNet( net->GetNet() ); @@ -1555,6 +1585,7 @@ void BOARD::Show( int nestLevel, std::ostream& os ) // specialization of the output: NestedSpace( nestLevel + 1, os ) << "\n"; p = m_Modules; + for( ; p; p = p->Next() ) p->Show( nestLevel + 2, os ); @@ -1562,6 +1593,7 @@ void BOARD::Show( int nestLevel, std::ostream& os ) NestedSpace( nestLevel + 1, os ) << "\n"; p = m_Drawings; + for( ; p; p = p->Next() ) p->Show( nestLevel + 2, os ); @@ -1569,6 +1601,7 @@ void BOARD::Show( int nestLevel, std::ostream& os ) NestedSpace( nestLevel + 1, os ) << "\n"; p = m_Track; + for( ; p; p = p->Next() ) p->Show( nestLevel + 2, os ); @@ -1576,6 +1609,7 @@ void BOARD::Show( int nestLevel, std::ostream& os ) NestedSpace( nestLevel + 1, os ) << "\n"; p = m_Zone; + for( ; p; p = p->Next() ) p->Show( nestLevel + 2, os ); @@ -1590,6 +1624,7 @@ void BOARD::Show( int nestLevel, std::ostream& os ) */ p = (BOARD_ITEM*) m_Son; + for( ; p; p = p->Next() ) { p->Show( nestLevel + 1, os ); diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 854796669c..6bcbf40485 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -842,6 +842,7 @@ public: { if( (unsigned) index < m_ZoneDescriptorList.size() ) return m_ZoneDescriptorList[index]; + return NULL; } @@ -879,8 +880,8 @@ public: /** * Function AddArea * Add an empty copper area to board areas list - * @param aNewZonesList = a PICKED_ITEMS_LIST * where to store new areas pickers (useful in undo commands) - * can be NULL + * @param aNewZonesList = a PICKED_ITEMS_LIST * where to store new areas pickers (useful + * in undo commands) can be NULL * @param aNetcode = the necode of the copper area (0 = no net) * @param aLayer = the layer of area * @param aStartPointPosition = position of the first point of the polygon outline of this area @@ -924,8 +925,8 @@ public: * Function ClipAreaPolygon * Process an area that has been modified, by clipping its polygon against itself. * This may change the number and order of copper areas in the net. - * @param aNewZonesList = a PICKED_ITEMS_LIST * where to store new areas pickers (useful in undo commands) - * can be NULL + * @param aNewZonesList = a PICKED_ITEMS_LIST * where to store new areas pickers (useful + * in undo commands) can be NULL * @param aCurrArea = the zone to process * @param bMessageBoxInt == true, shows message when clipping occurs. * @param bMessageBoxArc == true, shows message when clipping can't be done due to arcs. @@ -940,7 +941,7 @@ public: ZONE_CONTAINER* aCurrArea, bool bMessageBoxArc, bool bMessageBoxInt, - bool bRetainArcs = TRUE ); + bool bRetainArcs = true ); /** * Process an area that has been modified, by clipping its polygon against @@ -949,7 +950,7 @@ public: * @param aModifiedZonesList = a PICKED_ITEMS_LIST * where to store deleted or added areas * (useful in undo commands. Can be NULL * @param modified_area = area to test - * @param bMessageBoxInt : if TRUE, shows message boxes when clipping occurs. + * @param bMessageBoxInt : if true, shows message boxes when clipping occurs. * @param bMessageBoxArc if true, shows message when clipping can't be done due to arcs. * @return : * -1 if arcs intersect other sides, so polygon can't be clipped diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index 4d48346f73..b37ef8eb51 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -108,8 +108,9 @@ bool DIMENSION::ReadDimensionDescr( LINE_READER* aReader ) while( aReader->ReadLine() ) { Line = aReader->Line(); + if( strnicmp( Line, "$EndDIMENSION", 4 ) == 0 ) - return TRUE; + return true; if( Line[0] == 'V' ) { @@ -125,6 +126,7 @@ bool DIMENSION::ReadDimensionDescr( LINE_READER* aReader ) if( layer < FIRST_NO_COPPER_LAYER ) layer = FIRST_NO_COPPER_LAYER; + if( layer > LAST_NO_COPPER_LAYER ) layer = LAST_NO_COPPER_LAYER; @@ -221,7 +223,7 @@ bool DIMENSION::ReadDimensionDescr( LINE_READER* aReader ) } } - return FALSE; + return false; } @@ -275,8 +277,10 @@ void DIMENSION::Rotate(const wxPoint& aRotCentre, int aAngle) RotatePoint( &m_Text->m_Pos, aRotCentre, aAngle ); m_Text->m_Orient += aAngle; + if( m_Text->m_Orient >= 3600 ) m_Text->m_Orient -= 3600; + if( ( m_Text->m_Orient > 900 ) && ( m_Text->m_Orient <2700 ) ) m_Text->m_Orient -= 1800; @@ -323,8 +327,10 @@ void DIMENSION::Mirror(const wxPoint& axis_pos) INVERT( m_Pos.y ); INVERT( m_Text->m_Pos.y ); INVERT_ANGLE( m_Text->m_Orient ); + if( m_Text->m_Orient >= 3600 ) m_Text->m_Orient -= 3600; + if( ( m_Text->m_Orient > 900 ) && ( m_Text->m_Orient < 2700 ) ) m_Text->m_Orient -= 1800; @@ -456,10 +462,13 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText ) if( TraitG_ox > Barre_ox ) hx = -hx; + if( TraitG_ox == Barre_ox ) hx = 0; + if( TraitG_oy > Barre_oy ) hy = -hy; + if( TraitG_oy == Barre_oy ) hy = 0; @@ -503,16 +512,17 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText ) TraitD_fy = Barre_fy + hy; /* Calculate the better text position and orientation: */ - m_Pos.x = m_Text->m_Pos.x - = (Barre_fx + TraitG_fx) / 2; - m_Pos.y = m_Text->m_Pos.y - = (Barre_fy + TraitG_fy) / 2; + m_Pos.x = m_Text->m_Pos.x = (Barre_fx + TraitG_fx) / 2; + m_Pos.y = m_Text->m_Pos.y = (Barre_fy + TraitG_fy) / 2; m_Text->m_Orient = -(int) (angle * 1800 / M_PI); + if( m_Text->m_Orient < 0 ) m_Text->m_Orient += 3600; + if( m_Text->m_Orient >= 3600 ) m_Text->m_Orient -= 3600; + if( (m_Text->m_Orient > 900) && (m_Text->m_Orient <2700) ) m_Text->m_Orient -= 1800; @@ -537,6 +547,7 @@ void DIMENSION::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int mode_color, const wxP m_Text->Draw( panel, DC, mode_color, offset ); BOARD * brd = GetBoard( ); + if( brd->IsLayerVisible( m_Layer ) == false ) return; @@ -734,6 +745,7 @@ bool DIMENSION::HitTest( EDA_RECT& refArea ) { if( refArea.Contains( m_Pos ) ) return true; + return false; } diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index 8d98652228..661d9a675f 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -109,7 +109,7 @@ bool DRAWSEGMENT::ReadDrawSegmentDescr( LINE_READER* aReader ) Line = aReader->Line(); if( strnicmp( Line, "$End", 4 ) == 0 ) - return TRUE; /* End of description */ + return true; /* End of description */ if( Line[0] == 'P' ) { @@ -175,7 +175,7 @@ bool DRAWSEGMENT::ReadDrawSegmentDescr( LINE_READER* aReader ) } } - return FALSE; + return false; } @@ -227,9 +227,9 @@ MODULE* DRAWSEGMENT::GetParentModule() const void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& aOffset ) { int ux0, uy0, dx, dy; - int l_piste; + int l_trace; int color, mode; - int rayon; + int radius; BOARD * brd = GetBoard( ); @@ -239,7 +239,7 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wx color = brd->GetLayerColor( GetLayer() ); GRSetDrawMode( DC, draw_mode ); - l_piste = m_Width >> 1; /* half trace width */ + l_trace = m_Width >> 1; /* half trace width */ // Line start point or Circle and Arc center ux0 = m_Start.x + aOffset.x; @@ -250,34 +250,37 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wx dy = m_End.y + aOffset.y; mode = DisplayOpt.DisplayDrawItems; + if( m_Flags & FORCE_SKETCH ) mode = SKETCH; - if( l_piste < DC->DeviceToLogicalXRel( L_MIN_DESSIN ) ) + if( l_trace < DC->DeviceToLogicalXRel( L_MIN_DESSIN ) ) mode = FILAIRE; switch( m_Shape ) { case S_CIRCLE: - rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); + radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); + if( mode == FILAIRE ) { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, color ); + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, radius, color ); } else if( mode == SKETCH ) { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon - l_piste, color ); - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon + l_piste, color ); + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, radius - l_trace, color ); + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, radius + l_trace, color ); } else { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, m_Width, color ); + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, radius, m_Width, color ); } + break; case S_ARC: int StAngle, EndAngle; - rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); + radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); StAngle = (int) ArcTangente( dy - uy0, dx - ux0 ); EndAngle = StAngle + m_Angle; @@ -295,19 +298,19 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wx if( mode == FILAIRE ) GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon, color ); + radius, color ); else if( mode == SKETCH ) { GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon - l_piste, color ); + radius - l_trace, color ); GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon + l_piste, color ); + radius + l_trace, color ); } else { GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon, m_Width, color ); + radius, m_Width, color ); } break; case S_CURVE: @@ -329,15 +332,17 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wx else { GRFillCSegm( &panel->m_ClipBox, DC, - m_BezierPoints[i].x, m_BezierPoints[i].y, - m_BezierPoints[i-1].x, m_BezierPoints[i-1].y, + m_BezierPoints[i].x, m_BezierPoints[i].y, + m_BezierPoints[i-1].x, m_BezierPoints[i-1].y, m_Width, color ); } } break; default: if( mode == FILAIRE ) + { GRLine( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, 0, color ); + } else if( mode == SKETCH ) { GRCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, @@ -348,6 +353,7 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wx GRFillCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, m_Width, color ); } + break; } } @@ -388,6 +394,7 @@ void DRAWSEGMENT::DisplayInfo( EDA_DRAW_FRAME* frame ) default: frame->AppendMsgPanel( shape, _( "Segment" ), RED ); } + wxString start; start << GetStart(); @@ -396,8 +403,7 @@ void DRAWSEGMENT::DisplayInfo( EDA_DRAW_FRAME* frame ) frame->AppendMsgPanel( start, end, DARKGREEN ); - frame->AppendMsgPanel( _( "Layer" ), - board->GetLayerName( m_Layer ), DARKBROWN ); + frame->AppendMsgPanel( _( "Layer" ), board->GetLayerName( m_Layer ), DARKBROWN ); valeur_param( (unsigned) m_Width, msg ); frame->AppendMsgPanel( _( "Width" ), msg, DARKCYAN ); @@ -444,6 +450,7 @@ EDA_RECT DRAWSEGMENT::GetBoundingBox() const if( ii == 0 ) p_end = pt; + bbox.m_Pos.x = MIN( bbox.m_Pos.x, pt.x ); bbox.m_Pos.y = MIN( bbox.m_Pos.y, pt.y ); p_end.x = MAX( p_end.x, pt.x ); @@ -471,10 +478,10 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aRefPos ) case S_CIRCLE: case S_ARC: { - int rayon = GetRadius(); + int radius = GetRadius(); int dist = (int) hypot( (double) relPos.x, (double) relPos.y ); - if( abs( rayon - dist ) <= ( m_Width / 2 ) ) + if( abs( radius - dist ) <= ( m_Width / 2 ) ) { if( m_Shape == S_CIRCLE ) return true; @@ -498,8 +505,7 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aRefPos ) case S_CURVE: for( unsigned int i= 1; i < m_BezierPoints.size(); i++) { - if( TestSegmentHit( aRefPos,m_BezierPoints[i-1], - m_BezierPoints[i-1], m_Width / 2 ) ) + if( TestSegmentHit( aRefPos,m_BezierPoints[i-1], m_BezierPoints[i-1], m_Width / 2 ) ) return true; } break; @@ -527,6 +533,7 @@ bool DRAWSEGMENT::HitTest( EDA_RECT& refArea ) // Text if area intersects the circle: EDA_RECT area = refArea; area.Inflate( radius ); + if( area.Contains( m_Start ) ) return true; } diff --git a/pcbnew/class_edge_mod.cpp b/pcbnew/class_edge_mod.cpp index aeed51852b..9da227c3d1 100644 --- a/pcbnew/class_edge_mod.cpp +++ b/pcbnew/class_edge_mod.cpp @@ -77,7 +77,7 @@ void EDGE_MODULE::SetDrawCoord() */ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& offset ) { - int ux0, uy0, dx, dy, rayon, StAngle, EndAngle; + int ux0, uy0, dx, dy, radius, StAngle, EndAngle; int color, type_trace; int typeaff; PCB_BASE_FRAME* frame; @@ -105,9 +105,11 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wx GRSetDrawMode( DC, draw_mode ); typeaff = frame->m_DisplayModEdge; + if( m_Layer <= LAST_COPPER_LAYER ) { typeaff = frame->m_DisplayPcbTrackFill; + if( !typeaff ) typeaff = SKETCH; } @@ -125,53 +127,53 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wx else // SKETCH Mode GRCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, m_Width, color ); + break; case S_CIRCLE: - rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); + radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); + if( typeaff == FILAIRE ) { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, color ); + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, radius, color ); } else { if( typeaff == FILLED ) { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, - m_Width, color ); + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, radius, m_Width, color ); } else // SKETCH Mode { - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, - rayon + (m_Width / 2), color ); - GRCircle( &panel->m_ClipBox, DC, ux0, uy0, - rayon - (m_Width / 2), color ); + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, radius + (m_Width / 2), color ); + GRCircle( &panel->m_ClipBox, DC, ux0, uy0, radius - (m_Width / 2), color ); } } + break; case S_ARC: - rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); + radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); StAngle = (int) ArcTangente( dy - uy0, dx - ux0 ); EndAngle = StAngle + m_Angle; + if( StAngle > EndAngle ) EXCHG( StAngle, EndAngle ); + if( typeaff == FILAIRE ) { - GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon, color ); + GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, radius, color ); } else if( typeaff == FILLED ) { - GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, rayon, - m_Width, color ); + GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, radius, m_Width, color ); } else // SKETCH Mode { GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon + (m_Width / 2), color ); + radius + (m_Width / 2), color ); GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, - rayon - (m_Width / 2), color ); + radius - (m_Width / 2), color ); } break; @@ -190,8 +192,7 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wx pt += module->m_Pos - offset; } - GRPoly( &panel->m_ClipBox, DC, points.size(), &points[0], - TRUE, m_Width, color, color ); + GRPoly( &panel->m_ClipBox, DC, points.size(), &points[0], true, m_Width, color, color ); break; } } @@ -208,34 +209,27 @@ void EDGE_MODULE::DisplayInfo( EDA_DRAW_FRAME* frame ) return; BOARD* board = (BOARD*) module->GetParent(); + if( !board ) return; frame->ClearMsgPanel(); frame->AppendMsgPanel( _( "Graphic Item" ), wxEmptyString, DARKCYAN ); - - frame->AppendMsgPanel( _( "Module" ), module->m_Reference->m_Text, - DARKCYAN ); + frame->AppendMsgPanel( _( "Module" ), module->m_Reference->m_Text, DARKCYAN ); frame->AppendMsgPanel( _( "Value" ), module->m_Value->m_Text, BLUE ); msg.Printf( wxT( "%8.8lX" ), module->m_TimeStamp ); frame->AppendMsgPanel( _( "TimeStamp" ), msg, BROWN ); - - frame->AppendMsgPanel( _( "Mod Layer" ), - board->GetLayerName( module->GetLayer() ), RED ); - - frame->AppendMsgPanel( _( "Seg Layer" ), - board->GetLayerName( GetLayer() ), RED ); + frame->AppendMsgPanel( _( "Mod Layer" ), board->GetLayerName( module->GetLayer() ), RED ); + frame->AppendMsgPanel( _( "Seg Layer" ), board->GetLayerName( GetLayer() ), RED ); valeur_param( m_Width, msg ); frame->AppendMsgPanel( _( "Width" ), msg, BLUE ); } -/*******************************************/ bool EDGE_MODULE::Save( FILE* aFile ) const -/*******************************************/ { int ret = -1; @@ -271,8 +265,7 @@ bool EDGE_MODULE::Save( FILE* aFile ) const m_Width, m_Layer ); for( unsigned i = 0; iReadLine() ) { Buf = aReader->Line(); + if( strncmp( Buf, "Dl", 2 ) != 0 ) { error = 1; @@ -398,15 +393,18 @@ int EDGE_MODULE::ReadDescr( LINE_READER* aReader ) // Check for a reasonable width: if( m_Width <= 1 ) m_Width = 1; + if( m_Width > MAX_WIDTH ) m_Width = MAX_WIDTH; // Check for a reasonable layer: // m_Layer must be >= FIRST_NON_COPPER_LAYER, but because microwave footprints // can use the copper layers m_Layer < FIRST_NON_COPPER_LAYER is allowed. - // @todo: changes use of EDGE_MODULE these footprints and allows only m_Layer >= FIRST_NON_COPPER_LAYER + // @todo: changes use of EDGE_MODULE these footprints and allows only + // m_Layer >= FIRST_NON_COPPER_LAYER if( (m_Layer < 0) || (m_Layer > LAST_NON_COPPER_LAYER) ) m_Layer = SILKSCREEN_N_FRONT; + return error; } diff --git a/pcbnew/class_mire.cpp b/pcbnew/class_mire.cpp index dccc74522f..62ff5e38e6 100644 --- a/pcbnew/class_mire.cpp +++ b/pcbnew/class_mire.cpp @@ -16,20 +16,20 @@ #include "richio.h" -MIREPCB::MIREPCB( BOARD_ITEM* aParent ) : - BOARD_ITEM( aParent, TYPE_MIRE ) +PCB_TARGET::PCB_TARGET( BOARD_ITEM* aParent ) : + BOARD_ITEM( aParent, PCB_TARGET_T ) { m_Shape = 0; m_Size = 5000; } -MIREPCB::~MIREPCB() +PCB_TARGET::~PCB_TARGET() { } -void MIREPCB::Copy( MIREPCB* source ) +void PCB_TARGET::Copy( PCB_TARGET* source ) { m_Layer = source->m_Layer; m_Width = source->m_Width; @@ -42,37 +42,41 @@ void MIREPCB::Copy( MIREPCB* source ) /* Read the description from the PCB file. */ -bool MIREPCB::ReadMirePcbDescr( LINE_READER* aReader ) +bool PCB_TARGET::ReadMirePcbDescr( LINE_READER* aReader ) { char* Line; while( aReader->ReadLine() ) { Line = aReader->Line(); + if( strnicmp( Line, "$End", 4 ) == 0 ) - return TRUE; + return true; + if( Line[0] == 'P' ) { sscanf( Line + 2, " %X %d %d %d %d %d %lX", &m_Shape, &m_Layer, &m_Pos.x, &m_Pos.y, &m_Size, &m_Width, &m_TimeStamp ); + if( m_Layer < FIRST_NO_COPPER_LAYER ) m_Layer = FIRST_NO_COPPER_LAYER; + if( m_Layer > LAST_NO_COPPER_LAYER ) m_Layer = LAST_NO_COPPER_LAYER; } } - return FALSE; + return false; } -bool MIREPCB::Save( FILE* aFile ) const +bool PCB_TARGET::Save( FILE* aFile ) const { bool rc = false; - if( fprintf( aFile, "$MIREPCB\n" ) != sizeof("$MIREPCB\n")-1 ) + if( fprintf( aFile, "$PCB_TARGET\n" ) != sizeof("$PCB_TARGET\n")-1 ) goto out; fprintf( aFile, "Po %X %d %d %d %d %d %8.8lX\n", @@ -80,7 +84,7 @@ bool MIREPCB::Save( FILE* aFile ) const m_Pos.x, m_Pos.y, m_Size, m_Width, m_TimeStamp ); - if( fprintf( aFile, "$EndMIREPCB\n" ) != sizeof("$EndMIREPCB\n")-1 ) + if( fprintf( aFile, "$EndPCB_TARGET\n" ) != sizeof("$EndPCB_TARGET\n")-1 ) goto out; rc = true; @@ -92,13 +96,13 @@ out: -/* Draw MIREPCB object: 2 segments + 1 circle +/* Draw PCB_TARGET object: 2 segments + 1 circle * The circle radius is half the radius of the target * 2 lines have length the diameter of the target */ -void MIREPCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int mode_color, const wxPoint& offset ) +void PCB_TARGET::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int mode_color, const wxPoint& offset ) { - int rayon, ox, oy, gcolor, width; + int radius, ox, oy, gcolor, width; int dx1, dx2, dy1, dy2; int typeaff; @@ -106,10 +110,11 @@ void MIREPCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int mode_color, const wxPoi oy = m_Pos.y + offset.y; BOARD * brd = GetBoard( ); + if( brd->IsLayerVisible( m_Layer ) == false ) return; - gcolor = brd->GetLayerColor(m_Layer); + gcolor = brd->GetLayerColor( m_Layer ); GRSetDrawMode( DC, mode_color ); typeaff = DisplayOpt.DisplayDrawItems; @@ -118,7 +123,7 @@ void MIREPCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int mode_color, const wxPoi if( DC->LogicalToDeviceXRel( width ) < 2 ) typeaff = FILAIRE; - rayon = m_Size / 4; + radius = m_Size / 4; switch( typeaff ) { @@ -126,25 +131,25 @@ void MIREPCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int mode_color, const wxPoi width = 0; case FILLED: - GRCircle( &panel->m_ClipBox, DC, ox, oy, rayon, width, gcolor ); + GRCircle( &panel->m_ClipBox, DC, ox, oy, radius, width, gcolor ); break; case SKETCH: - GRCircle( &panel->m_ClipBox, DC, ox, oy, rayon + (width / 2), gcolor ); - GRCircle( &panel->m_ClipBox, DC, ox, oy, rayon - (width / 2), gcolor ); + GRCircle( &panel->m_ClipBox, DC, ox, oy, radius + (width / 2), gcolor ); + GRCircle( &panel->m_ClipBox, DC, ox, oy, radius - (width / 2), gcolor ); break; } - rayon = m_Size / 2; - dx1 = rayon; + radius = m_Size / 2; + dx1 = radius; dy1 = 0; dx2 = 0; - dy2 = rayon; + dy2 = radius; if( m_Shape ) /* Form X */ { - dx1 = dy1 = ( rayon * 7 ) / 5; + dx1 = dy1 = ( radius * 7 ) / 5; dx2 = dx1; dy2 = -dy1; } @@ -153,19 +158,13 @@ void MIREPCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int mode_color, const wxPoi { case FILAIRE: case FILLED: - GRLine( &panel->m_ClipBox, DC, ox - dx1, oy - dy1, - ox + dx1, oy + dy1, width, gcolor ); - GRLine( &panel->m_ClipBox, DC, ox - dx2, oy - dy2, - ox + dx2, oy + dy2, width, gcolor ); + GRLine( &panel->m_ClipBox, DC, ox - dx1, oy - dy1, ox + dx1, oy + dy1, width, gcolor ); + GRLine( &panel->m_ClipBox, DC, ox - dx2, oy - dy2, ox + dx2, oy + dy2, width, gcolor ); break; case SKETCH: - GRCSegm( &panel->m_ClipBox, DC, ox - dx1, oy - dy1, - ox + dx1, oy + dy1, - width, gcolor ); - GRCSegm( &panel->m_ClipBox, DC, ox - dx2, oy - dy2, - ox + dx2, oy + dy2, - width, gcolor ); + GRCSegm( &panel->m_ClipBox, DC, ox - dx1, oy - dy1, ox + dx1, oy + dy1, width, gcolor ); + GRCSegm( &panel->m_ClipBox, DC, ox - dx2, oy - dy2, ox + dx2, oy + dy2, width, gcolor ); break; } } @@ -177,12 +176,12 @@ void MIREPCB::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int mode_color, const wxPoi * @param refPos A wxPoint to test * @return bool - true if a hit, else false */ -bool MIREPCB::HitTest( const wxPoint& refPos ) +bool PCB_TARGET::HitTest( const wxPoint& refPos ) { int dX = refPos.x - m_Pos.x; int dY = refPos.y - m_Pos.y; - int rayon = m_Size / 2; - return abs( dX ) <= rayon && abs( dY ) <= rayon; + int radius = m_Size / 2; + return abs( dX ) <= radius && abs( dY ) <= radius; } @@ -192,10 +191,11 @@ bool MIREPCB::HitTest( const wxPoint& refPos ) * @param refArea : the given EDA_RECT * @return bool - true if a hit, else false */ -bool MIREPCB::HitTest( EDA_RECT& refArea ) +bool PCB_TARGET::HitTest( EDA_RECT& refArea ) { if( refArea.Contains( m_Pos ) ) return true; + return false; } @@ -206,7 +206,7 @@ bool MIREPCB::HitTest( EDA_RECT& refArea ) * @param aRotCentre - the rotation point. * @param aAngle - the rotation angle in 0.1 degree. */ -void MIREPCB::Rotate(const wxPoint& aRotCentre, int aAngle) +void PCB_TARGET::Rotate(const wxPoint& aRotCentre, int aAngle) { RotatePoint( &m_Pos, aRotCentre, aAngle ); } @@ -217,14 +217,14 @@ void MIREPCB::Rotate(const wxPoint& aRotCentre, int aAngle) * Flip this object, i.e. change the board side for this object * @param aCentre - the rotation point. */ -void MIREPCB::Flip(const wxPoint& aCentre ) +void PCB_TARGET::Flip(const wxPoint& aCentre ) { m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y ); SetLayer( ChangeSideNumLayer( GetLayer() ) ); } -EDA_RECT MIREPCB::GetBoundingBox() const +EDA_RECT PCB_TARGET::GetBoundingBox() const { EDA_RECT bBox; bBox.SetX( m_Pos.x - m_Size/2 ); @@ -236,7 +236,7 @@ EDA_RECT MIREPCB::GetBoundingBox() const } -wxString MIREPCB::GetSelectMenuText() const +wxString PCB_TARGET::GetSelectMenuText() const { wxString text; wxString msg; diff --git a/pcbnew/class_mire.h b/pcbnew/class_mire.h index aafb78e73e..390eb07399 100644 --- a/pcbnew/class_mire.h +++ b/pcbnew/class_mire.h @@ -1,5 +1,5 @@ /****************************************************/ -/* MIREPCB class definition. (targets for photos) */ +/* PCB_TARGET class definition. (targets for photos) */ /****************************************************/ #ifndef MIRE_H @@ -9,7 +9,7 @@ #include "richio.h" -class MIREPCB : public BOARD_ITEM +class PCB_TARGET : public BOARD_ITEM { public: int m_Width; @@ -18,11 +18,11 @@ public: int m_Size; public: - MIREPCB( BOARD_ITEM* aParent ); - ~MIREPCB(); + PCB_TARGET( BOARD_ITEM* aParent ); + ~PCB_TARGET(); - MIREPCB* Next() const { return (MIREPCB*) Pnext; } - MIREPCB* Back() const { return (MIREPCB*) Pnext; } + PCB_TARGET* Next() const { return (PCB_TARGET*) Pnext; } + PCB_TARGET* Back() const { return (PCB_TARGET*) Pnext; } wxPoint& GetPosition() { @@ -65,7 +65,7 @@ public: bool ReadMirePcbDescr( LINE_READER* aReader ); - void Copy( MIREPCB* source ); + void Copy( PCB_TARGET* source ); void Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int aDrawMode, const wxPoint& offset = ZeroOffset ); diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 0b227f9654..0aecfdf49c 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -113,16 +113,17 @@ void MODULE::Copy( MODULE* aModule ) /* Copy auxiliary data: Pads */ m_Pads.DeleteAll(); + for( D_PAD* pad = aModule->m_Pads; pad; pad = pad->Next() ) { D_PAD* newpad = new D_PAD( this ); newpad->Copy( pad ); - m_Pads.PushBack( newpad ); } /* Copy auxiliary data: Drawings */ m_Drawings.DeleteAll(); + for( BOARD_ITEM* item = aModule->m_Drawings; item; item = item->Next() ) { switch( item->Type() ) @@ -152,15 +153,18 @@ void MODULE::Copy( MODULE* aModule ) // Ensure there is one (or more) item in m_3D_Drawings m_3D_Drawings.PushBack( new S3D_MASTER( this ) ); // push a void item + for( S3D_MASTER* item = aModule->m_3D_Drawings; item; item = item->Next() ) { if( item->m_Shape3DName.IsEmpty() ) // do not copy empty shapes. continue; + S3D_MASTER* t3d = m_3D_Drawings; + if( t3d && t3d->m_Shape3DName.IsEmpty() ) // The first entry can - // exist, but is empty : - // use it. + { // exist, but is empty : use it. t3d->Copy( item ); + } else { t3d = new S3D_MASTER( this ); @@ -297,12 +301,16 @@ bool MODULE::Save( FILE* aFile ) const fprintf( aFile, "Sc %8.8lX\n", m_TimeStamp ); fprintf( aFile, "AR %s\n", TO_UTF8( m_Path ) ); fprintf( aFile, "Op %X %X 0\n", m_CntRot90, m_CntRot180 ); + if( m_LocalSolderMaskMargin != 0 ) fprintf( aFile, ".SolderMask %d\n", m_LocalSolderMaskMargin ); + if( m_LocalSolderPasteMargin != 0 ) fprintf( aFile, ".SolderPaste %d\n", m_LocalSolderPasteMargin ); + if( m_LocalSolderPasteMarginRatio != 0 ) fprintf( aFile, ".SolderPasteRatio %g\n", m_LocalSolderPasteMarginRatio ); + if( m_LocalClearance != 0 ) fprintf( aFile, ".LocalClearance %d\n", m_LocalClearance ); @@ -310,10 +318,13 @@ bool MODULE::Save( FILE* aFile ) const if( m_Attributs != MOD_DEFAULT ) { fprintf( aFile, "At " ); + if( m_Attributs & MOD_CMS ) fprintf( aFile, "SMD " ); + if( m_Attributs & MOD_VIRTUAL ) fprintf( aFile, "VIRTUAL " ); + fprintf( aFile, "\n" ); } @@ -334,6 +345,7 @@ bool MODULE::Save( FILE* aFile ) const case TYPE_EDGE_MODULE: if( !item->Save( aFile ) ) goto out; + break; default: @@ -422,11 +434,13 @@ int MODULE::Read_3D_Descr( LINE_READER* aReader ) while( aReader->ReadLine() ) { Line = aReader->Line(); + switch( Line[0] ) { case '$': if( Line[1] == 'E' ) return 0; + return 1; case 'N': // Shape File Name @@ -484,6 +498,7 @@ int MODULE::ReadDescr( LINE_READER* aReader ) { if( Line[1] == 'E' ) break; + if( Line[1] == 'P' ) { D_PAD* pad = new D_PAD( this ); @@ -495,6 +510,7 @@ int MODULE::ReadDescr( LINE_READER* aReader ) m_Pads.PushBack( pad ); continue; } + if( Line[1] == 'S' ) Read_3D_Descr( aReader ); } @@ -517,10 +533,13 @@ int MODULE::ReadDescr( LINE_READER* aReader ) &m_LastEdit_Time, &m_TimeStamp, BufCar1 ); m_ModuleStatus = 0; + if( BufCar1[0] == 'F' ) SetLocked( true ); + if( BufCar1[1] == 'P' ) m_ModuleStatus |= MODULE_is_PLACED; + break; case 'L': /* Li = read the library name of the footprint */ @@ -539,15 +558,20 @@ int MODULE::ReadDescr( LINE_READER* aReader ) sscanf( PtLine, " %X %X", &itmp1, &itmp2 ); m_CntRot180 = itmp2 & 0x0F; + if( m_CntRot180 > 10 ) m_CntRot180 = 10; m_CntRot90 = itmp1 & 0x0F; + if( m_CntRot90 > 10 ) m_CntRot90 = 0; + itmp1 = (itmp1 >> 4) & 0x0F; + if( itmp1 > 10 ) itmp1 = 0; + m_CntRot90 |= itmp1 << 4; break; @@ -557,21 +581,25 @@ int MODULE::ReadDescr( LINE_READER* aReader ) /* At = (At)tributes of module */ if( strstr( PtLine, "SMD" ) ) m_Attributs |= MOD_CMS; + if( strstr( PtLine, "VIRTUAL" ) ) m_Attributs |= MOD_VIRTUAL; } + if( Line[1] == 'R' ) { // alternate reference, e.g. /478C2408/478AD1B6 sscanf( PtLine, " %s", BufLine ); m_Path = FROM_UTF8( BufLine ); } + break; case 'T': /* Read a footprint text description (ref, value, or * drawing */ TEXTE_MODULE * textm; sscanf( Line + 1, "%d", &itmp1 ); + if( itmp1 == TEXT_is_REFERENCE ) textm = m_Reference; else if( itmp1 == TEXT_is_VALUE ) @@ -609,6 +637,7 @@ int MODULE::ReadDescr( LINE_READER* aReader ) m_LocalSolderPasteMarginRatio = atof( Line + 18 ); else if( strnicmp( Line, ".LocalClearance ", 16 ) == 0 ) m_LocalClearance = atoi( Line + 16 ); + break; default: @@ -617,12 +646,12 @@ int MODULE::ReadDescr( LINE_READER* aReader ) } /* Recalculate the bounding box */ - Set_Rectangle_Encadrement(); + CalculateBoundingBox(); return 0; } -void MODULE::Set_Rectangle_Encadrement() +void MODULE::CalculateBoundingBox() { m_BoundaryBox = GetFootPrintRect(); m_Surface = ABS( (double) m_BoundaryBox.GetWidth() * m_BoundaryBox.GetHeight() ); @@ -673,14 +702,14 @@ void MODULE::DisplayInfo( EDA_DRAW_FRAME* frame ) { int nbpad; char bufcar[512], Line[512]; - bool flag = FALSE; + bool flag = false; wxString msg; BOARD* board = GetBoard(); frame->EraseMsgBox(); if( frame->m_Ident != PCB_FRAME ) - flag = TRUE; + flag = true; frame->AppendMsgPanel( m_Reference->m_Text, m_Value->m_Text, DARKCYAN ); @@ -783,9 +812,6 @@ D_PAD* MODULE::FindPadByName( const wxString& aPadName ) const #else if( buf == aPadName ) #endif - - - return pad; } @@ -824,10 +850,12 @@ SEARCH_RESULT MODULE::Visit( INSPECTOR* inspector, const void* testData, case TYPE_TEXTE_MODULE: result = inspector->Inspect( m_Reference, testData ); + if( result == SEARCH_QUIT ) break; result = inspector->Inspect( m_Value, testData ); + if( result == SEARCH_QUIT ) break; @@ -908,6 +936,7 @@ void MODULE::Show( int nestLevel, std::ostream& os ) NestedSpace( nestLevel + 1, os ) << "\n"; p = m_Pads; + for( ; p; p = p->Next() ) p->Show( nestLevel + 2, os ); @@ -915,12 +944,14 @@ void MODULE::Show( int nestLevel, std::ostream& os ) NestedSpace( nestLevel + 1, os ) << "\n"; p = m_Drawings; + for( ; p; p = p->Next() ) p->Show( nestLevel + 2, os ); NestedSpace( nestLevel + 1, os ) << "\n"; p = m_Son; + for( ; p; p = p->Next() ) { p->Show( nestLevel + 1, os ); diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 7baa8cbc46..cb36aa9d8a 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -114,10 +114,10 @@ public: */ /** - * Function Set_Rectangle_Encadrement + * Function CalculateBoundingBox * calculates the bounding box in board coordinates. */ - void Set_Rectangle_Encadrement(); + void CalculateBoundingBox(); /** * Function GetFootPrintRect() diff --git a/pcbnew/class_module_transform_functions.cpp b/pcbnew/class_module_transform_functions.cpp index 29adafeaa9..b9a30e21f8 100644 --- a/pcbnew/class_module_transform_functions.cpp +++ b/pcbnew/class_module_transform_functions.cpp @@ -73,48 +73,54 @@ int ChangeSideNumLayer( int oldlayer ) /* Calculate the mask layer when flipping a footprint * BACK and FRONT copper layers , mask, paste, solder layers are swapped */ -int ChangeSideMaskLayer( int masque ) +int ChangeSideMaskLayer( int aMask ) { - int newmasque; + int newMask; - newmasque = masque & ~(LAYER_BACK | LAYER_FRONT | + newMask = aMask & ~(LAYER_BACK | LAYER_FRONT | SILKSCREEN_LAYER_BACK | SILKSCREEN_LAYER_FRONT | ADHESIVE_LAYER_BACK | ADHESIVE_LAYER_FRONT | SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT | SOLDERPASTE_LAYER_BACK | SOLDERPASTE_LAYER_FRONT | ADHESIVE_LAYER_BACK | ADHESIVE_LAYER_FRONT); - if( masque & LAYER_BACK ) - newmasque |= LAYER_FRONT; - if( masque & LAYER_FRONT ) - newmasque |= LAYER_BACK; + if( aMask & LAYER_BACK ) + newMask |= LAYER_FRONT; - if( masque & SILKSCREEN_LAYER_BACK ) - newmasque |= SILKSCREEN_LAYER_FRONT; - if( masque & SILKSCREEN_LAYER_FRONT ) - newmasque |= SILKSCREEN_LAYER_BACK; + if( aMask & LAYER_FRONT ) + newMask |= LAYER_BACK; - if( masque & ADHESIVE_LAYER_BACK ) - newmasque |= ADHESIVE_LAYER_FRONT; - if( masque & ADHESIVE_LAYER_FRONT ) - newmasque |= ADHESIVE_LAYER_BACK; + if( aMask & SILKSCREEN_LAYER_BACK ) + newMask |= SILKSCREEN_LAYER_FRONT; - if( masque & SOLDERMASK_LAYER_BACK ) - newmasque |= SOLDERMASK_LAYER_FRONT; - if( masque & SOLDERMASK_LAYER_FRONT ) - newmasque |= SOLDERMASK_LAYER_BACK; + if( aMask & SILKSCREEN_LAYER_FRONT ) + newMask |= SILKSCREEN_LAYER_BACK; - if( masque & SOLDERPASTE_LAYER_BACK ) - newmasque |= SOLDERPASTE_LAYER_FRONT; - if( masque & SOLDERPASTE_LAYER_FRONT ) - newmasque |= SOLDERPASTE_LAYER_BACK; + if( aMask & ADHESIVE_LAYER_BACK ) + newMask |= ADHESIVE_LAYER_FRONT; - if( masque & ADHESIVE_LAYER_BACK ) - newmasque |= ADHESIVE_LAYER_FRONT; - if( masque & ADHESIVE_LAYER_FRONT ) - newmasque |= ADHESIVE_LAYER_BACK; + if( aMask & ADHESIVE_LAYER_FRONT ) + newMask |= ADHESIVE_LAYER_BACK; - return newmasque; + if( aMask & SOLDERMASK_LAYER_BACK ) + newMask |= SOLDERMASK_LAYER_FRONT; + + if( aMask & SOLDERMASK_LAYER_FRONT ) + newMask |= SOLDERMASK_LAYER_BACK; + + if( aMask & SOLDERPASTE_LAYER_BACK ) + newMask |= SOLDERPASTE_LAYER_FRONT; + + if( aMask & SOLDERPASTE_LAYER_FRONT ) + newMask |= SOLDERPASTE_LAYER_BACK; + + if( aMask & ADHESIVE_LAYER_BACK ) + newMask |= ADHESIVE_LAYER_FRONT; + + if( aMask & ADHESIVE_LAYER_FRONT ) + newMask |= ADHESIVE_LAYER_BACK; + + return newMask; } @@ -160,7 +166,7 @@ void MODULE::Flip(const wxPoint& aCentre ) // Move module to its final position: wxPoint finalPos = m_Pos; finalPos.y = aCentre.y - ( finalPos.y - aCentre.y ); /// Mirror the Y position - SetPosition(finalPos); + SetPosition(finalPos); /* Flip layer */ SetLayer( ChangeSideNumLayer( GetLayer() ) ); @@ -171,6 +177,7 @@ void MODULE::Flip(const wxPoint& aCentre ) /* Mirror inversion layers pads. */ pt_pad = m_Pads; + for( ; pt_pad != NULL; pt_pad = pt_pad->Next() ) { pt_pad->m_Pos.y -= m_Pos.y; @@ -182,7 +189,7 @@ void MODULE::Flip(const wxPoint& aCentre ) NEGATE_AND_NORMALIZE_ANGLE_POS( pt_pad->m_Orient ); /* flip pads layers*/ - pt_pad->m_Masque_Layer = ChangeSideMaskLayer( pt_pad->m_Masque_Layer ); + pt_pad->m_layerMask = ChangeSideMaskLayer( pt_pad->m_layerMask ); } /* Mirror reference. */ @@ -285,7 +292,7 @@ void MODULE::Flip(const wxPoint& aCentre ) } } - Set_Rectangle_Encadrement(); + CalculateBoundingBox(); } void MODULE::SetPosition( const wxPoint& newpos ) @@ -327,7 +334,7 @@ void MODULE::SetPosition( const wxPoint& newpos ) } } - Set_Rectangle_Encadrement(); + CalculateBoundingBox(); } @@ -373,5 +380,5 @@ void MODULE::SetOrientation( int newangle ) } } - Set_Rectangle_Encadrement(); + CalculateBoundingBox(); } diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index 9e07b0f842..b5e28c3082 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -45,9 +45,8 @@ D_PAD::D_PAD( MODULE* parent ) : BOARD_CONNECTED_ITEM( parent, TYPE_PAD ) m_LocalSolderMaskMargin = 0; m_LocalSolderPasteMargin = 0; m_LocalSolderPasteMarginRatio = 0.0; - m_Masque_Layer = PAD_STANDARD_DEFAULT_LAYERS; // set layers mask to - // default for a standard - // pad + m_layerMask = PAD_STANDARD_DEFAULT_LAYERS; // set layers mask to + // default for a standard pad SetSubRatsnest( 0 ); // used in ratsnest // calculations @@ -160,10 +159,12 @@ void D_PAD::ReturnStringPadName( wxString& text ) const int ii; text.Empty(); + for( ii = 0; ii < 4; ii++ ) { if( m_Padname[ii] == 0 ) break; + text.Append( m_Padname[ii] ); } } @@ -175,8 +176,10 @@ void D_PAD::SetPadName( const wxString& name ) int ii, len; len = name.Length(); + if( len > 4 ) len = 4; + for( ii = 0; ii < len; ii++ ) m_Padname[ii] = name.GetChar( ii ); @@ -202,7 +205,7 @@ void D_PAD::Copy( D_PAD* source ) return; m_Pos = source->m_Pos; - m_Masque_Layer = source->m_Masque_Layer; + m_layerMask = source->m_layerMask; m_NumPadName = source->m_NumPadName; SetNet( source->GetNet() ); @@ -280,6 +283,7 @@ int D_PAD::GetSolderMaskMargin() { int margin = m_LocalSolderMaskMargin; MODULE * module = (MODULE*) GetParent(); + if( module ) { if( margin == 0 ) @@ -287,6 +291,7 @@ int D_PAD::GetSolderMaskMargin() if( module->m_LocalSolderMaskMargin ) margin = module->m_LocalSolderMaskMargin; } + if( margin == 0 ) { BOARD * brd = GetBoard(); @@ -298,9 +303,11 @@ int D_PAD::GetSolderMaskMargin() if( margin < 0 ) { int minsize = -MIN( m_Size.x, m_Size.y ) / 2; + if( margin < minsize ) minsize = minsize; } + return margin; } @@ -326,11 +333,13 @@ wxSize D_PAD::GetSolderPasteMargin() margin = module->m_LocalSolderPasteMargin; BOARD * brd = GetBoard(); + if( margin == 0 ) margin = brd->GetBoardDesignSettings()->m_SolderPasteMargin; if( mratio == 0.0 ) mratio = module->m_LocalSolderPasteMarginRatio; + if( mratio == 0.0 ) { mratio = brd->GetBoardDesignSettings()->m_SolderPasteMarginRatio; @@ -373,6 +382,7 @@ int D_PAD::ReadDescr( LINE_READER* aReader ) while( aReader->ReadLine() ) { Line = aReader->Line(); + if( Line[0] == '$' ) return 0; @@ -385,6 +395,7 @@ int D_PAD::ReadDescr( LINE_READER* aReader ) case 'S': // = Sh /* Read pad name */ nn = 0; + while( (*PtLine != '"') && *PtLine ) PtLine++; @@ -392,6 +403,7 @@ int D_PAD::ReadDescr( LINE_READER* aReader ) PtLine++; memset( m_Padname, 0, sizeof(m_Padname) ); + while( (*PtLine != '"') && *PtLine ) { if( nn < (int) sizeof(m_Padname) ) @@ -450,21 +462,24 @@ int D_PAD::ReadDescr( LINE_READER* aReader ) m_DrillShape = PAD_OVAL; } } + break; case 'A': nn = sscanf( PtLine, "%s %s %X", BufLine, BufCar, - &m_Masque_Layer ); + &m_layerMask ); - /* BufCar is not used now */ - /* update attributes */ + /* BufCar is not used now update attributes */ m_Attribut = PAD_STANDARD; if( strncmp( BufLine, "SMD", 3 ) == 0 ) m_Attribut = PAD_SMD; + if( strncmp( BufLine, "CONN", 4 ) == 0 ) m_Attribut = PAD_CONN; + if( strncmp( BufLine, "HOLE", 4 ) == 0 ) m_Attribut = PAD_HOLE_NOT_PLATED; + break; case 'N': /* Read Netname */ @@ -545,10 +560,12 @@ bool D_PAD::Save( FILE* aFile ) const m_DeltaSize.x, m_DeltaSize.y, m_Orient ); fprintf( aFile, "Dr %d %d %d", m_Drill.x, m_Offset.x, m_Offset.y ); + if( m_DrillShape == PAD_OVAL ) { fprintf( aFile, " %c %d %d", 'O', m_Drill.x, m_Drill.y ); } + fprintf( aFile, "\n" ); switch( m_Attribut ) @@ -571,7 +588,7 @@ bool D_PAD::Save( FILE* aFile ) const break; } - fprintf( aFile, "At %s N %8.8X\n", texttype, m_Masque_Layer ); + fprintf( aFile, "At %s N %8.8X\n", texttype, m_layerMask ); fprintf( aFile, "Ne %d %s\n", GetNet(), EscapedUTF8( m_Netname ).c_str() ); @@ -608,6 +625,7 @@ void D_PAD::DisplayInfo( EDA_DRAW_FRAME* frame ) frame->EraseMsgBox(); module = (MODULE*) m_Parent; + if( module ) { wxString msg = module->GetReference(); @@ -621,8 +639,7 @@ void D_PAD::DisplayInfo( EDA_DRAW_FRAME* frame ) /* For test and debug only: display m_physical_connexion and * m_logical_connexion */ #if 1 // Used only to debug connectivity calculations - Line.Printf( wxT( "%d-%d-%d " ), GetSubRatsnest(), - GetSubNet(), m_ZoneSubnet ); + Line.Printf( wxT( "%d-%d-%d " ), GetSubRatsnest(), GetSubNet(), m_ZoneSubnet ); frame->AppendMsgPanel( wxT( "L-P-Z" ), Line, DARKGREEN ); #endif @@ -630,9 +647,9 @@ void D_PAD::DisplayInfo( EDA_DRAW_FRAME* frame ) wxString layerInfo; - if( (m_Masque_Layer & ALL_CU_LAYERS) == 0 ) // pad is not on any copper layers + if( (m_layerMask & ALL_CU_LAYERS) == 0 ) // pad is not on any copper layers { - switch( m_Masque_Layer & ~ALL_CU_LAYERS ) + switch( m_layerMask & ~ALL_CU_LAYERS ) { case ADHESIVE_LAYER_BACK: layerInfo = board->GetLayerName( ADHESIVE_N_BACK ); @@ -697,33 +714,34 @@ void D_PAD::DisplayInfo( EDA_DRAW_FRAME* frame ) static const wxChar* andInternal = _( " & int" ); - if( (m_Masque_Layer & (LAYER_BACK | LAYER_FRONT)) == LAYER_BACK ) + if( (m_layerMask & (LAYER_BACK | LAYER_FRONT)) == LAYER_BACK ) { layerInfo = board->GetLayerName( LAYER_N_BACK ); - if( m_Masque_Layer & INTERIOR_COPPER ) + if( m_layerMask & INTERIOR_COPPER ) layerInfo += andInternal; } - else if( (m_Masque_Layer & (LAYER_BACK | LAYER_FRONT)) == (LAYER_BACK | LAYER_FRONT) ) + else if( (m_layerMask & (LAYER_BACK | LAYER_FRONT)) == (LAYER_BACK | LAYER_FRONT) ) { layerInfo = board->GetLayerName( LAYER_N_BACK ) + wxT(", ") + board->GetLayerName( LAYER_N_FRONT ); - if( m_Masque_Layer & INTERIOR_COPPER ) + if( m_layerMask & INTERIOR_COPPER ) layerInfo += andInternal; } - else if( (m_Masque_Layer & (LAYER_BACK | LAYER_FRONT)) == LAYER_FRONT ) + else if( (m_layerMask & (LAYER_BACK | LAYER_FRONT)) == LAYER_FRONT ) { layerInfo = board->GetLayerName( LAYER_N_FRONT ); - if( m_Masque_Layer & INTERIOR_COPPER ) + if( m_layerMask & INTERIOR_COPPER ) layerInfo += andInternal; } - - else // necessarily true: if( m_Masque_Layer & INTERIOR_COPPER ) + else // necessarily true: if( m_layerMask & INTERIOR_COPPER ) + { layerInfo = _( "internal" ); + } } frame->AppendMsgPanel( _( "Layer" ), layerInfo, DARKGREEN ); @@ -737,6 +755,7 @@ void D_PAD::DisplayInfo( EDA_DRAW_FRAME* frame ) frame->AppendMsgPanel( _( "V Size" ), Line, RED ); valeur_param( (unsigned) m_Drill.x, Line ); + if( m_DrillShape == PAD_CIRCLE ) { frame->AppendMsgPanel( _( "Drill" ), Line, RED ); @@ -751,6 +770,7 @@ void D_PAD::DisplayInfo( EDA_DRAW_FRAME* frame ) } int module_orient = module ? module->m_Orient : 0; + if( module_orient ) Line.Printf( wxT( "%3.1f(+%3.1f)" ), (float) ( m_Orient - module_orient ) / 10, @@ -777,7 +797,7 @@ void D_PAD::DisplayInfo( EDA_DRAW_FRAME* frame ) // see class_pad.h bool D_PAD::IsOnLayer( int aLayer ) const { - return (1 << aLayer) & m_Masque_Layer; + return (1 << aLayer) & m_layerMask; } @@ -807,8 +827,10 @@ bool D_PAD::HitTest( const wxPoint& refPos ) { case PAD_CIRCLE: dist = hypot( delta.x, delta.y ); + if( wxRound( dist ) <= dx ) return true; + break; case PAD_TRAPEZOID: @@ -821,8 +843,10 @@ bool D_PAD::HitTest( const wxPoint& refPos ) default: RotatePoint( &delta, -m_Orient ); + if( (abs( delta.x ) <= dx ) && (abs( delta.y ) <= dy) ) return true; + break; } @@ -836,23 +860,29 @@ int D_PAD::Compare( const D_PAD* padref, const D_PAD* padcmp ) if( (diff = padref->m_PadShape - padcmp->m_PadShape) ) return diff; + if( (diff = padref->m_Size.x - padcmp->m_Size.x) ) return diff; + if( (diff = padref->m_Size.y - padcmp->m_Size.y) ) return diff; + if( (diff = padref->m_Offset.x - padcmp->m_Offset.x) ) return diff; + if( (diff = padref->m_Offset.y - padcmp->m_Offset.y) ) return diff; + if( (diff = padref->m_DeltaSize.x - padcmp->m_DeltaSize.x) ) return diff; + if( (diff = padref->m_DeltaSize.y - padcmp->m_DeltaSize.y) ) return diff; // @todo check if export_gencad still works: // specctra_export needs this, but maybe export_gencad does not. added on // Jan 24 2008 by Dick. - if( ( diff = padref->m_Masque_Layer - padcmp->m_Masque_Layer ) ) + if( ( diff = padref->m_layerMask - padcmp->m_layerMask ) ) return diff; return 0; @@ -864,19 +894,19 @@ wxString D_PAD::ShowPadShape() const switch( m_PadShape ) { case PAD_CIRCLE: - return _("Circle"); + return _( "Circle" ); case PAD_OVAL: - return _("Oval"); + return _( "Oval" ); case PAD_RECT: - return _("Rect"); + return _( "Rect" ); case PAD_TRAPEZOID: - return _("Trap"); + return _( "Trap" ); default: - return wxT("??Unknown??"); + return wxT( "??Unknown??" ); } } @@ -886,19 +916,19 @@ wxString D_PAD::ShowPadAttr() const switch( m_Attribut & 0x0F ) { case PAD_STANDARD: - return _("Std"); + return _( "Std" ); case PAD_SMD: - return _("Smd"); + return _( "Smd" ); case PAD_CONN: - return _("Conn"); + return _( "Conn" ); case PAD_HOLE_NOT_PLATED: - return _("Not Plated"); + return _( "Not Plated" ); default: - return wxT("??Unkown??"); + return wxT( "??Unkown??" ); } } @@ -910,11 +940,11 @@ wxString D_PAD::GetSelectMenuText() const text << _( "Pad" ) << wxT( " \"" ) << ReturnStringPadName() << wxT( "\" (" ); - if ( (m_Masque_Layer & ALL_CU_LAYERS) == ALL_CU_LAYERS ) + if ( (m_layerMask & ALL_CU_LAYERS) == ALL_CU_LAYERS ) text << _("all copper layers"); - else if( (m_Masque_Layer & LAYER_BACK ) == LAYER_BACK ) + else if( (m_layerMask & LAYER_BACK ) == LAYER_BACK ) text << board->GetLayerName(LAYER_N_BACK); - else if( (m_Masque_Layer & LAYER_FRONT) == LAYER_FRONT ) + else if( (m_layerMask & LAYER_FRONT) == LAYER_FRONT ) text << board->GetLayerName(LAYER_N_FRONT); else text << _( "???" ); @@ -935,12 +965,11 @@ wxString D_PAD::GetSelectMenuText() const */ void D_PAD::Show( int nestLevel, std::ostream& os ) { - char padname[5] = - { m_Padname[0], m_Padname[1], m_Padname[2], m_Padname[3], 0 }; + char padname[5] = { m_Padname[0], m_Padname[1], m_Padname[2], m_Padname[3], 0 }; char layerMask[16]; - sprintf( layerMask, "0x%08X", m_Masque_Layer ); + sprintf( layerMask, "0x%08X", m_layerMask ); // for now, make it look like XML: NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index 4cf26e06c1..ef5d56d157 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -73,7 +73,7 @@ public: */ }; - int m_Masque_Layer; // Bitwise layer :1= copper layer, 15= cmp, + int m_layerMask; // Bitwise layer :1= copper layer, 15= cmp, // 2..14 = internal layers // 16 .. 31 = technical layers diff --git a/pcbnew/class_pad_draw_functions.cpp b/pcbnew/class_pad_draw_functions.cpp index bd1eaf1d70..88ed7541de 100644 --- a/pcbnew/class_pad_draw_functions.cpp +++ b/pcbnew/class_pad_draw_functions.cpp @@ -97,29 +97,30 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDraw_mode, const wxPoi /* If pad are only on front side (no layer on back side) * and if hide front side pads is enabled, do not draw */ - if( !frontVisible && ( (m_Masque_Layer & BACK_SIDE_LAYERS) == 0 ) ) + if( !frontVisible && ( (m_layerMask & BACK_SIDE_LAYERS) == 0 ) ) return; /* If pad are only on back side (no layer on front side) * and if hide back side pads is enabled, do not draw */ - if( !backVisible && ( (m_Masque_Layer & FRONT_SIDE_LAYERS) == 0 ) ) + if( !backVisible && ( (m_layerMask & FRONT_SIDE_LAYERS) == 0 ) ) return; PCB_BASE_FRAME* frame = (PCB_BASE_FRAME*) aPanel->GetParent(); PCB_SCREEN* screen = frame->GetScreen(); + if( frame->m_DisplayPadFill == FILLED ) drawInfo.m_ShowPadFilled = true; else drawInfo.m_ShowPadFilled = false; - if( m_Masque_Layer & LAYER_FRONT ) + if( m_layerMask & LAYER_FRONT ) { color = brd->GetVisibleElementColor( PAD_FR_VISIBLE ); } - if( m_Masque_Layer & LAYER_BACK ) + if( m_layerMask & LAYER_BACK ) { color |= brd->GetVisibleElementColor( PAD_BK_VISIBLE ); } @@ -128,7 +129,7 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDraw_mode, const wxPoi { // If the pad in on only one tech layer, use the layer color // else use DARKGRAY - int mask_non_copper_layers = m_Masque_Layer & ~ALL_CU_LAYERS; + int mask_non_copper_layers = m_layerMask & ~ALL_CU_LAYERS; #ifdef SHOW_PADMASK_REAL_SIZE_AND_COLOR mask_non_copper_layers &= brd->GetVisibleLayers(); #endif @@ -208,8 +209,7 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDraw_mode, const wxPoi } // if PAD_SMD pad and high contrast mode - if( ( m_Attribut == PAD_SMD || m_Attribut == PAD_CONN ) - && DisplayOpt.ContrastModeDisplay ) + if( ( m_Attribut == PAD_SMD || m_Attribut == PAD_CONN ) && DisplayOpt.ContrastModeDisplay ) { // when routing tracks if( frame && frame->GetToolId() == ID_TRACK_BUTT ) @@ -220,10 +220,8 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDraw_mode, const wxPoi // if routing between copper and component layers, // or the current layer is one of said 2 external copper layers, // then highlight only the current layer. - if( ( ( 1 << routeTop ) | ( 1 << routeBot ) ) - == ( LAYER_BACK | LAYER_FRONT ) - || ( ( 1 << screen->m_Active_Layer ) - & ( LAYER_BACK | LAYER_FRONT ) ) ) + if( ( ( 1 << routeTop ) | ( 1 << routeBot ) ) == ( LAYER_BACK | LAYER_FRONT ) + || ( ( 1 << screen->m_Active_Layer ) & ( LAYER_BACK | LAYER_FRONT ) ) ) { if( !IsOnLayer( screen->m_Active_Layer ) ) { @@ -319,8 +317,9 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDraw_mode, const wxPoi color = ColorRefs[color & MASKCOLOR].m_LightColor; bool DisplayIsol = DisplayOpt.DisplayPadIsol; - if( ( m_Masque_Layer & ALL_CU_LAYERS ) == 0 ) - DisplayIsol = FALSE; + + if( ( m_layerMask & ALL_CU_LAYERS ) == 0 ) + DisplayIsol = false; if( m_Attribut == PAD_HOLE_NOT_PLATED ) drawInfo.m_ShowNotPlatedHole = true; @@ -339,12 +338,12 @@ void D_PAD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, int aDraw_mode, const wxPoi * needed (never needed in Cvpcb nor in Gerbview) */ drawInfo.m_PadClearance = DisplayIsol ? GetClearance() : 0; + /* Draw the pad number */ if( frame && !frame->m_DisplayPadNum ) drawInfo.m_Display_padnum = false; - if( ( DisplayOpt.DisplayNetNamesMode == 0 ) - || ( DisplayOpt.DisplayNetNamesMode == 2 ) ) + if( ( DisplayOpt.DisplayNetNamesMode == 0 ) || ( DisplayOpt.DisplayNetNamesMode == 2 ) ) drawInfo.m_Display_netname = false; // Display net names is restricted to pads that are on the active layer @@ -378,6 +377,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) wxSize halfsize = m_Size; halfsize.x >>= 1; halfsize.y >>= 1; + switch( GetShape() ) { case PAD_CIRCLE: @@ -398,6 +398,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) 0, aDrawInfo.m_Color ); } + break; case PAD_OVAL: @@ -406,6 +407,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) seg_width = BuildSegmentFromOvalShape(segStart, segEnd, angle); segStart += shape_pos; segEnd += shape_pos; + if( aDrawInfo.m_ShowPadFilled ) { GRFillCSegm( aClipBox, aDC, segStart.x, segStart.y, segEnd.x, segEnd.y, @@ -430,6 +432,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) case PAD_RECT: case PAD_TRAPEZOID: BuildPadPolygon( coord, aDrawInfo.m_Mask_margin, angle ); + for( int ii = 0; ii < 4; ii++ ) coord[ii] += shape_pos; @@ -458,11 +461,14 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) int hole = m_Drill.x >> 1; bool drawhole = hole > 0; + if( !aDrawInfo.m_ShowPadFilled && !aDrawInfo. m_ShowNotPlatedHole ) drawhole = false; + if( drawhole ) { bool blackpenstate = false; + if( aDrawInfo.m_IsPrinting ) { blackpenstate = GetGRForceBlackPenState(); @@ -476,6 +482,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) GRSetDrawMode( aDC, GR_XOR ); int hole_color = aDrawInfo.m_HoleColor; + if( aDrawInfo. m_ShowNotPlatedHole ) // Draw a specific hole color hole_color = aDrawInfo.m_NPHoleColor; @@ -503,6 +510,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) delta_cy = halfsize.y - halfsize.x; seg_width = m_Drill.x; } + RotatePoint( &delta_cx, &delta_cy, angle ); GRFillCSegm( aClipBox, aDC, holepos.x + delta_cx, holepos.y + delta_cy, @@ -526,11 +534,11 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) int dx0 = MIN( halfsize.x, halfsize.y ); int nc_color = BLUE; - if( m_Masque_Layer & LAYER_FRONT ) /* Draw \ */ + if( m_layerMask & LAYER_FRONT ) /* Draw \ */ GRLine( aClipBox, aDC, holepos.x - dx0, holepos.y - dx0, holepos.x + dx0, holepos.y + dx0, 0, nc_color ); - if( m_Masque_Layer & LAYER_BACK ) /* Draw / */ + if( m_layerMask & LAYER_BACK ) /* Draw / */ GRLine( aClipBox, aDC, holepos.x + dx0, holepos.y - dx0, holepos.x - dx0, holepos.y + dx0, 0, nc_color ); } @@ -544,11 +552,15 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) wxSize AreaSize; // size of text area, normalized to // AreaSize.y < AreaSize.x int shortname_len = m_ShortNetname.Len(); + if( !aDrawInfo.m_Display_netname ) shortname_len = 0; + if( GetShape() == PAD_CIRCLE ) angle = 0; + AreaSize = m_Size; + if( m_Size.y > m_Size.x ) { angle += 900; @@ -556,12 +568,10 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) AreaSize.y = m_Size.x; } - if( shortname_len > 0 ) // if there is a netname, provides room - // to display this netname + if( shortname_len > 0 ) // if there is a netname, provides room to display this netname { - AreaSize.y /= 2; // Text used only the upper area of the - // pad. The lower area displays the net - // name + AreaSize.y /= 2; // Text used only the upper area of the + // pad. The lower area displays the net name tpos.y -= AreaSize.y / 2; } @@ -581,6 +591,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) wxString buffer; int tsize; + if( aDrawInfo.m_Display_padnum ) { ReturnStringPadName( buffer ); @@ -610,8 +621,10 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) if( aDC->LogicalToDeviceXRel( tsize ) >= CHAR_SIZE_MIN ) // Not drawable in size too small. { tpos = tpos0; + if( aDrawInfo.m_Display_padnum ) tpos.y += AreaSize.y / 2; + RotatePoint( &tpos, shape_pos, angle ); // tsize reserve room for marges and segments thickness @@ -622,6 +635,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) } } + /** * Function BuildSegmentFromOvalShape * Has meaning only for OVAL (and ROUND) pads. @@ -632,6 +646,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) int D_PAD::BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd, int aRotation) const { int width; + if( m_Size.y < m_Size.x ) // Build an horizontal equiv segment { int delta = ( m_Size.x - m_Size.y ) / 2; @@ -660,6 +675,7 @@ int D_PAD::BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd, int a return width; } + /** * Function BuildPadPolygon * Has meaning only for polygonal pads (trapeziod and rectangular) @@ -690,6 +706,7 @@ void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotat // Only possible for inflate negative values. if( halfsize.x < 0 ) halfsize.x = 0; + if( halfsize.y < 0 ) halfsize.y = 0; } @@ -702,10 +719,13 @@ void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotat // be sure delta values are not to large if( (delta.x < 0) && (delta.x <= -halfsize.y) ) delta.x = -halfsize.y + 1; + if( (delta.x > 0) && (delta.x >= halfsize.y) ) delta.x = halfsize.y - 1; + if( (delta.y < 0) && (delta.y <= -halfsize.x) ) delta.y = -halfsize.x + 1; + if( (delta.y > 0) && (delta.y >= halfsize.x) ) delta.y = halfsize.x - 1; } @@ -730,6 +750,7 @@ void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotat { double angle; wxSize corr; + if( delta.y ) // lower and upper segment is horizontal { // Calculate angle of left (or right) segment with vertical axis @@ -766,6 +787,7 @@ void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotat { delta = aInflateValue; // this pad is rectangular (delta null). } + aCoord[0].x += -delta.x - corr.x; // lower left aCoord[0].y += delta.y + corr.y; @@ -786,10 +808,13 @@ void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotat if( aCoord[0].x > 0 ) // lower left x coordinate must be <= 0 aCoord[0].x = aCoord[3].x = 0; + if( aCoord[1].x > 0 ) // upper left x coordinate must be <= 0 aCoord[1].x = aCoord[2].x = 0; + if( aCoord[0].y < 0 ) // lower left y coordinate must be >= 0 aCoord[0].y = aCoord[1].y = 0; + if( aCoord[3].y < 0 ) // lower right y coordinate must be >= 0 aCoord[3].y = aCoord[2].y = 0; } diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 4260f7237b..95410d1dae 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -30,10 +30,8 @@ static bool ShowClearance( const TRACK* aTrack ) } -/**********************************************************/ TRACK::TRACK( BOARD_ITEM* aParent, KICAD_T idtype ) : BOARD_CONNECTED_ITEM( aParent, idtype ) -/**********************************************************/ { m_Width = 0; m_Shape = S_SEGMENT; @@ -174,6 +172,7 @@ TRACK* TRACK::Copy() const return NULL; // should never happen } + /** * Function GetClearance (virtual) * returns the clearance in internal units. If \a aItem is not NULL then the @@ -192,6 +191,7 @@ int TRACK::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const return BOARD_CONNECTED_ITEM::GetClearance( aItem ); } + /** * Function GetDrillValue * calculate the drill value for vias (m_Drill if > 0, or default drill value for the Netclass @@ -215,11 +215,8 @@ int TRACK::GetDrillValue() const } -/***********************/ -bool TRACK::IsNull() -/***********************/ - // return true if segment length = 0 +bool TRACK::IsNull() { if( ( Type() != TYPE_VIA ) && ( m_Start == m_End ) ) return true; @@ -228,10 +225,6 @@ bool TRACK::IsNull() } -/*************************************************************/ -int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) -/*************************************************************/ - /* Return: * STARTPOINT if point if near (dist = min_dist) star point * ENDPOINT if point if near (dist = min_dist) end point @@ -239,6 +232,7 @@ int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) * 0 if no * if min_dist < 0: min_dist = track_width/2 */ +int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) { int result = 0; @@ -256,12 +250,14 @@ int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) else { double dist = hypot( (double)dx, (double) dy ); + if( min_dist >= (int) dist ) result |= STARTPOINT; } dx = m_End.x - point.x; dy = m_End.y - point.y; + if( min_dist == 0 ) { if( (dx == 0) && (dy == 0 ) ) @@ -270,6 +266,7 @@ int TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) else { double dist = hypot( (double) dx, (double) dy ); + if( min_dist >= (int) dist ) result |= ENDPOINT; } @@ -356,11 +353,15 @@ void TRACK::Flip( const wxPoint& aCentre ) { m_Start.y = aCentre.y - (m_Start.y - aCentre.y); m_End.y = aCentre.y - (m_End.y - aCentre.y); + if( Type() == TYPE_VIA ) { + // Huh? Wouldn't it be better to us Type() != VIA and get rid of these brackets? } else + { SetLayer( ChangeSideNumLayer( GetLayer() ) ); + } } @@ -386,9 +387,7 @@ SEARCH_RESULT TRACK::Visit( INSPECTOR* inspector, const void* testData, } -/***********************************************/ bool SEGVIA::IsOnLayer( int layer_number ) const -/***********************************************/ { int bottom_layer, top_layer; @@ -401,12 +400,10 @@ bool SEGVIA::IsOnLayer( int layer_number ) const } -/***********************************/ -int TRACK::ReturnMaskLayer() -/***********************************/ /* Return the mask layer for this. * for a via, there is more than one layer used */ +int TRACK::ReturnMaskLayer() { if( Type() == TYPE_VIA ) { @@ -423,6 +420,7 @@ int TRACK::ReturnMaskLayer() ( (SEGVIA*) this )->ReturnLayerPair( &top_layer, &bottom_layer ); int layermask = 0; + while( bottom_layer <= top_layer ) { layermask |= g_TabOneLayerMask[bottom_layer++]; @@ -431,14 +429,12 @@ int TRACK::ReturnMaskLayer() return layermask; } else + { return g_TabOneLayerMask[m_Layer]; + } } -/*********************************************************/ -void SEGVIA::SetLayerPair( int top_layer, int bottom_layer ) -/*********************************************************/ - /** Set the .m_Layer member param: * For a via m_Layer contains the 2 layers : * top layer and bottom layer used by the via. @@ -447,6 +443,7 @@ void SEGVIA::SetLayerPair( int top_layer, int bottom_layer ) * @param top_layer = first layer connected by the via * @param bottom_layer = last layer connected by the via */ +void SEGVIA::SetLayerPair( int top_layer, int bottom_layer ) { if( Shape() == VIA_THROUGH ) { @@ -461,10 +458,6 @@ void SEGVIA::SetLayerPair( int top_layer, int bottom_layer ) } -/*********************************************************************/ -void SEGVIA::ReturnLayerPair( int* top_layer, int* bottom_layer ) const -/*********************************************************************/ - /** * Function ReturnLayerPair * Return the 2 layers used by the via (the via actually uses @@ -472,6 +465,7 @@ void SEGVIA::ReturnLayerPair( int* top_layer, int* bottom_layer ) const * @param top_layer = pointer to the first layer (can be null) * @param bottom_layer = pointer to the last layer (can be null) */ +void SEGVIA::ReturnLayerPair( int* top_layer, int* bottom_layer ) const { int b_layer = LAYER_N_BACK; int t_layer = LAYER_N_FRONT; @@ -480,6 +474,7 @@ void SEGVIA::ReturnLayerPair( int* top_layer, int* bottom_layer ) const { b_layer = (m_Layer >> 4) & 15; t_layer = m_Layer & 15; + if( b_layer > t_layer ) EXCHG( b_layer, t_layer ); } @@ -511,13 +506,10 @@ TRACK* TRACK::GetBestInsertPoint( BOARD* aPcb ) } -/*******************************************/ -TRACK* TRACK::GetStartNetCode( int NetCode ) -/*******************************************/ - /* Search (within the track linked list) the first segment matching the netcode * ( the linked list is always sorted by net codes ) */ +TRACK* TRACK::GetStartNetCode( int NetCode ) { TRACK* Track = this; int ii = 0; @@ -546,13 +538,10 @@ TRACK* TRACK::GetStartNetCode( int NetCode ) } -/*****************************************/ -TRACK* TRACK::GetEndNetCode( int NetCode ) -/*****************************************/ - /* Search (within the track linked list) the last segment matching the netcode * ( the linked list is always sorted by net codes ) */ +TRACK* TRACK::GetEndNetCode( int NetCode ) { TRACK* NextS, * Track = this; int ii = 0; @@ -566,6 +555,7 @@ TRACK* TRACK::GetEndNetCode( int NetCode ) while( Track != NULL ) { NextS = (TRACK*) Track->Pnext; + if( Track->GetNet() == NetCode ) ii++; @@ -603,13 +593,11 @@ bool TRACK::Save( FILE* aFile ) const } -/*********************************************************************/ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& aOffset ) -/*********************************************************************/ { - int l_piste; + int l_trace; int color; - int rayon; + int radius; int curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer; if( Type() == TYPE_ZONE && DisplayOpt.DisplayZonesMode != 0 ) @@ -618,8 +606,7 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& BOARD * brd = GetBoard( ); color = brd->GetLayerColor(m_Layer); - if( brd->IsLayerVisible( m_Layer ) == false && ( color & HIGHLIGHT_FLAG ) != - HIGHLIGHT_FLAG ) + if( brd->IsLayerVisible( m_Layer ) == false && ( color & HIGHLIGHT_FLAG ) != HIGHLIGHT_FLAG ) return; if( DisplayOpt.ContrastModeDisplay ) @@ -647,44 +634,43 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& GRSetDrawMode( DC, draw_mode ); - l_piste = m_Width >> 1; + l_trace = m_Width >> 1; if( m_Shape == S_CIRCLE ) { - rayon = (int) hypot( (double) ( m_End.x - m_Start.x ), - (double) ( m_End.y - m_Start.y ) ); + radius = (int) hypot( (double) ( m_End.x - m_Start.x ), + (double) ( m_End.y - m_Start.y ) ); - if( DC->LogicalToDeviceXRel( l_piste ) < L_MIN_DESSIN ) + if( DC->LogicalToDeviceXRel( l_trace ) < L_MIN_DESSIN ) { GRCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x, - m_Start.y + aOffset.y, rayon, color ); + m_Start.y + aOffset.y, radius, color ); } else { - if( DC->LogicalToDeviceXRel( l_piste ) <= 1 ) /* Sketch mode if l_piste/zoom <= 1 */ + if( DC->LogicalToDeviceXRel( l_trace ) <= 1 ) /* Sketch mode if l_trace/zoom <= 1 */ { GRCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x, - m_Start.y + aOffset.y, rayon, color ); + m_Start.y + aOffset.y, radius, color ); } else if( ( !DisplayOpt.DisplayPcbTrackFill) || GetState( FORCE_SKETCH ) ) { GRCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x, - m_Start.y + aOffset.y, rayon - l_piste, color ); + m_Start.y + aOffset.y, radius - l_trace, color ); GRCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x, - m_Start.y + aOffset.y, rayon + l_piste, color ); + m_Start.y + aOffset.y, radius + l_trace, color ); } else { GRCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x, - m_Start.y + aOffset.y, rayon, - m_Width, color ); + m_Start.y + aOffset.y, radius, m_Width, color ); } } return; } - if( DC->LogicalToDeviceXRel( l_piste ) < L_MIN_DESSIN ) + if( DC->LogicalToDeviceXRel( l_trace ) < L_MIN_DESSIN ) { GRLine( &panel->m_ClipBox, DC, m_Start + aOffset, m_End + aOffset, 0, color ); return; @@ -724,12 +710,10 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& return; #define THRESHOLD 10 - if( (m_End.x - m_Start.x) != 0 - && (m_End.y - m_Start.y) != 0 ) + if( (m_End.x - m_Start.x) != 0 && (m_End.y - m_Start.y) != 0 ) return; - int len = ABS( (m_End.x - m_Start.x) - + (m_End.y - m_Start.y) ); + int len = ABS( (m_End.x - m_Start.x) + (m_End.y - m_Start.y) ); if( len < THRESHOLD * m_Width ) return; @@ -739,11 +723,14 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& if( GetNet() == 0 ) return; + NETINFO_ITEM* net = ( (BOARD*) GetParent() )->FindNet( GetNet() ); + if( net == NULL ) return; int textlen = net->GetShortNetname().Len(); + if( textlen > 0 ) { // calculate a good size for the text @@ -754,6 +741,7 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& // Calculate angle: if the track segment is vertical, angle = 90 degrees int angle = 0; + if( (m_End.x - m_Start.x) == 0 ) // Vertical segment angle = 900; // angle is in 0.1 degree @@ -772,12 +760,10 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& } -/*******************************************************************************************/ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint& aOffset ) -/*******************************************************************************************/ { int color; - int rayon; + int radius; int curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer; int fillvia = 0; @@ -819,17 +805,17 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint SetAlpha( &color, 150 ); - rayon = m_Width >> 1; - // for small via size on screen (rayon < 4 pixels) draw a simplified shape + radius = m_Width >> 1; + // for small via size on screen (radius < 4 pixels) draw a simplified shape - int radius_in_pixels = DC->LogicalToDeviceXRel( rayon ); + int radius_in_pixels = DC->LogicalToDeviceXRel( radius ); bool fast_draw = false; // Vias are drawn as a filled circle or a double circle. The hole will be drawn later - int drill_rayon = GetDrillValue() / 2; + int drill_radius = GetDrillValue() / 2; - int inner_rayon = rayon - DC->DeviceToLogicalXRel( 2 ); + int inner_radius = radius - DC->DeviceToLogicalXRel( 2 ); if( radius_in_pixels < 3 ) { @@ -838,25 +824,27 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint } if( fillvia ) - GRFilledCircle( &panel->m_ClipBox, DC, m_Start + aOffset, rayon, color ); - + { + GRFilledCircle( &panel->m_ClipBox, DC, m_Start + aOffset, radius, color ); + } else { - GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset,rayon, 0, color ); + GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset,radius, 0, color ); if ( fast_draw ) return; - GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset, inner_rayon, 0, color ); + GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset, inner_radius, 0, color ); } // Draw the via hole if the display option allows it if( DisplayOpt.m_DisplayViaMode != VIA_HOLE_NOT_SHOW ) { if( (DisplayOpt.m_DisplayViaMode == ALL_VIA_HOLE_SHOW) // Display all drill holes requested - || ( (drill_rayon > 0 ) && !IsDrillDefault() ) ) // Or Display non default holes requested + || ( (drill_radius > 0 ) && !IsDrillDefault() ) ) // Or Display non default holes requested { if( fillvia ) { bool blackpenstate = false; + if( screen->m_IsPrinting ) { blackpenstate = GetGRForceBlackPenState(); @@ -864,31 +852,32 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint color = g_DrawBgColor; } else + { color = BLACK; // or DARKGRAY; + } if( draw_mode != GR_XOR ) GRSetDrawMode( DC, GR_COPY ); else GRSetDrawMode( DC, GR_XOR ); - if( DC->LogicalToDeviceXRel( drill_rayon ) > 1 ) // Draw hole if large enough. + if( DC->LogicalToDeviceXRel( drill_radius ) > 1 ) // Draw hole if large enough. GRFilledCircle( &panel->m_ClipBox, DC, m_Start.x + aOffset.x, - m_Start.y + aOffset.y, drill_rayon, 0, color, color ); + m_Start.y + aOffset.y, drill_radius, 0, color, color ); if( screen->m_IsPrinting ) GRForceBlackPen( blackpenstate ); } else { - if( drill_rayon < inner_rayon ) // We can show the via hole - GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset, drill_rayon, 0, color ); + if( drill_radius < inner_radius ) // We can show the via hole + GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset, drill_radius, 0, color ); } } } if( DisplayOpt.ShowTrackClearanceMode == SHOW_CLEARANCE_ALWAYS ) - GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset, - rayon + GetClearance(), 0, color ); + GRCircle( &panel->m_ClipBox, DC, m_Start + aOffset, radius + GetClearance(), 0, color ); // for Micro Vias, draw a partial cross : // X on component layer, or + on copper layer @@ -899,13 +888,13 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint if( IsOnLayer( LAYER_N_BACK ) ) { - ax = rayon; ay = 0; - bx = drill_rayon; by = 0; + ax = radius; ay = 0; + bx = drill_radius; by = 0; } else { - ax = ay = (rayon * 707) / 1000; - bx = by = (drill_rayon * 707) / 1000; + ax = ay = (radius * 707) / 1000; + bx = by = (drill_radius * 707) / 1000; } /* lines | or \ */ @@ -934,7 +923,7 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint // (so we can see superimposed buried vias ): if( Shape() == VIA_BLIND_BURIED ) { - int ax = 0, ay = rayon, bx = 0, by = drill_rayon; + int ax = 0, ay = radius, bx = 0, by = drill_radius; int layer_top, layer_bottom; ( (SEGVIA*) this )->ReturnLayerPair( &layer_top, &layer_bottom ); @@ -948,7 +937,7 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint m_Start.y + aOffset.y - by, 0, color ); /* lines for the bottom layer */ - ax = 0; ay = rayon; bx = 0; by = drill_rayon; + ax = 0; ay = radius; bx = 0; by = drill_radius; RotatePoint( &ax, &ay, layer_bottom * 3600 / brd->GetCopperLayerCount( ) ); RotatePoint( &bx, &by, layer_bottom * 3600 / brd->GetCopperLayerCount( ) ); GRLine( &panel->m_ClipBox, DC, m_Start.x + aOffset.x - ax, @@ -960,13 +949,17 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode, const wxPoint // Display the short netname: if( GetNet() == 0 ) return; + if( DisplayOpt.DisplayNetNamesMode == 0 || DisplayOpt.DisplayNetNamesMode == 1 ) return; + NETINFO_ITEM* net = ( (BOARD*) GetParent() )->FindNet( GetNet() ); + if( net == NULL ) return; int len = net->GetShortNetname().Len(); + if( len > 0 ) { // calculate a good size for the text @@ -998,9 +991,10 @@ void TRACK::DisplayInfo( EDA_DRAW_FRAME* frame ) { int trackLen = 0; int lenDie = 0; - Marque_Une_Piste( board, this, NULL, &trackLen, &lenDie, false ); + MarkTrace( board, this, NULL, &trackLen, &lenDie, false ); msg = frame->CoordinateToString( trackLen ); frame->AppendMsgPanel( _( "Track Len" ), msg, DARKCYAN ); + if( lenDie != 0 ) { msg = frame->CoordinateToString( trackLen + lenDie ); @@ -1092,6 +1086,7 @@ void TRACK::DisplayInfoBase( EDA_DRAW_FRAME* frame ) /* Display the State member */ msg = wxT( ". . " ); + if( GetState( TRACK_LOCKED ) ) msg[0] = 'F'; @@ -1107,11 +1102,12 @@ void TRACK::DisplayInfoBase( EDA_DRAW_FRAME* frame ) int top_layer, bottom_layer; Via->ReturnLayerPair( &top_layer, &bottom_layer ); - msg = board->GetLayerName( top_layer ) + wxT( "/" ) - + board->GetLayerName( bottom_layer ); + msg = board->GetLayerName( top_layer ) + wxT( "/" ) + board->GetLayerName( bottom_layer ); } else + { msg = board->GetLayerName( m_Layer ); + } frame->AppendMsgPanel( _( "Layer" ), msg, BROWN ); @@ -1172,8 +1168,7 @@ bool TRACK::HitTest( const wxPoint& refPos ) if( Type() == TYPE_VIA ) { - return (double) spot_cX * spot_cX + (double) spot_cY * spot_cY <= - (double) radius * radius; + return (double) spot_cX * spot_cX + (double) spot_cY * spot_cY <= (double) radius * radius; } else { @@ -1196,8 +1191,10 @@ bool TRACK::HitTest( EDA_RECT& refArea ) { if( refArea.Contains( m_Start ) ) return true; + if( refArea.Contains( m_End ) ) return true; + return false; } @@ -1305,11 +1302,11 @@ void SEGVIA::Show( int nestLevel, std::ostream& os ) if( board ) os << " layers=\"" << board->GetLayerName( topLayer ).Trim().mb_str() << "," << board->GetLayerName( botLayer ).Trim().mb_str() << '"'; - os << - " width=\"" << m_Width << '"' << - " drill=\"" << GetDrillValue() << '"' << - " netcode=\"" << GetNet() << "\">" << - ""; + + os << " width=\"" << m_Width << '"' + << " drill=\"" << GetDrillValue() << '"' + << " netcode=\"" << GetNet() << "\">" + << ""; os << "\n"; } @@ -1321,26 +1318,37 @@ wxString TRACK::ShowState( int stateBits ) if( stateBits & IS_LINKED ) ret << wxT( " | IS_LINKED" ); + if( stateBits & TRACK_AR ) ret << wxT( " | TRACK_AR" ); + if( stateBits & TRACK_LOCKED ) ret << wxT( " | TRACK_LOCKED" ); + if( stateBits & IN_EDIT ) ret << wxT( " | IN_EDIT" ); + if( stateBits & IS_DRAGGED ) ret << wxT( " | IS_DRAGGED" ); + if( stateBits & DO_NOT_DRAW ) ret << wxT( " | DO_NOT_DRAW" ); + if( stateBits & IS_DELETED ) ret << wxT( " | IS_DELETED" ); + if( stateBits & BUSY ) ret << wxT( " | BUSY" ); + if( stateBits & END_ONPAD ) ret << wxT( " | END_ONPAD" ); + if( stateBits & BEGIN_ONPAD ) ret << wxT( " | BEGIN_ONPAD" ); + if( stateBits & FLAG0 ) ret << wxT( " | FLAG0" ); + if( stateBits & FLAG1 ) ret << wxT( " | FLAG1" ); diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index c78b168308..f58dd38b7b 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -77,41 +77,42 @@ wxPoint& ZONE_CONTAINER::GetPosition() } else pos = wxPoint( 0, 0 ); + return pos; } -/*******************************************/ -void ZONE_CONTAINER::SetNet( int anet_code ) -{ -/*******************************************/ /** * Set the netcode and the netname * if netcode >= 0, set the netname * if netcode < 0: keep old netname (used to set an necode error flag) */ +void ZONE_CONTAINER::SetNet( int anet_code ) +{ m_NetCode = anet_code; if( anet_code < 0 ) return; BOARD* board = GetBoard(); + if( board ) { NETINFO_ITEM* net = board->FindNet( anet_code ); + if( net ) m_Netname = net->GetNetname(); else m_Netname.Empty(); } else + { m_Netname.Empty(); + } } -/********************************************/ bool ZONE_CONTAINER::Save( FILE* aFile ) const -/********************************************/ { unsigned item_pos; int ret; @@ -123,13 +124,15 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const // Save the outline main info ret = fprintf( aFile, "ZInfo %8.8lX %d %s\n", - m_TimeStamp, m_NetCode, - EscapedUTF8( m_Netname ).c_str() ); + m_TimeStamp, m_NetCode, + EscapedUTF8( m_Netname ).c_str() ); + if( ret < 3 ) return false; // Save the outline layer info ret = fprintf( aFile, "ZLayer %d\n", m_Layer ); + if( ret < 1 ) return false; @@ -151,6 +154,7 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const } ret = fprintf( aFile, "ZAux %d %c\n", corners_count, outline_hatch ); + if( ret < 2 ) return false; @@ -172,10 +176,12 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const } ret = fprintf( aFile, "ZClearance %d %c\n", m_ZoneClearance, padoption ); + if( ret < 2 ) return false; ret = fprintf( aFile, "ZMinThickness %d\n", m_ZoneMinThickness ); + if( ret < 1 ) return false; @@ -186,12 +192,14 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const m_IsFilled ? 'S' : 'F', m_ThermalReliefGapValue, m_ThermalReliefCopperBridgeValue ); + if( ret < 3 ) return false; ret = fprintf( aFile, "ZSmoothing %d %d\n", cornerSmoothingType, cornerRadius ); + if( ret < 2 ) return false; @@ -201,6 +209,7 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const ret = fprintf( aFile, "ZCorner %d %d %d\n", m_Poly->corner[item_pos].x, m_Poly->corner[item_pos].y, m_Poly->corner[item_pos].end_contour ); + if( ret < 3 ) return false; } @@ -209,6 +218,7 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const if( m_FilledPolysList.size() ) { fprintf( aFile, "$POLYSCORNERS\n" ); + for( unsigned ii = 0; ii < m_FilledPolysList.size(); ii++ ) { const CPolyPt* corner = &m_FilledPolysList[ii]; @@ -218,6 +228,7 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const corner->y, corner->end_contour, corner->utility ); + if( ret < 4 ) return false; } @@ -229,27 +240,28 @@ bool ZONE_CONTAINER::Save( FILE* aFile ) const if( m_FillSegmList.size() ) { fprintf( aFile, "$FILLSEGMENTS\n" ); + for( unsigned ii = 0; ii < m_FillSegmList.size(); ii++ ) { ret = fprintf( aFile, "%d %d %d %d\n", m_FillSegmList[ii].m_Start.x, m_FillSegmList[ii].m_Start.y, m_FillSegmList[ii].m_End.x, m_FillSegmList[ii].m_End.y ); + if( ret < 4 ) return false; } fprintf( aFile, "$endFILLSEGMENTS\n" ); } + fprintf( aFile, "$endCZONE_OUTLINE\n" ); return true; } -/**********************************************************/ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) { -/**********************************************************/ char* Line, * text; char netname_buffer[1024]; int ret; @@ -257,9 +269,11 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) bool error = false, has_corner = false; netname_buffer[0] = 0; + while( aReader->ReadLine() ) { Line = aReader->Line(); + if( strnicmp( Line, "ZCorner", 7 ) == 0 ) // new corner found { int x; @@ -268,8 +282,11 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) text = Line + 7; ret = sscanf( text, "%d %d %d", &x, &y, &flag ); + if( ret < 3 ) + { error = true; + } else { if( !has_corner ) @@ -278,6 +295,7 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) AppendCorner( wxPoint( x, y ) ); has_corner = true; + if( flag ) m_Poly->Close(); } @@ -289,8 +307,11 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) text = Line + 5; ret = sscanf( text, "%X %d %s", &ts, &netcode, netname_buffer ); + if( ret < 3 ) + { error = true; + } else { m_TimeStamp = ts; @@ -305,6 +326,7 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) text = Line + 6; ret = sscanf( text, "%d", &x ); + if( ret < 1 ) error = true; else @@ -317,8 +339,11 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) text = Line + 4; ret = sscanf( text, "%d %c", &x, hopt ); + if( ret < 2 ) + { error = true; + } else { switch( hopt[0] ) @@ -379,14 +404,17 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) m_IsFilled = (fillstate == 'S') ? true : false; } - else if( strnicmp( Line, "ZClearance", 10 ) == 0 ) // Clearance and pad options info found + else if( strnicmp( Line, "ZClearance", 10 ) == 0 ) // Clearance and pad options info found { int clearance = 200; char padoption; text = Line + 10; ret = sscanf( text, "%d %1c", &clearance, &padoption ); + if( ret < 2 ) + { error = true; + } else { m_ZoneClearance = clearance; @@ -415,6 +443,7 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) int thickness; text = Line + 13; ret = sscanf( text, "%d", &thickness ); + if( ret < 1 ) error = true; else @@ -425,8 +454,10 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) while( aReader->ReadLine() ) { Line = aReader->Line(); + if( strnicmp( Line, "$endPOLYSCORNERS", 4 ) == 0 ) break; + CPolyPt corner; int end_contour, utility; utility = 0; @@ -438,6 +469,7 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) &utility ); if( ret < 4 ) return false; + corner.end_contour = end_contour ? true : false; corner.utility = utility; m_FilledPolysList.push_back( corner ); @@ -449,8 +481,10 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) while( aReader->ReadLine() ) { Line = aReader->Line(); + if( strnicmp( Line, "$endFILLSEGMENTS", 4 ) == 0 ) break; + ret = sscanf( Line, "%d %d %d %d", &segm.m_Start.x, @@ -459,6 +493,7 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) &segm.m_End.y ); if( ret < 4 ) return false; + m_FillSegmList.push_back( segm ); } } @@ -492,8 +527,7 @@ void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int aDrawMode, const BOARD* brd = GetBoard(); int color = brd->GetLayerColor( m_Layer ); - if( brd->IsLayerVisible( m_Layer ) == false - && ( color & HIGHLIGHT_FLAG ) != HIGHLIGHT_FLAG ) + if( brd->IsLayerVisible( m_Layer ) == false && ( color & HIGHLIGHT_FLAG ) != HIGHLIGHT_FLAG ) return; GRSetDrawMode( DC, aDrawMode ); @@ -514,6 +548,7 @@ void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int aDrawMode, const else color |= HIGHLIGHT_FLAG; } + if( color & HIGHLIGHT_FLAG ) color = ColorRefs[color & MASKCOLOR].m_LightColor; @@ -528,7 +563,7 @@ void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int aDrawMode, const { seg_start = GetCornerPosition( ic ) + offset; - if( m_Poly->corner[ic].end_contour == FALSE && ic < GetNumCorners() - 1 ) + if( m_Poly->corner[ic].end_contour == false && ic < GetNumCorners() - 1 ) { seg_end = GetCornerPosition( ic + 1 ) + offset; } @@ -537,6 +572,7 @@ void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int aDrawMode, const seg_end = GetCornerPosition( i_start_contour ) + offset; i_start_contour = ic + 1; } + lines.push_back( seg_start ); lines.push_back( seg_end ); } @@ -561,11 +597,6 @@ void ZONE_CONTAINER::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, int aDrawMode, const } -/************************************************************************************/ -void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel, - wxDC* DC, int aDrawMode, const wxPoint& offset ) -{ -/************************************************************************************/ /** * Function DrawDrawFilledArea * Draws the filled areas for this zone (polygon list .m_FilledPolysList) @@ -574,6 +605,9 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel, * @param offset = Draw offset (usually wxPoint(0,0)) * @param aDrawMode = GR_OR, GR_XOR, GR_COPY .. */ +void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel, + wxDC* DC, int aDrawMode, const wxPoint& offset ) +{ static vector CornersTypeBuffer; static vector CornersBuffer; @@ -615,6 +649,7 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel, else color |= HIGHLIGHT_FLAG; } + if( color & HIGHLIGHT_FLAG ) color = ColorRefs[color & MASKCOLOR].m_LightColor; @@ -625,6 +660,7 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel, // Draw all filled areas int imax = m_FilledPolysList.size() - 1; + for( int ic = 0; ic <= imax; ic++ ) { CPolyPt* corner = &m_FilledPolysList[ic]; @@ -649,6 +685,7 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel, if( (m_ZoneMinThickness > 1) || outline_mode ) { int ilim = CornersBuffer.size() - 1; + for( int is = 0, ie = ilim; is <= ilim; ie = is, is++ ) { int x0 = CornersBuffer[is].x; @@ -675,6 +712,7 @@ void ZONE_CONTAINER::DrawFilledArea( EDA_DRAW_PANEL* panel, GRPoly( &panel->m_ClipBox, DC, CornersBuffer.size(), &CornersBuffer[0], true, 0, color, color ); } + CornersTypeBuffer.clear(); CornersBuffer.clear(); } @@ -725,10 +763,6 @@ EDA_RECT ZONE_CONTAINER::GetBoundingBox() const } -/**********************************************************************************************/ -void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode ) -{ -/***********************************************************************************************/ /** * Function DrawWhileCreateOutline * Draws the zone outline when ir is created. @@ -739,12 +773,15 @@ void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC, in * @param DC = current Device Context * @param draw_mode = draw mode: OR, XOR .. */ +void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC, int draw_mode ) +{ int current_gr_mode = draw_mode; bool is_close_segment = false; wxPoint seg_start, seg_end; if( DC == NULL ) return; + int curr_layer = ( (PCB_SCREEN*) panel->GetScreen() )->m_Active_Layer; BOARD* brd = GetBoard(); int color = brd->GetLayerColor( m_Layer ) & MASKCOLOR; @@ -758,20 +795,22 @@ void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC, in } } - // draw the lines wxPoint start_contour_pos = GetCornerPosition( 0 ); int icmax = GetNumCorners() - 1; + for( int ic = 0; ic <= icmax; ic++ ) { int xi = GetCornerPosition( ic ).x; int yi = GetCornerPosition( ic ).y; int xf, yf; - if( m_Poly->corner[ic].end_contour == FALSE && ic < icmax ) + + if( m_Poly->corner[ic].end_contour == false && ic < icmax ) { is_close_segment = false; xf = GetCornerPosition( ic + 1 ).x; yf = GetCornerPosition( ic + 1 ).y; + if( (m_Poly->corner[ic + 1].end_contour) || (ic == icmax - 1) ) current_gr_mode = GR_XOR; else @@ -788,7 +827,9 @@ void ZONE_CONTAINER::DrawWhileCreateOutline( EDA_DRAW_PANEL* panel, wxDC* DC, in if( ic < icmax ) start_contour_pos = GetCornerPosition( ic + 1 ); } + GRSetDrawMode( DC, current_gr_mode ); + if( is_close_segment ) GRLine( &panel->m_ClipBox, DC, xi, yi, xf, yf, 0, WHITE ); else @@ -808,6 +849,7 @@ bool ZONE_CONTAINER::HitTest( const wxPoint& refPos ) { if( HitTestForCorner( refPos ) ) return true; + if( HitTestForEdge( refPos ) ) return true; @@ -830,6 +872,7 @@ bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos ) #define CORNER_MIN_DIST 100 // distance (in internal units) to detect a corner in a zone outline int min_dist = CORNER_MIN_DIST + 1; + if( GetBoard() && GetBoard()->m_PcbFrame ) { // Use grid size because it is known @@ -839,12 +882,14 @@ bool ZONE_CONTAINER::HitTestForCorner( const wxPoint& refPos ) wxPoint delta; unsigned lim = m_Poly->corner.size(); + for( unsigned item_pos = 0; item_pos < lim; item_pos++ ) { delta.x = refPos.x - m_Poly->corner[item_pos].x; delta.y = refPos.y - m_Poly->corner[item_pos].y; // Calculate a distance: int dist = MAX( abs( delta.x ), abs( delta.y ) ); + if( dist < min_dist ) // this corner is a candidate: { m_CornerSelection = item_pos; @@ -874,6 +919,7 @@ bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos ) #define EDGE_MIN_DIST 200 // distance (in internal units) to detect a zone outline int min_dist = EDGE_MIN_DIST+1; + if( GetBoard() && GetBoard()->m_PcbFrame ) { // Use grid size because it is known @@ -882,6 +928,7 @@ bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos ) } unsigned first_corner_pos = 0; + for( unsigned item_pos = 0; item_pos < lim; item_pos++ ) { unsigned end_segm = item_pos + 1; @@ -899,11 +946,12 @@ bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos ) /* test the dist between segment and ref point */ int dist = (int) GetPointToLineSegmentDistance( refPos.x, - refPos.y, - m_Poly->corner[item_pos].x, - m_Poly->corner[item_pos].y, - m_Poly->corner[end_segm].x, - m_Poly->corner[end_segm].y ); + refPos.y, + m_Poly->corner[item_pos].x, + m_Poly->corner[item_pos].y, + m_Poly->corner[end_segm].x, + m_Poly->corner[end_segm].y ); + if( dist < min_dist ) { m_CornerSelection = item_pos; @@ -929,10 +977,13 @@ bool ZONE_CONTAINER::HitTest( EDA_RECT& refArea ) if( rect.left < refArea.GetX() ) is_out_of_box = true; + if( rect.top < refArea.GetY() ) is_out_of_box = true; + if( rect.right > refArea.GetRight() ) is_out_of_box = true; + if( rect.bottom > refArea.GetBottom() ) is_out_of_box = true; @@ -1011,6 +1062,7 @@ void ZONE_CONTAINER::DisplayInfo( EDA_DRAW_FRAME* frame ) msg = _( "Zone Outline" ); int ncont = m_Poly->GetContour( m_CornerSelection ); + if( ncont ) msg << wxT( " " ) << _( "(Cutout)" ); @@ -1037,7 +1089,9 @@ void ZONE_CONTAINER::DisplayInfo( EDA_DRAW_FRAME* frame ) frame->AppendMsgPanel( _( "NetName" ), msg, RED ); } else + { frame->AppendMsgPanel( _( "Non Copper Zone" ), wxEmptyString, RED ); + } /* Display net code : (useful in test or debug) */ msg.Printf( wxT( "%d" ), GetNet() ); @@ -1053,6 +1107,7 @@ void ZONE_CONTAINER::DisplayInfo( EDA_DRAW_FRAME* frame ) msg.Printf( _( "Segments" ), m_FillMode ); else msg = _( "Polygons" ); + frame->AppendMsgPanel( _( "Fill mode" ), msg, BROWN ); // Useful for statistics : @@ -1119,7 +1174,10 @@ void ZONE_CONTAINER::MoveEdge( const wxPoint& offset ) ii = m_Poly->GetContourStart( icont ); } else + { ii++; + } + SetCornerPosition( ii, GetCornerPosition( ii ) + offset ); m_Poly->Hatch(); diff --git a/pcbnew/class_zone.h b/pcbnew/class_zone.h index 01b258cfe0..ed8d296bfd 100644 --- a/pcbnew/class_zone.h +++ b/pcbnew/class_zone.h @@ -281,7 +281,7 @@ public: * @param verbose = true to show error messages * @return error level (0 = no error) */ - int Fill_Zone( PCB_EDIT_FRAME* frame, wxDC* DC, bool verbose = TRUE ); + int Fill_Zone( PCB_EDIT_FRAME* frame, wxDC* DC, bool verbose = true ); /** * Function Fill_Zone_Areas_With_Segments diff --git a/pcbnew/clean.cpp b/pcbnew/clean.cpp index 8cee96172d..0c8ae7fcde 100644 --- a/pcbnew/clean.cpp +++ b/pcbnew/clean.cpp @@ -31,17 +31,17 @@ static void ConnectDanglingEndToVia( BOARD* pcb ); #endif -/*****************************************/ -void PCB_EDIT_FRAME::Clean_Pcb( wxDC* DC ) -/*****************************************/ /* Install the track operation dialog frame */ +void PCB_EDIT_FRAME::Clean_Pcb( wxDC* DC ) { DIALOG_CLEANING_OPTIONS::connectToPads = false; DIALOG_CLEANING_OPTIONS dlg( this ); + if( dlg.ShowModal() == wxID_OK ) Clean_Pcb_Items( this, DC, dlg.cleanVias, dlg.mergeSegments, - dlg.deleteUnconnectedSegm, dlg.connectToPads ); + dlg.deleteUnconnectedSegm, dlg.connectToPads ); + DrawPanel->Refresh( true ); } @@ -115,6 +115,7 @@ void Clean_Pcb_Items( PCB_EDIT_FRAME* frame, wxDC* DC, frame->OnModify(); } + void clean_vias( BOARD * aPcb ) { TRACK* track; @@ -127,9 +128,11 @@ void clean_vias( BOARD * aPcb ) // Search and delete others vias at same location TRACK* alt_track = track->Next(); + for( ; alt_track != NULL; alt_track = next_track ) { next_track = alt_track->Next(); + if( alt_track->m_Shape != VIA_THROUGH ) continue; @@ -146,11 +149,13 @@ void clean_vias( BOARD * aPcb ) for( track = aPcb->m_Track; track != NULL; track = next_track ) { next_track = track->Next(); + if( track->m_Shape != VIA_THROUGH ) continue; D_PAD* pad = Fast_Locate_Pad_Connecte( aPcb, track->m_Start, ALL_CU_LAYERS ); - if( pad && (pad->m_Masque_Layer & EXTERNAL_LAYERS) == EXTERNAL_LAYERS ) // redundant Via + + if( pad && (pad->m_layerMask & EXTERNAL_LAYERS) == EXTERNAL_LAYERS ) // redundant Via { /* delete via */ track->UnLink(); @@ -160,15 +165,12 @@ void clean_vias( BOARD * aPcb ) } -/*****************************************************************************/ -static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) -/*****************************************************************************/ - /* * Delete dangling tracks * Vias: * If a via is only connected to a dangling track, it also will be removed */ +static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) { TRACK* segment; TRACK* other; @@ -181,7 +183,7 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) if( frame->GetBoard()->m_Track == NULL ) return; - frame->DrawPanel->m_AbortRequest = FALSE; + frame->DrawPanel->m_AbortRequest = false; // correct via m_End defects for( segment = frame->GetBoard()->m_Track; segment; segment = next ) @@ -192,6 +194,7 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) { if( segment->m_Start != segment->m_End ) segment->m_End = segment->m_Start; + continue; } } @@ -199,6 +202,7 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) // removal of unconnected tracks segment = startNetcode = frame->GetBoard()->m_Track; oldnetcode = segment->GetNet(); + for( int ii = 0; segment ; segment = next, ii++ ) { next = segment->Next(); @@ -222,6 +226,7 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) D_PAD* pad; pad = Fast_Locate_Pad_Connecte( frame->GetBoard(), segment->m_Start, masklayer ); + if( pad != NULL ) { segment->start = pad; @@ -229,6 +234,7 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) } pad = Fast_Locate_Pad_Connecte( frame->GetBoard(), segment->m_End, masklayer ); + if( pad != NULL ) { segment->end = pad; @@ -239,27 +245,30 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) // For via tests, an enhancement could to test if connected to 2 items on different layers. // Currently a via must be connected to 2 items, taht can be on the same layer int top_layer, bottom_layer; + if( (type_end & START_ON_PAD ) == 0 ) { - other = Locate_Piste_Connectee( segment, frame->GetBoard()->m_Track, NULL, START ); + other = GetConnectedTrace( segment, frame->GetBoard()->m_Track, NULL, START ); if( other == NULL ) // Test a connection to zones { if( segment->Type() != TYPE_VIA ) { - zone = frame->GetBoard()->HitTestForAnyFilledArea(segment->m_Start, segment->GetLayer() ); + zone = frame->GetBoard()->HitTestForAnyFilledArea( segment->m_Start, + segment->GetLayer() ); } - else { ((SEGVIA*)segment)->ReturnLayerPair( &top_layer, &bottom_layer ); - zone = frame->GetBoard()->HitTestForAnyFilledArea(segment->m_Start, top_layer, bottom_layer ); + zone = frame->GetBoard()->HitTestForAnyFilledArea( segment->m_Start, + top_layer, bottom_layer ); } } if( (other == NULL) && (zone == NULL) ) + { flag_erase |= 1; - + } else // segment, via or zone connected to this end { segment->start = other; @@ -272,12 +281,14 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) segment->SetState( BUSY, ON ); SEGVIA* via = (SEGVIA*) other; - other = Locate_Piste_Connectee( via, frame->GetBoard()->m_Track, - NULL, START ); + other = GetConnectedTrace( via, frame->GetBoard()->m_Track, NULL, START ); + if( other == NULL ) { via->ReturnLayerPair( &top_layer, &bottom_layer ); - zone = frame->GetBoard()->HitTestForAnyFilledArea(via->m_Start, bottom_layer, top_layer ); + zone = frame->GetBoard()->HitTestForAnyFilledArea( via->m_Start, + bottom_layer, + top_layer ); } if( (other == NULL) && (zone == NULL) ) @@ -291,23 +302,25 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) // if not connected to a pad, test if segment's END is connected to another track if( (type_end & END_ON_PAD ) == 0 ) { - other = Locate_Piste_Connectee( segment, frame->GetBoard()->m_Track, - NULL, END ); + other = GetConnectedTrace( segment, frame->GetBoard()->m_Track, NULL, END ); + if( other == NULL ) // Test a connection to zones { if( segment->Type() != TYPE_VIA ) - zone = frame->GetBoard()->HitTestForAnyFilledArea(segment->m_End, segment->GetLayer() ); - + zone = frame->GetBoard()->HitTestForAnyFilledArea( segment->m_End, + segment->GetLayer() ); else { ((SEGVIA*)segment)->ReturnLayerPair( &top_layer, &bottom_layer ); - zone = frame->GetBoard()->HitTestForAnyFilledArea(segment->m_End,top_layer, bottom_layer ); + zone = frame->GetBoard()->HitTestForAnyFilledArea( segment->m_End, + top_layer, bottom_layer ); } } if ( (other == NULL) && (zone == NULL) ) + { flag_erase |= 0x10; - + } else // segment, via or zone connected to this end { segment->end = other; @@ -321,12 +334,14 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) segment->SetState( BUSY, ON ); SEGVIA* via = (SEGVIA*) other; - other = Locate_Piste_Connectee( via, frame->GetBoard()->m_Track, - NULL, END ); + other = GetConnectedTrace( via, frame->GetBoard()->m_Track, NULL, END ); + if( other == NULL ) { via->ReturnLayerPair( &top_layer, &bottom_layer ); - zone = frame->GetBoard()->HitTestForAnyFilledArea(via->m_End, bottom_layer, top_layer ); + zone = frame->GetBoard()->HitTestForAnyFilledArea( via->m_End, + bottom_layer, + top_layer ); } if( (other == NULL) && (zone == NULL) ) @@ -346,7 +361,9 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) startNetcode = next; } else + { next = startNetcode; + } // remove segment from screen and board segment->Draw( frame->DrawPanel, DC, GR_XOR ); @@ -359,10 +376,8 @@ static void DeleteUnconnectedTracks( PCB_EDIT_FRAME* frame, wxDC* DC ) } -/************************************************************/ -static void clean_segments( PCB_EDIT_FRAME* frame ) -/************************************************************/ /* Delete null lenght segments, and intermediate points .. */ +static void clean_segments( PCB_EDIT_FRAME* frame ) { TRACK* segment, * nextsegment; TRACK* other; @@ -370,12 +385,13 @@ static void clean_segments( PCB_EDIT_FRAME* frame ) int flag, no_inc; wxString msg; - frame->DrawPanel->m_AbortRequest = FALSE; + frame->DrawPanel->m_AbortRequest = false; // Delete null segments for( segment = frame->GetBoard()->m_Track; segment; segment = nextsegment ) { nextsegment = segment->Next(); + if( !segment->IsNull() ) continue; @@ -423,6 +439,7 @@ static void clean_segments( PCB_EDIT_FRAME* frame ) /* delete intermediate points */ ii = 0; + for( segment = frame->GetBoard()->m_Track; segment; segment = nextsegment ) { TRACK* segStart; @@ -430,6 +447,7 @@ static void clean_segments( PCB_EDIT_FRAME* frame ) TRACK* segDelete; nextsegment = segment->Next(); + if( frame->DrawPanel->m_AbortRequest ) return; @@ -441,8 +459,8 @@ static void clean_segments( PCB_EDIT_FRAME* frame ) // search for a possible point that connects on the START point of the segment for( segStart = segment->Next(); ; ) { - segStart = Locate_Piste_Connectee( segment, segStart, - NULL, START ); + segStart = GetConnectedTrace( segment, segStart, NULL, START ); + if( segStart ) { // the two segments must have the same width @@ -455,8 +473,7 @@ static void clean_segments( PCB_EDIT_FRAME* frame ) /* We must have only one segment connected */ segStart->SetState( BUSY, ON ); - other = Locate_Piste_Connectee( segment, frame->GetBoard()->m_Track, - NULL, START ); + other = GetConnectedTrace( segment, frame->GetBoard()->m_Track, NULL, START ); segStart->SetState( BUSY, OFF ); if( other == NULL ) @@ -467,9 +484,10 @@ static void clean_segments( PCB_EDIT_FRAME* frame ) break; } - if( flag ) /* We have the starting point of the segment is connecte to an other segment */ + if( flag ) // We have the starting point of the segment is connecte to an other segment { segDelete = AlignSegment( frame->GetBoard(), segment, segStart, START ); + if( segDelete ) { no_inc = 1; @@ -480,7 +498,8 @@ static void clean_segments( PCB_EDIT_FRAME* frame ) /* search for a possible point that connects on the END point of the segment: */ for( segEnd = segment->Next(); ; ) { - segEnd = Locate_Piste_Connectee( segment, segEnd, NULL, END ); + segEnd = GetConnectedTrace( segment, segEnd, NULL, END ); + if( segEnd ) { if( segment->m_Width != segEnd->m_Width ) @@ -491,8 +510,7 @@ static void clean_segments( PCB_EDIT_FRAME* frame ) /* We must have only one segment connected */ segEnd->SetState( BUSY, ON ); - other = Locate_Piste_Connectee( segment, frame->GetBoard()->m_Track, - NULL, END ); + other = GetConnectedTrace( segment, frame->GetBoard()->m_Track, NULL, END ); segEnd->SetState( BUSY, OFF ); if( other == NULL ) @@ -501,12 +519,15 @@ static void clean_segments( PCB_EDIT_FRAME* frame ) break; } else + { break; + } } - if( flag & 2 ) /* We have the ending point of the segment is connecte to an other segment */ + if( flag & 2 ) // We have the ending point of the segment is connecte to an other segment { segDelete = AlignSegment( frame->GetBoard(), segment, segEnd, END ); + if( segDelete ) { no_inc = 1; @@ -522,9 +543,6 @@ static void clean_segments( PCB_EDIT_FRAME* frame ) } -/****************************************************************************/ -static TRACK* AlignSegment( BOARD* Pcb, TRACK* pt_ref, TRACK* pt_segm, int extremite ) -/****************************************************************************/ /* Function used by clean_segments. * Test alignement of pt_segm and pt_ref (which must have acommon end). * and see if the common point is not on a pad (i.e. if this common point can be removed). @@ -536,6 +554,7 @@ static TRACK* AlignSegment( BOARD* Pcb, TRACK* pt_ref, TRACK* pt_segm, int extre * and return pt_segm (which can be deleted). * else return NULL */ +static TRACK* AlignSegment( BOARD* Pcb, TRACK* pt_ref, TRACK* pt_segm, int extremite ) { int flag = 0; @@ -570,6 +589,7 @@ static TRACK* AlignSegment( BOARD* Pcb, TRACK* pt_ref, TRACK* pt_segm, int extre if( (refdy * segmdx != refdx * segmdy) && (refdy * segmdx != -refdx * segmdy) ) return NULL; + flag = 4; } @@ -602,7 +622,7 @@ static TRACK* AlignSegment( BOARD* Pcb, TRACK* pt_ref, TRACK* pt_segm, int extre { /* We do not have a pad */ if( Fast_Locate_Pad_Connecte( Pcb, pt_ref->m_End, - g_TabOneLayerMask[pt_ref->GetLayer()] ) ) + g_TabOneLayerMask[pt_ref->GetLayer()] ) ) return NULL; /* change the common point coordinate of pt_segm tu use the other point @@ -618,6 +638,7 @@ static TRACK* AlignSegment( BOARD* Pcb, TRACK* pt_ref, TRACK* pt_segm, int extre return pt_segm; } } + return NULL; } @@ -644,6 +665,7 @@ bool PCB_EDIT_FRAME::RemoveMisConnectedTracks( wxDC* aDC ) // find the netcode for segment using anything connected to the "start" of "segment" net_code_s = -1; + if( segment->start && segment->start->Type()==TYPE_PAD ) { // get the netcode of the pad to propagate. @@ -651,8 +673,7 @@ bool PCB_EDIT_FRAME::RemoveMisConnectedTracks( wxDC* aDC ) } else { - other = Locate_Piste_Connectee( segment, GetBoard()->m_Track, - NULL, START ); + other = GetConnectedTrace( segment, GetBoard()->m_Track, NULL, START ); if( other ) net_code_s = other->GetNet(); } @@ -662,14 +683,15 @@ bool PCB_EDIT_FRAME::RemoveMisConnectedTracks( wxDC* aDC ) // find the netcode for segment using anything connected to the "end" of "segment" net_code_e = -1; + if( segment->end && segment->end->Type()==TYPE_PAD ) { net_code_e = ((D_PAD*)(segment->end))->GetNet(); } else { - other = Locate_Piste_Connectee( segment, GetBoard()->m_Track, - NULL, END ); + other = GetConnectedTrace( segment, GetBoard()->m_Track, NULL, END ); + if( other ) net_code_e = other->GetNet(); } @@ -706,9 +728,6 @@ bool PCB_EDIT_FRAME::RemoveMisConnectedTracks( wxDC* aDC ) #if 0 -/***************************************************************/ -static void Gen_Raccord_Track( PCB_EDIT_FRAME* frame, wxDC* DC ) -/***************************************************************/ /** * Function Gen_Raccord_Track @@ -717,26 +736,30 @@ static void Gen_Raccord_Track( PCB_EDIT_FRAME* frame, wxDC* DC ) * segment first being operated on. This is done so that the subsequent tests * of connection, which do not test segment overlaps, will see this continuity. */ +static void Gen_Raccord_Track( PCB_EDIT_FRAME* frame, wxDC* DC ) { TRACK* segment; TRACK* other; int nn = 0; - int masquelayer; + int layerMask; int ii, percent, oldpercent; wxString msg; frame->Affiche_Message( wxT( "Gen Raccords sur Pistes:" ) ); + if( frame->GetBoard()->GetNumSegmTrack() == 0 ) return; - frame->DrawPanel->m_AbortRequest = FALSE; + frame->DrawPanel->m_AbortRequest = false; oldpercent = -1; ii = 0; + for( segment = frame->GetBoard()->m_Track; segment; segment = segment->Next() ) { // display activity ii++; percent = (100 * ii) / frame->GetBoard()->m_Track.GetCount(); + if( percent != oldpercent ) { frame->DisplayActivity( percent, wxT( "Tracks: " ) ); @@ -752,14 +775,15 @@ static void Gen_Raccord_Track( PCB_EDIT_FRAME* frame, wxDC* DC ) if( frame->DrawPanel->m_AbortRequest ) return; - masquelayer = segment->ReturnMaskLayer(); + layerMask = segment->ReturnMaskLayer(); // look at the "start" of the "segment" for( other = frame->GetBoard()->m_Track; other; other = other->Next() ) { TRACK* newTrack; - other = Locate_Pistes( other, segment->m_Start, masquelayer ); + other = GetTrace( other, segment->m_Start, layerMask ); + if( other == NULL ) break; @@ -796,7 +820,7 @@ static void Gen_Raccord_Track( PCB_EDIT_FRAME* frame, wxDC* DC ) other->m_End = segment->m_Start; newTrack->m_Start = segment->m_Start; - Trace_Une_Piste( frame->DrawPanel, DC, other, 2, GR_OR ); + DrawTraces( frame->DrawPanel, DC, other, 2, GR_OR ); // skip forward one, skipping the newTrack other = newTrack; @@ -807,7 +831,8 @@ static void Gen_Raccord_Track( PCB_EDIT_FRAME* frame, wxDC* DC ) { TRACK* newTrack; - other = Locate_Pistes( other, segment->m_End, masquelayer ); + other = GetTrace( other, segment->m_End, layerMask ); + if( other == NULL ) break; @@ -842,7 +867,7 @@ static void Gen_Raccord_Track( PCB_EDIT_FRAME* frame, wxDC* DC ) other->m_End = segment->m_End; newTrack->m_Start = segment->m_End; - Trace_Une_Piste( frame->DrawPanel, DC, other, 2, GR_OR ); + DrawTraces( frame->DrawPanel, DC, other, 2, GR_OR ); // skip forward one, skipping the newTrack other = newTrack; @@ -882,9 +907,10 @@ static void ConnectDanglingEndToVia( BOARD* pcb ) if( !via->IsOnLayer( other->GetLayer() ) ) continue; - // if the other track's m_End does not match the via position, and the track's m_Start is - // within the bounds of the via, and the other track has no start - if( other->m_End!=via->GetPosition() && via->HitTest( other->m_Start ) && !other->start ) + // if the other track's m_End does not match the via position, and the track's + // m_Start is within the bounds of the via, and the other track has no start + if( other->m_End != via->GetPosition() && via->HitTest( other->m_Start ) + && !other->start ) { TRACK* newTrack = other->Copy(); @@ -905,9 +931,10 @@ static void ConnectDanglingEndToVia( BOARD* pcb ) via->end = other; } - // if the other track's m_Start does not match the via position, and the track's m_End is - // within the bounds of the via, and the other track has no end - else if( other->m_Start!=via->GetPosition() && via->HitTest( other->m_End ) && !other->end ) + // if the other track's m_Start does not match the via position, and the track's + // m_End is within the bounds of the via, and the other track has no end + else if( other->m_Start != via->GetPosition() && via->HitTest( other->m_End ) + && !other->end ) { TRACK* newTrack = other->Copy(); @@ -932,22 +959,19 @@ static void ConnectDanglingEndToVia( BOARD* pcb ) } -/***************************************************************/ -void ConnectDanglingEndToPad( PCB_EDIT_FRAME* frame, wxDC* DC ) -/**************************************************************/ - /** * Function ConnectDanglingEndToPad * possibly adds a segment to the end of any and all tracks if their end is not exactly * connected into the center of the pad. This allows faster control of * connections. */ +void ConnectDanglingEndToPad( PCB_EDIT_FRAME* frame, wxDC* DC ) { TRACK* segment; - int nb_new_piste = 0; + int nb_new_trace = 0; wxString msg; - frame->DrawPanel->m_AbortRequest = FALSE; + frame->DrawPanel->m_AbortRequest = false; for( segment = frame->GetBoard()->m_Track; segment; segment = segment->Next() ) { @@ -957,24 +981,23 @@ void ConnectDanglingEndToPad( PCB_EDIT_FRAME* frame, wxDC* DC ) return; pad = Locate_Pad_Connecte( frame->GetBoard(), segment, START ); + if( pad ) { // test if the track is not precisely starting on the found pad if( segment->m_Start != pad->m_Pos ) { - if( Locate_Piste_Connectee( segment, frame->GetBoard()->m_Track, - NULL, START ) == NULL ) + if( GetConnectedTrace( segment, frame->GetBoard()->m_Track, NULL, START ) == NULL ) { TRACK* newTrack = segment->Copy(); frame->GetBoard()->m_Track.Insert( newTrack, segment->Next() ); newTrack->m_End = pad->m_Pos; - newTrack->start = segment; newTrack->end = pad; - nb_new_piste++; + nb_new_trace++; newTrack->Draw( frame->DrawPanel, DC, GR_OR ); } @@ -982,13 +1005,13 @@ void ConnectDanglingEndToPad( PCB_EDIT_FRAME* frame, wxDC* DC ) } pad = Locate_Pad_Connecte( frame->GetBoard(), segment, END ); + if( pad ) { // test if the track is not precisely ending on the found pad if( segment->m_End != pad->m_Pos ) { - if( Locate_Piste_Connectee( segment, frame->GetBoard()->m_Track, - NULL, END ) == NULL ) + if( GetConnectedTrace( segment, frame->GetBoard()->m_Track, NULL, END ) == NULL ) { TRACK* newTrack = segment->Copy(); @@ -998,7 +1021,7 @@ void ConnectDanglingEndToPad( PCB_EDIT_FRAME* frame, wxDC* DC ) newTrack->start = pad; newTrack->end = segment; - nb_new_piste++; + nb_new_trace++; } } } diff --git a/pcbnew/collectors.cpp b/pcbnew/collectors.cpp index 27cfa37a1c..f46b244e7a 100644 --- a/pcbnew/collectors.cpp +++ b/pcbnew/collectors.cpp @@ -36,15 +36,15 @@ const KICAD_T GENERAL_COLLECTOR::AllBoardItems[] = { // there are some restrictions on the order of items in the general case. // all items in m_Drawings for instance should be contiguous. // *** all items in a same list (shown here) must be contiguous **** - TYPE_MARKER_PCB, // in m_markers + TYPE_MARKER_PCB, // in m_markers TYPE_TEXTE, // in m_Drawings TYPE_DRAWSEGMENT, // in m_Drawings - TYPE_DIMENSION, // in m_Drawings - TYPE_MIRE, // in m_Drawings + TYPE_DIMENSION, // in m_Drawings + PCB_TARGET_T, // in m_Drawings TYPE_VIA, // in m_Tracks TYPE_TRACK, // in m_Tracks TYPE_PAD, // in modules - TYPE_TEXTE_MODULE, // in modules + TYPE_TEXTE_MODULE, // in modules TYPE_MODULE, // in m_Modules TYPE_ZONE, // in m_Zones TYPE_ZONE_CONTAINER, // in m_ZoneDescriptorList @@ -70,7 +70,7 @@ const KICAD_T GENERAL_COLLECTOR::AllButZones[] = { TYPE_TEXTE, TYPE_DRAWSEGMENT, TYPE_DIMENSION, - TYPE_MIRE, + PCB_TARGET_T, TYPE_VIA, TYPE_TRACK, TYPE_PAD, @@ -153,6 +153,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testDa case TYPE_PAD: { MODULE* m = (MODULE*) item->GetParent(); + if( m->GetReference() == wxT( "Y2" ) ) { breakhere++; @@ -187,6 +188,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testDa case TYPE_TEXTE_MODULE: { TEXTE_MODULE* tm = (TEXTE_MODULE*) item; + if( tm->m_Text == wxT( "10uH" ) ) { breakhere++; @@ -197,6 +199,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testDa case TYPE_MODULE: { MODULE* m = (MODULE*) item; + if( m->GetReference() == wxT( "C98" ) ) { breakhere++; @@ -217,10 +220,12 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testDa case TYPE_PAD: // there are pad specific visibility controls. // Criterias to select a pad is: - // for smd pads: the module parent must be seen, and pads on the corresponding board side must be seen + // for smd pads: the module parent must be seen, and pads on the corresponding + // board side must be seen // if pad is a thru hole, then it can be visible when its parent module is not. // for through pads: pads on Front or Back board sides must be seen pad = (D_PAD*) item; + if( (pad->m_Attribut != PAD_SMD) && (pad->m_Attribut != PAD_CONN) ) // a hole is present, so multiple layers { @@ -229,7 +234,10 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testDa pad_through = true; } else // smd, so use pads test after module test + { module = (MODULE*) item->GetParent(); + } + break; case TYPE_VIA: @@ -253,7 +261,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testDa case TYPE_DIMENSION: break; - case TYPE_MIRE: + case PCB_TARGET_T: break; case TYPE_TEXTE_MODULE: @@ -298,10 +306,12 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_ITEM* testItem, const void* testDa { if( m_Guide->IgnorePads() ) goto exit; + if( ! pad_through ) { if( m_Guide->IgnorePadsOnFront() && pad->IsOnLayer(LAYER_N_FRONT ) ) goto exit; + if( m_Guide->IgnorePadsOnBack() && pad->IsOnLayer(LAYER_N_BACK ) ) goto exit; } diff --git a/pcbnew/connect.cpp b/pcbnew/connect.cpp index acc681bf07..fe261aaed3 100644 --- a/pcbnew/connect.cpp +++ b/pcbnew/connect.cpp @@ -23,16 +23,12 @@ static void RebuildTrackChain( BOARD* pcb ); /*..*/ -/**************************************************************************************************/ -static int Merge_Two_SubNets( TRACK* pt_start_conn, TRACK* pt_end_conn, int old_val, int new_val ) -/**************************************************************************************************/ - /** * Function Merge_Two_SubNets * Used by Propagate_SubNet() - * Change a subnet value to a new value, for tracks ans pads which are connected to corresponding track - * for pads and tracks, this is the .m_Subnet member that is tested and modified - * these members are block numbers (or cluster numbers) for a given net + * Change a subnet value to a new value, for tracks ans pads which are connected to + * corresponding track for pads and tracks, this is the .m_Subnet member that is tested + * and modified these members are block numbers (or cluster numbers) for a given net * The result is merging 2 blocks (or subnets) * @return modification count * @param old_val = subnet value to modify @@ -41,6 +37,7 @@ static int Merge_Two_SubNets( TRACK* pt_start_conn, TRACK* pt_end_conn, int old_ * @param pt_end_conn = last track segment to test * If pt_end_conn = NULL: search is made from pt_start_conn to end of linked list */ +static int Merge_Two_SubNets( TRACK* pt_start_conn, TRACK* pt_end_conn, int old_val, int new_val ) { TRACK* pt_conn; int nb_change = 0; @@ -53,12 +50,14 @@ static int Merge_Two_SubNets( TRACK* pt_start_conn, TRACK* pt_end_conn, int old_ EXCHG( old_val, new_val ); pt_conn = pt_start_conn; + for( ; pt_conn != NULL; pt_conn = pt_conn->Next() ) { if( pt_conn->GetSubNet() != old_val ) { if( pt_conn == pt_end_conn ) break; + continue; } @@ -68,6 +67,7 @@ static int Merge_Two_SubNets( TRACK* pt_start_conn, TRACK* pt_end_conn, int old_ if( pt_conn->start && ( pt_conn->start->Type() == TYPE_PAD) ) { pt_pad = (D_PAD*) (pt_conn->start); + if( pt_pad->GetSubNet() == old_val ) pt_pad->SetSubNet( pt_conn->GetSubNet() ); } @@ -75,9 +75,11 @@ static int Merge_Two_SubNets( TRACK* pt_start_conn, TRACK* pt_end_conn, int old_ if( pt_conn->end && (pt_conn->end->Type() == TYPE_PAD) ) { pt_pad = (D_PAD*) (pt_conn->end); + if( pt_pad->GetSubNet() == old_val ) pt_pad->SetSubNet( pt_conn->GetSubNet() ); } + if( pt_conn == pt_end_conn ) break; } @@ -86,39 +88,42 @@ static int Merge_Two_SubNets( TRACK* pt_start_conn, TRACK* pt_end_conn, int old_ } -/******************************************************************/ -static void Propagate_SubNet( TRACK* pt_start_conn, TRACK* pt_end_conn ) -/******************************************************************/ /** * Function Propagate_SubNet - * Test a list of track segment, to create or propagate a sub netcode to pads and segments connected together - * the track list must be sorted by nets, and all segments from pt_start_conn to pt_end_conn have the same net - * When 2 items are connected (a track to a pad, or a track to an other track) they are grouped in a cluster. + * Test a list of track segments, to create or propagate a sub netcode to pads and + * segments connected together the track list must be sorted by nets, and all segments + * from pt_start_conn to pt_end_conn have the same net when 2 items are connected (a + * track to a pad, or a track to an other track) they are grouped in a cluster. * for pads, this is the .m_physical_connexion member which is a cluster identifier * for tracks, this is the .m_Subnet member which is a cluster identifier * For a given net, if all tracks are created, there is only one cluster. - * but if not all tracks are created, there are more than one cluster, and some ratsnets will be shown. + * but if not all tracks are created, there are more than one cluster, and some ratsnets + * will be shown. * @param pt_start_conn = first track to test * @param pt_end_conn = last segment to test */ +static void Propagate_SubNet( TRACK* pt_start_conn, TRACK* pt_end_conn ) { TRACK* pt_conn; int sub_netcode; D_PAD* pt_pad; - TRACK* pt_autre_piste; + TRACK* pt_other_trace; BOARD_ITEM* PtStruct; /* Clear variables used in computations */ pt_conn = pt_start_conn; + for( ; pt_conn != NULL; pt_conn = pt_conn->Next() ) { pt_conn->SetSubNet( 0 ); PtStruct = pt_conn->start; + if( PtStruct && (PtStruct->Type() == TYPE_PAD) ) ( (D_PAD*) PtStruct )->SetSubNet( 0 ); PtStruct = pt_conn->end; + if( PtStruct && (PtStruct->Type() == TYPE_PAD) ) ( (D_PAD*) PtStruct )->SetSubNet( 0 ); @@ -131,6 +136,7 @@ static void Propagate_SubNet( TRACK* pt_start_conn, TRACK* pt_end_conn ) /* Start of calculation */ pt_conn = pt_start_conn; + for( ; pt_conn != NULL; pt_conn = pt_conn->Next() ) { /* First: handling connections to pads */ @@ -140,19 +146,20 @@ static void Propagate_SubNet( TRACK* pt_start_conn, TRACK* pt_end_conn ) if( PtStruct && (PtStruct->Type() == TYPE_PAD) ) { pt_pad = (D_PAD*) PtStruct; - if( pt_conn->GetSubNet() ) /* the track segment is already a cluster member */ + + if( pt_conn->GetSubNet() ) /* the track segment is already a cluster member */ { - if( pt_pad->GetSubNet() > 0 ) /* The pad is already a cluster member, so we can merge the 2 clusters */ + if( pt_pad->GetSubNet() > 0 ) /* The pad is already a cluster member, so we can merge the 2 clusters */ { Merge_Two_SubNets( pt_start_conn, pt_end_conn, - pt_pad->GetSubNet(), pt_conn->GetSubNet() ); + pt_pad->GetSubNet(), pt_conn->GetSubNet() ); } else /* The pad is not yet attached to a cluster , so we can add this pad to the cluster */ pt_pad->SetSubNet( pt_conn->GetSubNet() ); } - else /* the track segment is not attached to a cluster */ + else /* the track segment is not attached to a cluster */ { - if( pt_pad->GetSubNet() > 0 ) /* it is connected to a pad in a cluster, merge this track */ + if( pt_pad->GetSubNet() > 0 ) /* it is connected to a pad in a cluster, merge this track */ { pt_conn->SetSubNet( pt_pad->GetSubNet() ); } @@ -166,19 +173,23 @@ static void Propagate_SubNet( TRACK* pt_start_conn, TRACK* pt_end_conn ) } PtStruct = pt_conn->end; + if( PtStruct && (PtStruct->Type() == TYPE_PAD) ) /* The segment end on a pad */ { pt_pad = (D_PAD*) PtStruct; + if( pt_conn->GetSubNet() ) { if( pt_pad->GetSubNet() > 0 ) { Merge_Two_SubNets( pt_start_conn, pt_end_conn, - pt_pad->GetSubNet(), pt_conn->GetSubNet() ); + pt_pad->GetSubNet(), pt_conn->GetSubNet() ); } else + { pt_pad->SetSubNet( pt_conn->GetSubNet() ); + } } else { @@ -198,85 +209,88 @@ static void Propagate_SubNet( TRACK* pt_start_conn, TRACK* pt_end_conn ) /* Test connections between segments */ PtStruct = pt_conn->start; + if( PtStruct && (PtStruct->Type() != TYPE_PAD) ) { /* The segment starts on an other track */ - pt_autre_piste = (TRACK*) PtStruct; + pt_other_trace = (TRACK*) PtStruct; if( pt_conn->GetSubNet() ) /* the track segment is already a cluster member */ { - if( pt_autre_piste->GetSubNet() ) /* The other track is already a cluster member, so we can merge the 2 clusters */ + if( pt_other_trace->GetSubNet() ) /* The other track is already a cluster member, so we can merge the 2 clusters */ { Merge_Two_SubNets( pt_start_conn, pt_end_conn, - pt_autre_piste->GetSubNet(), pt_conn->GetSubNet() ); + pt_other_trace->GetSubNet(), pt_conn->GetSubNet() ); } else /* The other track is not yet attached to a cluster , so we can add this other track to the cluster */ { - pt_autre_piste->SetSubNet( pt_conn->GetSubNet() ); + pt_other_trace->SetSubNet( pt_conn->GetSubNet() ); } } else /* the track segment is not yet attached to a cluster */ { - if( pt_autre_piste->GetSubNet() ) /* The other track is already a cluster member, so we can add the segment to the cluster */ + if( pt_other_trace->GetSubNet() ) /* The other track is already a cluster member, so we can add the segment to the cluster */ { - pt_conn->SetSubNet( pt_autre_piste->GetSubNet() ); + pt_conn->SetSubNet( pt_other_trace->GetSubNet() ); } else /* it is connected to an other segment not in a cluster, so we must create a new cluster (only with the 2 track segments) */ { sub_netcode++; pt_conn->SetSubNet( sub_netcode ); - pt_autre_piste->SetSubNet( pt_conn->GetSubNet() ); + pt_other_trace->SetSubNet( pt_conn->GetSubNet() ); } } } PtStruct = pt_conn->end; // Do the same calculations for the segment end point + if( PtStruct && (PtStruct->Type() != TYPE_PAD) ) { - pt_autre_piste = (TRACK*) PtStruct; + pt_other_trace = (TRACK*) PtStruct; if( pt_conn->GetSubNet() ) /* the track segment is already a cluster member */ { - if( pt_autre_piste->GetSubNet() ) + if( pt_other_trace->GetSubNet() ) { Merge_Two_SubNets( pt_start_conn, pt_end_conn, - pt_autre_piste->GetSubNet(), pt_conn->GetSubNet() ); + pt_other_trace->GetSubNet(), pt_conn->GetSubNet() ); } else - pt_autre_piste->SetSubNet( pt_conn->GetSubNet() ); + { + pt_other_trace->SetSubNet( pt_conn->GetSubNet() ); + } } else /* the track segment is not yet attached to a cluster */ { - if( pt_autre_piste->GetSubNet() ) + if( pt_other_trace->GetSubNet() ) { - pt_conn->SetSubNet( pt_autre_piste->GetSubNet() ); + pt_conn->SetSubNet( pt_other_trace->GetSubNet() ); } else { sub_netcode++; pt_conn->SetSubNet( sub_netcode ); - pt_autre_piste->SetSubNet( pt_conn->GetSubNet() ); + pt_other_trace->SetSubNet( pt_conn->GetSubNet() ); } } } + if( pt_conn == pt_end_conn ) break; } } -/***************************************************/ -void PCB_BASE_FRAME::test_connexions( wxDC* DC ) -/***************************************************/ - /** * Function testing the connections relative to all nets - * This function update the status of the ratsnest ( flag CH_ACTIF = 0 if a connection is found, = 1 else) - * track segments are assumed to be sorted by net codes. - * This is the case because when a new track is added, it is inserted in the linked list according to its net code. - * and when nets are changed (when a new netlist is read) tracks are sorted before using this function + * This function update the status of the ratsnest ( flag CH_ACTIF = 0 if a connection + * is found, = 1 else) track segments are assumed to be sorted by net codes. + * This is the case because when a new track is added, it is inserted in the linked list + * according to its net code. and when nets are changed (when a new netlist is read) + * tracks are sorted before using this function * @param DC = current Device Context */ +void PCB_BASE_FRAME::test_connexions( wxDC* DC ) { // Clear the cluster identifier for all pads for( unsigned i = 0; i< m_Pcb->GetPadsCount(); ++i ) @@ -290,7 +304,7 @@ void PCB_BASE_FRAME::test_connexions( wxDC* DC ) m_Pcb->Test_Connections_To_Copper_Areas(); // Test existing connections net by net - for( TRACK* track = m_Pcb->m_Track; track; ) + for( TRACK* track = m_Pcb->m_Track; track; ) { // this is the current net because pt_start_conn is the first segment of the net int current_net_code = track->GetNet(); @@ -309,16 +323,13 @@ void PCB_BASE_FRAME::test_connexions( wxDC* DC ) } -/*************************************************************************/ -void PCB_BASE_FRAME::test_1_net_connexion( wxDC* DC, int net_code ) -/*************************************************************************/ - /** * Function testing the connections relative to a given net * track segments are assumed to be sorted by net codes * @param DC = current Device Context * @param net_code = net code to test */ +void PCB_BASE_FRAME::test_1_net_connexion( wxDC* DC, int net_code ) { wxString msg; @@ -326,7 +337,7 @@ void PCB_BASE_FRAME::test_1_net_connexion( wxDC* DC, int net_code ) return; if( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 ) - Compile_Ratsnest( DC, TRUE ); + Compile_Ratsnest( DC, true ); for( unsigned i = 0; iGetPadsCount(); ++i ) { @@ -355,11 +366,12 @@ void PCB_BASE_FRAME::test_1_net_connexion( wxDC* DC, int net_code ) if( pt_start_conn ) pt_end_conn = pt_start_conn->GetEndNetCode( net_code ); - if( pt_start_conn && pt_end_conn ) // c.a.d. s'il y a des segments + if( pt_start_conn && pt_end_conn ) // c.a.d. if there are segments { Build_Pads_Info_Connections_By_Tracks( pt_start_conn, pt_end_conn ); } } + Merge_SubNets_Connected_By_CopperAreas( m_Pcb, net_code ); /* Test the rastnest for this net */ @@ -375,10 +387,6 @@ void PCB_BASE_FRAME::test_1_net_connexion( wxDC* DC, int net_code ) } -/*******************************************************************************************/ -static void Build_Pads_Info_Connections_By_Tracks( TRACK* pt_start_conn, TRACK* pt_end_conn ) -/*******************************************************************************************/ - /** Used after a track change (delete a track ou add a track) * Compute connections (initialize the .start and .end members) for a single net. * tracks must be sorted by net, as usual @@ -388,6 +396,7 @@ static void Build_Pads_Info_Connections_By_Tracks( TRACK* pt_start_conn, TRACK* * If a track is deleted, the other pointers to pads do not change. * When a track is added, its pointers to pads are already initialized */ +static void Build_Pads_Info_Connections_By_Tracks( TRACK* pt_start_conn, TRACK* pt_end_conn ) { TRACK* Track; @@ -413,6 +422,7 @@ static void Build_Pads_Info_Connections_By_Tracks( TRACK* pt_start_conn, TRACK* { TRACK* pt_segm; int layermask = Track->ReturnMaskLayer(); + for( pt_segm = pt_start_conn; pt_segm != NULL; pt_segm = pt_segm->Next() ) { int curlayermask = pt_segm->ReturnMaskLayer(); @@ -428,6 +438,7 @@ static void Build_Pads_Info_Connections_By_Tracks( TRACK* pt_start_conn, TRACK* { pt_segm->end = Track; } + if( pt_segm == pt_end_conn ) break; } @@ -435,12 +446,12 @@ static void Build_Pads_Info_Connections_By_Tracks( TRACK* pt_start_conn, TRACK* if( Track->start == NULL ) // end track not already connected, search a connection { - Track->start = Locate_Piste_Connectee( Track, Track, pt_end_conn, START ); + Track->start = GetConnectedTrace( Track, Track, pt_end_conn, START ); } if( Track->end == NULL ) // end track not already connected, search a connection { - Track->end = Locate_Piste_Connectee( Track, Track, pt_end_conn, END ); + Track->end = GetConnectedTrace( Track, Track, pt_end_conn, END ); } if( Track == pt_end_conn ) @@ -460,18 +471,19 @@ static void Build_Pads_Info_Connections_By_Tracks( TRACK* pt_start_conn, TRACK* * A track is seen as connected if the px, py position is same as the pad position. * * @param aPcb = the board. - * @param pt_liste = Pointers to pads buffer - * This buffer is a list like the list created by build_liste_pad, but sorted by increasing X pad coordinate + * @param pt_liste = Pointers to pads buffer. This buffer is a list like the list + * created by build_liste_pad, but sorted by increasing X pad coordinate * @param posref = reference coordinate - * @param masque_layer = Layers (bit to bit) to consider - * @return : pointer on the connected pad - * This function uses a fast search in this sorted pad list and it is faster than Fast_Locate_Pad_connecte(), + * @param aLayerMask = Layers (bit to bit) to consider + * @return : pointer on the connected pad. This function uses a fast search in this sorted + * pad list and it is faster than Fast_Locate_Pad_connecte(), * But this sorted pad list must be built before calling this function. * - * (Note: The usual pad list (created by build_liste_pad) m_Pcb->m_Pads is sorted by increasing netcodes ) + * (Note: The usual pad list (created by build_liste_pad) m_Pcb->m_Pads is sorted by + * increasing netcodes ) */ static D_PAD* SuperFast_Locate_Pad_Connecte( BOARD* aPcb, LISTE_PAD* pt_liste, - const wxPoint& posref, int masque_layer ) + const wxPoint& posref, int aLayerMask ) { D_PAD* pad; int ii; @@ -481,6 +493,7 @@ static D_PAD* SuperFast_Locate_Pad_Connecte( BOARD* aPcb, LISTE_PAD* pt_liste, LISTE_PAD* lim = pt_liste + nb_pad - 1; ptr_pad = pt_liste; + while( nb_pad ) { pad = *ptr_pad; @@ -493,15 +506,20 @@ static D_PAD* SuperFast_Locate_Pad_Connecte( BOARD* aPcb, LISTE_PAD* pt_liste, if( pad->m_Pos.x < posref.x ) /* Must search after this item */ { ptr_pad += nb_pad; + if( ptr_pad > lim ) ptr_pad = lim; + continue; } + if( pad->m_Pos.x > posref.x ) /* Must search before this item */ { ptr_pad -= nb_pad; + if( ptr_pad < pt_liste ) ptr_pad = pt_liste; + continue; } @@ -511,6 +529,7 @@ static D_PAD* SuperFast_Locate_Pad_Connecte( BOARD* aPcb, LISTE_PAD* pt_liste, while( ptr_pad >= pt_liste ) { pad = *ptr_pad; + if( pad->m_Pos.x == posref.x ) ptr_pad--; else @@ -525,6 +544,7 @@ static D_PAD* SuperFast_Locate_Pad_Connecte( BOARD* aPcb, LISTE_PAD* pt_liste, return NULL; /* outside suitable block */ pad = *ptr_pad; + if( pad->m_Pos.x != posref.x ) return NULL; /* outside suitable block */ @@ -532,7 +552,7 @@ static D_PAD* SuperFast_Locate_Pad_Connecte( BOARD* aPcb, LISTE_PAD* pt_liste, continue; /* A Pad if found here: but it must mach the layer */ - if( pad->m_Masque_Layer & masque_layer ) // Matches layer => a connected pad is found ! + if( pad->m_layerMask & aLayerMask ) // Matches layer => a connected pad is found ! return pad; } } @@ -555,48 +575,47 @@ static int SortPadsByXCoord( const void* pt_ref, const void* pt_comp ) } -/*****************************************************************************/ void CreateSortedPadListByXCoord( BOARD* aBoard, std::vector* aVector ) -/*****************************************************************************/ { - aVector->insert( aVector->end(), aBoard->m_NetInfo->m_PadsFullList.begin(), aBoard->m_NetInfo->m_PadsFullList.end() ); + aVector->insert( aVector->end(), aBoard->m_NetInfo->m_PadsFullList.begin(), + aBoard->m_NetInfo->m_PadsFullList.end() ); qsort( &(*aVector)[0], aBoard->GetPadsCount(), sizeof( D_PAD*), SortPadsByXCoord ); } -/********************************************************************/ -void PCB_BASE_FRAME::RecalculateAllTracksNetcode() -/********************************************************************/ - /* search connections between tracks and pads, and propagate pad net codes to the track segments * This is a 2 pass computation. * First: - * We search a connection between a track segment and a pad: if found : this segment netcode is set to the pad netcode + * We search a connection between a track segment and a pad: if found : this segment netcode + * is set to the pad netcode */ +void PCB_BASE_FRAME::RecalculateAllTracksNetcode() { - TRACK* pt_piste; + TRACK* pt_trace; TRACK* pt_next; char new_passe_request = 1; std::vector sortedPads; BOARD_ITEM* PtStruct; - int masque_layer; + int layerMask; wxString msg; // Build the net info list GetBoard()->m_NetInfo->BuildListOfNets(); - if( m_Pcb->GetPadsCount() == 0 ) // If no pad, reset pointers and netcode, and do nothing else + if( m_Pcb->GetPadsCount() == 0 ) // If no pad, reset pointers and netcode, and do nothing else { - pt_piste = m_Pcb->m_Track; - for( ; pt_piste != NULL; pt_piste = pt_piste->Next() ) + pt_trace = m_Pcb->m_Track; + + for( ; pt_trace != NULL; pt_trace = pt_trace->Next() ) { - pt_piste->start = NULL; - pt_piste->SetState( BEGIN_ONPAD | END_ONPAD, OFF ); - pt_piste->SetNet( 0 ); - pt_piste->end = NULL; + pt_trace->start = NULL; + pt_trace->SetState( BEGIN_ONPAD | END_ONPAD, OFF ); + pt_trace->SetNet( 0 ); + pt_trace->end = NULL; } + return; } @@ -606,43 +625,45 @@ void PCB_BASE_FRAME::RecalculateAllTracksNetcode() CreateSortedPadListByXCoord( m_Pcb, &sortedPads ); /* Reset variables and flags used in computation */ - pt_piste = m_Pcb->m_Track; - for( ; pt_piste != NULL; pt_piste = pt_piste->Next() ) + pt_trace = m_Pcb->m_Track; + + for( ; pt_trace != NULL; pt_trace = pt_trace->Next() ) { - pt_piste->SetState( BUSY | IN_EDIT | BEGIN_ONPAD | END_ONPAD, OFF ); - pt_piste->SetZoneSubNet( 0 ); - pt_piste->SetNet( 0 ); // net code = 0 means not connected + pt_trace->SetState( BUSY | IN_EDIT | BEGIN_ONPAD | END_ONPAD, OFF ); + pt_trace->SetZoneSubNet( 0 ); + pt_trace->SetNet( 0 ); // net code = 0 means not connected } /* First pass: search connection between a track segment and a pad. * if found, set the track net code to the pad netcode */ - pt_piste = m_Pcb->m_Track; - for( ; pt_piste != NULL; pt_piste = pt_piste->Next() ) + pt_trace = m_Pcb->m_Track; + + for( ; pt_trace != NULL; pt_trace = pt_trace->Next() ) { - masque_layer = g_TabOneLayerMask[pt_piste->GetLayer()]; + layerMask = g_TabOneLayerMask[pt_trace->GetLayer()]; /* Search for a pad on the segment starting point */ - pt_piste->start = SuperFast_Locate_Pad_Connecte( m_Pcb, + pt_trace->start = SuperFast_Locate_Pad_Connecte( m_Pcb, &sortedPads[0], - pt_piste->m_Start, - masque_layer ); - if( pt_piste->start != NULL ) + pt_trace->m_Start, + layerMask ); + if( pt_trace->start != NULL ) { - pt_piste->SetState( BEGIN_ONPAD, ON ); - pt_piste->SetNet( ( (D_PAD*) (pt_piste->start) )->GetNet() ); + pt_trace->SetState( BEGIN_ONPAD, ON ); + pt_trace->SetNet( ( (D_PAD*) (pt_trace->start) )->GetNet() ); } /* Search for a pad on the segment ending point */ - pt_piste->end = SuperFast_Locate_Pad_Connecte( m_Pcb, + pt_trace->end = SuperFast_Locate_Pad_Connecte( m_Pcb, &sortedPads[0], - pt_piste->m_End, - masque_layer ); + pt_trace->m_End, + layerMask ); - if( pt_piste->end != NULL ) + if( pt_trace->end != NULL ) { - pt_piste->SetState( END_ONPAD, ON ); - pt_piste->SetNet( ( (D_PAD*) (pt_piste->end) )->GetNet() ); + pt_trace->SetState( END_ONPAD, ON ); + pt_trace->SetNet( ( (D_PAD*) (pt_trace->end) )->GetNet() ); } } @@ -657,16 +678,16 @@ void PCB_BASE_FRAME::RecalculateAllTracksNetcode() * when a track has a net code and the other has a null net code, the null net code is changed */ - for( pt_piste = m_Pcb->m_Track; pt_piste != NULL; pt_piste = pt_piste->Next() ) + for( pt_trace = m_Pcb->m_Track; pt_trace != NULL; pt_trace = pt_trace->Next() ) { - if( pt_piste->start == NULL ) + if( pt_trace->start == NULL ) { - pt_piste->start = Locate_Piste_Connectee( pt_piste, m_Pcb->m_Track, NULL, START ); + pt_trace->start = GetConnectedTrace( pt_trace, m_Pcb->m_Track, NULL, START ); } - if( pt_piste->end == NULL ) + if( pt_trace->end == NULL ) { - pt_piste->end = Locate_Piste_Connectee( pt_piste, m_Pcb->m_Track, NULL, END ); + pt_trace->end = GetConnectedTrace( pt_trace, m_Pcb->m_Track, NULL, END ); } } @@ -676,7 +697,7 @@ void PCB_BASE_FRAME::RecalculateAllTracksNetcode() while( new_passe_request ) { - bool reset_flag = FALSE; + bool reset_flag = false; new_passe_request = 0; /* look for vias which could be connect many tracks */ @@ -690,77 +711,83 @@ void PCB_BASE_FRAME::RecalculateAllTracksNetcode() // Lock for a connection to a track with a known netcode pt_next = m_Pcb->m_Track; - while( ( pt_next = Locate_Piste_Connectee( via, pt_next, NULL, START ) ) != NULL ) + + while( ( pt_next = GetConnectedTrace( via, pt_next, NULL, START ) ) != NULL ) { if( pt_next->GetNet() ) { via->SetNet( pt_next->GetNet() ); break; } + pt_next->SetState( BUSY, ON ); - reset_flag = TRUE; + reset_flag = true; } } if( reset_flag ) - for( pt_piste = m_Pcb->m_Track; pt_piste != NULL; pt_piste = pt_piste->Next() ) + for( pt_trace = m_Pcb->m_Track; pt_trace != NULL; pt_trace = pt_trace->Next() ) { - pt_piste->SetState( BUSY, OFF ); + pt_trace->SetState( BUSY, OFF ); } - /* set the netcode of connected tracks: if at track is connected to a pad, its net code is already set. + /* set the netcode of connected tracks: if at track is connected to a pad, its net + * code is already set. * if the current track is connected to an other track: * if a track has a net code, it is used for the other track. * Thus there is a propagation of the netcode from a track to an other. * if none of the 2 track has a net code we do nothing * the iteration is stopped when no new change occurs */ - for( pt_piste = m_Pcb->m_Track; pt_piste != NULL; pt_piste = pt_piste->Next() ) + for( pt_trace = m_Pcb->m_Track; pt_trace != NULL; pt_trace = pt_trace->Next() ) { /* look for the connection to the current segment starting point */ - PtStruct = (BOARD_ITEM*) pt_piste->start; + PtStruct = (BOARD_ITEM*) pt_trace->start; + if( PtStruct && (PtStruct->Type() != TYPE_PAD) ) { // Begin on an other track segment pt_next = (TRACK*) PtStruct; - if( pt_piste->GetNet() ) + + if( pt_trace->GetNet() ) { if( pt_next->GetNet() == 0 ) // the current track has a netcode, we use it for the other track { new_passe_request = 1; // A change is made: a new iteration is requested. - pt_next->SetNet( pt_piste->GetNet() ); + pt_next->SetNet( pt_trace->GetNet() ); } } else { if( pt_next->GetNet() != 0 ) // the other track has a netcode, we use it for the current track { - pt_piste->SetNet( pt_next->GetNet() ); + pt_trace->SetNet( pt_next->GetNet() ); new_passe_request = 1; } } } /* look for the connection to the current segment ending point */ - PtStruct = pt_piste->end; - if( PtStruct &&(PtStruct->Type() != TYPE_PAD) ) + PtStruct = pt_trace->end; + + if( PtStruct && (PtStruct->Type() != TYPE_PAD) ) { pt_next = (TRACK*) PtStruct; // End on an other track: propagate netcode if possible - if( pt_piste->GetNet() ) + if( pt_trace->GetNet() ) { if( pt_next->GetNet() == 0 ) { new_passe_request = 1; - pt_next->SetNet( pt_piste->GetNet() ); + pt_next->SetNet( pt_trace->GetNet() ); } } else { if( pt_next->GetNet() != 0 ) { - pt_piste->SetNet( pt_next->GetNet() ); + pt_trace->SetNet( pt_next->GetNet() ); new_passe_request = 1; } } diff --git a/pcbnew/deltrack.cpp b/pcbnew/deltrack.cpp index ae3dc70700..344db56e5b 100644 --- a/pcbnew/deltrack.cpp +++ b/pcbnew/deltrack.cpp @@ -33,7 +33,7 @@ TRACK* PCB_EDIT_FRAME::Delete_Segment( wxDC* DC, TRACK* aTrack ) D( g_CurrentTrackList.VerifyListIntegrity(); ) // Delete the current trace - ShowNewTrackWhenMovingCursor( DrawPanel, DC, wxDefaultPosition, FALSE ); + ShowNewTrackWhenMovingCursor( DrawPanel, DC, wxDefaultPosition, false ); // delete the most recently entered delete g_CurrentTrackList.PopBack(); @@ -51,13 +51,11 @@ TRACK* PCB_EDIT_FRAME::Delete_Segment( wxDC* DC, TRACK* aTrack ) } } - while( g_CurrentTrackSegment && g_CurrentTrackSegment->Type() == - TYPE_VIA ) + while( g_CurrentTrackSegment && g_CurrentTrackSegment->Type() == TYPE_VIA ) { delete g_CurrentTrackList.PopBack(); - if( g_CurrentTrackSegment && g_CurrentTrackSegment->Type() != - TYPE_VIA ) + if( g_CurrentTrackSegment && g_CurrentTrackSegment->Type() != TYPE_VIA ) previous_layer = g_CurrentTrackSegment->GetLayer(); } @@ -66,8 +64,8 @@ TRACK* PCB_EDIT_FRAME::Delete_Segment( wxDC* DC, TRACK* aTrack ) setActiveLayer( previous_layer ); UpdateStatusBar(); - if( g_TwoSegmentTrackBuild ) // We must have 2 segments or more, - // or 0 + + if( g_TwoSegmentTrackBuild ) // We must have 2 segments or more, or 0 { if( g_CurrentTrackList.GetCount() == 1 && g_CurrentTrackSegment->Type() != TYPE_VIA ) @@ -89,7 +87,7 @@ TRACK* PCB_EDIT_FRAME::Delete_Segment( wxDC* DC, TRACK* aTrack ) else { if( DrawPanel->IsMouseCaptured() ) - DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, FALSE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false ); return g_CurrentTrackSegment; } @@ -178,8 +176,9 @@ void PCB_EDIT_FRAME::Remove_One_Track( wxDC* DC, TRACK* pt_segm ) if( pt_segm == NULL ) return; - TRACK* trackList = Marque_Une_Piste( GetBoard(), pt_segm, - &segments_to_delete_count, NULL, NULL, true ); + TRACK* trackList = MarkTrace( GetBoard(), pt_segm, &segments_to_delete_count, + NULL, NULL, true ); + if( segments_to_delete_count == 0 ) return; @@ -190,6 +189,7 @@ void PCB_EDIT_FRAME::Remove_One_Track( wxDC* DC, TRACK* pt_segm ) int ii = 0; TRACK* tracksegment = trackList; TRACK* next_track; + for( ; ii < segments_to_delete_count; ii++, tracksegment = next_track ) { next_track = tracksegment->Next(); @@ -198,9 +198,9 @@ void PCB_EDIT_FRAME::Remove_One_Track( wxDC* DC, TRACK* pt_segm ) //D( printf( "%s: track %p status=\"%s\"\n", __func__, tracksegment, // TO_UTF8( TRACK::ShowState( tracksegment->GetState( -1 ) ) ) // ); ) - D( std::cout<<__func__<<": track "< g_DragSegmentList; /* Functions */ -void Dessine_Segments_Dragges( EDA_DRAW_PANEL* panel, wxDC* DC ); +void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC ); void Build_Drag_Liste( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module ); void Build_1_Pad_SegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, D_PAD* PtPad ); void Collect_TrackSegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, - wxPoint& point, int MasqueLayer, int net_code ); + wxPoint& point, int LayerMask, int net_code ); /** diff --git a/pcbnew/dragsegm.cpp b/pcbnew/dragsegm.cpp index 37d74bd830..7d9fc00cb0 100644 --- a/pcbnew/dragsegm.cpp +++ b/pcbnew/dragsegm.cpp @@ -26,10 +26,8 @@ DRAG_SEGM::DRAG_SEGM( TRACK* segm ) } -/*******************************************************************/ -void Dessine_Segments_Dragges( EDA_DRAW_PANEL* panel, wxDC* DC ) -/*******************************************************************/ /* Redraw the list of segments starting in g_DragSegmentList, while moving a footprint */ +void DrawSegmentWhileMovingFootprint( EDA_DRAW_PANEL* panel, wxDC* DC ) { D_PAD* pt_pad; TRACK* Track; @@ -45,6 +43,7 @@ void Dessine_Segments_Dragges( EDA_DRAW_PANEL* panel, wxDC* DC ) Track->Draw( panel, DC, GR_XOR ); // erase from screen at old position #endif pt_pad = g_DragSegmentList[ii].m_Pad_Start; + if( pt_pad ) { pos = pt_pad->m_Pos - g_Offset_Module; @@ -52,6 +51,7 @@ void Dessine_Segments_Dragges( EDA_DRAW_PANEL* panel, wxDC* DC ) } pt_pad = g_DragSegmentList[ii].m_Pad_End; + if( pt_pad ) { pos = pt_pad->m_Pos - g_Offset_Module; @@ -63,18 +63,17 @@ void Dessine_Segments_Dragges( EDA_DRAW_PANEL* panel, wxDC* DC ) } -/*************************************************************************/ -void Build_Drag_Liste( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module ) -/*************************************************************************/ /** Build the list of track segments connected to pads of a given module * by populate the std::vector g_DragSegmentList * For each selected track segment set the EDIT flag * and redraw them in EDIT mode (sketch mode) */ +void Build_Drag_Liste( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module ) { D_PAD* pt_pad; pt_pad = Module->m_Pads; + for( ; pt_pad != NULL; pt_pad = (D_PAD*) pt_pad->Next() ) { Build_1_Pad_SegmentsToDrag( panel, DC, pt_pad ); @@ -84,32 +83,31 @@ void Build_Drag_Liste( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module ) } -/**********************************************************************************/ -void Build_1_Pad_SegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, D_PAD* PtPad ) -/**********************************************************************************/ /** Build the list of track segments connected to a given pad * by populate the std::vector g_DragSegmentList * For each selected track segment set the EDIT flag * and redraw them in EDIT mode (sketch mode) * Net codes must be OK. */ +void Build_1_Pad_SegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, D_PAD* PtPad ) { TRACK* Track; int net_code = PtPad->GetNet(); - int MasqueLayer; + int LayerMask; wxPoint pos; BOARD* pcb = ( (PCB_BASE_FRAME*)( panel->GetParent() ) )->GetBoard(); Track = pcb->m_Track->GetStartNetCode( net_code ); pos = PtPad->m_Pos; - MasqueLayer = PtPad->m_Masque_Layer; + LayerMask = PtPad->m_layerMask; + for( ; Track; Track = Track->Next() ) { if( Track->GetNet() != net_code ) break; - if( ( MasqueLayer & Track->ReturnMaskLayer() ) == 0 ) + if( ( LayerMask & Track->ReturnMaskLayer() ) == 0 ) continue; if( pos == Track->m_Start ) @@ -127,12 +125,10 @@ void Build_1_Pad_SegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, D_PAD* PtPad ) } -/******************************************************************/ -void AddSegmentToDragList( EDA_DRAW_PANEL* panel, wxDC* DC, int flag, TRACK* Track ) -/******************************************************************/ /* Add the segment"Track" to the drag list, and erase it from screen * flag = STARTPOINT (if the point to drag is the start point of Track) or ENDPOINT */ +void AddSegmentToDragList( EDA_DRAW_PANEL* panel, wxDC* DC, int flag, TRACK* Track ) { DRAG_SEGM wrapper( Track ); @@ -156,15 +152,12 @@ void AddSegmentToDragList( EDA_DRAW_PANEL* panel, wxDC* DC, int flag, TRACK* Tra } -/**********************************************************************************/ -void Collect_TrackSegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, - wxPoint& aRefPos, int MasqueLayer, int net_code ) -/**********************************************************************************/ - /* Build the list of tracks connected to the ref point * Net codes must be OK. * @param aRefPos = reference point of connection */ +void Collect_TrackSegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, + wxPoint& aRefPos, int LayerMask, int net_code ) { BOARD* pcb = ( (PCB_BASE_FRAME*)( panel->GetParent() ) )->GetBoard(); @@ -175,7 +168,7 @@ void Collect_TrackSegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, if( track->GetNet() != net_code ) // Bad net, not connected break; - if( ( MasqueLayer & track->ReturnMaskLayer() ) == 0 ) + if( ( LayerMask & track->ReturnMaskLayer() ) == 0 ) continue; // Cannot be connected, not on the same layer if( track->m_Flags & IS_DRAGGED ) @@ -194,12 +187,12 @@ void Collect_TrackSegmentsToDrag( EDA_DRAW_PANEL* panel, wxDC* DC, if( flag ) { AddSegmentToDragList( panel, DC, flag, track ); + // If a connected via is found at location aRefPos, // collect also tracks connected by this via. if( track->Type() == TYPE_VIA ) - Collect_TrackSegmentsToDrag( panel, DC, aRefPos, - track->ReturnMaskLayer(), - net_code ); + Collect_TrackSegmentsToDrag( panel, DC, aRefPos, track->ReturnMaskLayer(), + net_code ); } } } diff --git a/pcbnew/drc.cpp b/pcbnew/drc.cpp index bb257c0fbb..4923c48668 100644 --- a/pcbnew/drc.cpp +++ b/pcbnew/drc.cpp @@ -228,6 +228,7 @@ void DRC::RunTests( wxTextCtrl* aMessages ) aMessages->AppendText( _( "Fill zones...\n" ) ); wxSafeYield(); } + m_mainWindow->Fill_All_Zones( false ); // test zone clearances to other zones, pads, tracks, and vias @@ -263,9 +264,7 @@ void DRC::RunTests( wxTextCtrl* aMessages ) } -/***************************************************************/ void DRC::ListUnconnectedPads() -/***************************************************************/ { testUnconnected(); @@ -408,9 +407,7 @@ bool DRC::testNetClasses() } -/***********************/ void DRC::testPad2Pad() -/***********************/ { std::vector sortedPads; @@ -466,7 +463,7 @@ void DRC::testUnconnected() if( (m_pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 ) { wxClientDC dc( m_mainWindow->DrawPanel ); - m_mainWindow->Compile_Ratsnest( &dc, TRUE ); + m_mainWindow->Compile_Ratsnest( &dc, true ); } if( m_pcb->GetRatsnestsCount() == 0 ) @@ -475,6 +472,7 @@ void DRC::testUnconnected() for( unsigned ii = 0; ii < m_pcb->GetRatsnestsCount(); ++ii ) { RATSNEST_ITEM* rat = &m_pcb->m_FullRatsnest[ii]; + if( (rat->m_Status & CH_ACTIF) == 0 ) continue; @@ -491,9 +489,7 @@ void DRC::testUnconnected() } -/**********************************************/ void DRC::testZones( bool adoTestFillSegments ) -/**********************************************/ { // Test copper areas for valide netcodes // if a netcode is < 0 the netname was not found when reading a netlist @@ -502,8 +498,10 @@ void DRC::testZones( bool adoTestFillSegments ) for( int ii = 0; ii < m_pcb->GetAreaCount(); ii++ ) { ZONE_CONTAINER* Area_To_Test = m_pcb->GetArea( ii ); + if( !Area_To_Test->IsOnCopperLayer() ) continue; + if( Area_To_Test->GetNet() < 0 ) { m_currentMarker = fillMarker( Area_To_Test, @@ -536,6 +534,7 @@ void DRC::testZones( bool adoTestFillSegments ) // Pads already tested: disable pad test bool rc = doTrackDrc( zoneSeg, m_pcb->m_Track, false ); + if( !rc ) { wxASSERT( m_currentMarker ); @@ -546,12 +545,9 @@ void DRC::testZones( bool adoTestFillSegments ) } -/*****************************************************************************/ -bool DRC::doPadToPadsDrc( D_PAD* aRefPad, LISTE_PAD* aStart, LISTE_PAD* aEnd, - int x_limit ) -/*****************************************************************************/ +bool DRC::doPadToPadsDrc( D_PAD* aRefPad, LISTE_PAD* aStart, LISTE_PAD* aEnd, int x_limit ) { - int layerMask = aRefPad->m_Masque_Layer & ALL_CU_LAYERS; + int layerMask = aRefPad->m_layerMask & ALL_CU_LAYERS; /* used to test DRC pad to holes: this dummy pad has the size and shape of the hole * to test pad to pad hole DRC, using the pad to pad DRC test function. @@ -561,7 +557,7 @@ bool DRC::doPadToPadsDrc( D_PAD* aRefPad, LISTE_PAD* aStart, LISTE_PAD* aEnd, */ MODULE dummymodule( m_pcb ); // Creates a dummy parent D_PAD dummypad( &dummymodule ); - dummypad.m_Masque_Layer |= ALL_CU_LAYERS; // Ensure the hole is on all copper layers + dummypad.m_layerMask |= ALL_CU_LAYERS; // Ensure the hole is on all copper layers dummypad.m_LocalClearance = 1; /* Use the minimal local clerance value for the dummy pad * the clearance of the active pad will be used * as minimum distance to a hole @@ -571,6 +567,7 @@ bool DRC::doPadToPadsDrc( D_PAD* aRefPad, LISTE_PAD* aStart, LISTE_PAD* aEnd, for( LISTE_PAD* pad_list = aStart; pad_listm_Masque_Layer & layerMask ) == 0 ) + if( (pad->m_layerMask & layerMask ) == 0 ) { // if holes are in the same location and have the same size and shape, // this can be accepted @@ -592,6 +589,7 @@ bool DRC::doPadToPadsDrc( D_PAD* aRefPad, LISTE_PAD* aStart, LISTE_PAD* aEnd, { if( aRefPad->m_DrillShape == PAD_CIRCLE ) continue; + if( pad->m_Orient == aRefPad->m_Orient ) // for oval holes: must also have the same orientation continue; } @@ -606,6 +604,7 @@ bool DRC::doPadToPadsDrc( D_PAD* aRefPad, LISTE_PAD* aStart, LISTE_PAD* aEnd, dummypad.m_PadShape = (pad->m_DrillShape == PAD_OVAL) ? PAD_OVAL : PAD_CIRCLE; dummypad.m_Orient = pad->m_Orient; dummypad.ComputeShapeMaxRadius(); // compute the radius of the circle containing this pad + if( !checkClearancePadToPad( aRefPad, &dummypad ) ) { // here we have a drc error on pad! @@ -630,6 +629,7 @@ bool DRC::doPadToPadsDrc( D_PAD* aRefPad, LISTE_PAD* aStart, LISTE_PAD* aEnd, return false; } } + continue; } @@ -654,8 +654,7 @@ bool DRC::doPadToPadsDrc( D_PAD* aRefPad, LISTE_PAD* aStart, LISTE_PAD* aEnd, if( !checkClearancePadToPad( aRefPad, pad ) ) { // here we have a drc error! - m_currentMarker = fillMarker( aRefPad, pad, - DRCE_PAD_NEAR_PAD1, m_currentMarker ); + m_currentMarker = fillMarker( aRefPad, pad, DRCE_PAD_NEAR_PAD1, m_currentMarker ); return false; } } diff --git a/pcbnew/drc_clearance_test_functions.cpp b/pcbnew/drc_clearance_test_functions.cpp index 28b527f3d7..aabb6cad7a 100644 --- a/pcbnew/drc_clearance_test_functions.cpp +++ b/pcbnew/drc_clearance_test_functions.cpp @@ -52,10 +52,12 @@ bool trapezoid2trapezoidDRC( wxPoint aTref[4], wxPoint aTcompare[4], int aDist ) */ if( TestPointInsidePolygon( aTref, 4, aTcompare[0] ) ) return false; + if( TestPointInsidePolygon( aTcompare, 4, aTref[0] ) ) return false; int ii, jj, kk, ll; + for( ii = 0, jj = 3; ii<4; jj = ii, ii++ ) // for all edges in aTref { for( kk = 0, ll = 3; kk < 4; ll = kk, kk++ ) // for all edges in aTcompare @@ -91,6 +93,7 @@ bool trapezoid2segmentDRC( wxPoint aTref[4], wxPoint aSegStart, wxPoint aSegEnd, return false; int ii, jj; + for( ii = 0, jj = 3; ii < 4; jj = ii, ii++ ) // for all edges in aTref { double d; @@ -128,6 +131,7 @@ bool trapezoid2pointDRC( wxPoint aTref[4], wxPoint aPcompare, int aDist ) // Test distance between aPcompare and polygon edges: int ii, jj; double dist = (double) aDist; + for( ii = 0, jj = 3; ii < 4; jj = ii, ii++ ) // for all edges in polygon { if( TestLineHit( aTref[ii].x, aTref[ii].y, @@ -140,9 +144,7 @@ bool trapezoid2pointDRC( wxPoint aTref[4], wxPoint aPcompare, int aDist ) return true; } -/***********************************************************************/ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) -/***********************************************************************/ { TRACK* track; wxPoint delta; // lenght on X and Y axis of segments @@ -205,15 +207,18 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) bool err = true; ( (SEGVIA*) aRefSeg )->ReturnLayerPair( &layer1, &layer2 ); - if( layer1> layer2 ) + + if( layer1 > layer2 ) EXCHG( layer1, layer2 ); // test: if( layer1 == LAYER_N_BACK && layer2 == LAYER_N_2 ) err = false; + if( layer1 == (m_pcb->GetBoardDesignSettings()->GetCopperLayerCount() - 2 ) && layer2 == LAYER_N_FRONT ) err = false; + if( err ) { m_currentMarker = fillMarker( aRefSeg, NULL, @@ -260,7 +265,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) */ MODULE dummymodule( m_pcb ); // Creates a dummy parent D_PAD dummypad( &dummymodule ); - dummypad.m_Masque_Layer = ALL_CU_LAYERS; // Ensure the hole is on all layers + dummypad.m_layerMask = ALL_CU_LAYERS; // Ensure the hole is on all layers // Compute the min distance to pads if( testPads ) @@ -273,10 +278,11 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) * But if a drill hole exists (a pad on a single layer can have a hole!) * we must test the hole */ - if( (pad->m_Masque_Layer & layerMask ) == 0 ) + if( (pad->m_layerMask & layerMask ) == 0 ) { - /* We must test the pad hole. In order to use the function checkClearanceSegmToPad(), - * a pseudo pad is used, with a shape and a size like the hole + /* We must test the pad hole. In order to use the function + * checkClearanceSegmToPad(),a pseudo pad is used, with a shape and a + * size like the hole */ if( pad->m_Drill.x == 0 ) continue; @@ -289,12 +295,13 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) m_padToTestPos = dummypad.GetPosition() - origin; if( !checkClearanceSegmToPad( &dummypad, aRefSeg->m_Width, - netclass->GetClearance() ) ) + netclass->GetClearance() ) ) { m_currentMarker = fillMarker( aRefSeg, pad, DRCE_TRACK_NEAR_THROUGH_HOLE, m_currentMarker ); return false; } + continue; } @@ -378,6 +385,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) return false; } } + continue; } @@ -396,8 +404,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) if( checkMarginToCircle( segStartPoint, w_dist, m_segmLength ) ) continue; - m_currentMarker = fillMarker( aRefSeg, track, - DRCE_TRACK_NEAR_VIA, m_currentMarker ); + m_currentMarker = fillMarker( aRefSeg, track, DRCE_TRACK_NEAR_VIA, m_currentMarker ); return false; } @@ -423,6 +430,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) DRCE_TRACK_ENDS1, m_currentMarker ); return false; } + if( !checkMarginToCircle( segStartPoint, w_dist, m_segmLength ) ) { m_currentMarker = fillMarker( aRefSeg, track, @@ -430,6 +438,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) return false; } } + if( segEndPoint.x > (-w_dist) && segEndPoint.x < (m_segmLength + w_dist) ) { /* Fine test : we consider the rounded shape of the ends */ @@ -439,6 +448,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) DRCE_TRACK_ENDS3, m_currentMarker ); return false; } + if( !checkMarginToCircle( segEndPoint, w_dist, m_segmLength ) ) { m_currentMarker = fillMarker( aRefSeg, track, @@ -462,6 +472,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) // Test if segments are crossing if( segStartPoint.y > segEndPoint.y ) EXCHG( segStartPoint.y, segEndPoint.y ); + if( (segStartPoint.y < 0) && (segEndPoint.y > 0) ) { m_currentMarker = fillMarker( aRefSeg, track, @@ -531,12 +542,14 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) RotatePoint( &relStartPos, angle ); RotatePoint( &relEndPos, angle ); + if( !checkMarginToCircle( relStartPos, w_dist, delta.x ) ) { m_currentMarker = fillMarker( aRefSeg, track, DRCE_ENDS_PROBLEM4, m_currentMarker ); return false; } + if( !checkMarginToCircle( relEndPos, w_dist, delta.x ) ) { m_currentMarker = fillMarker( aRefSeg, track, @@ -583,6 +596,7 @@ bool DRC::checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad ) */ bool swap_pads; swap_pads = false; + if( (aRefPad->m_PadShape != PAD_CIRCLE) && (aPad->m_PadShape == PAD_CIRCLE) ) swap_pads = true; else if( (aRefPad->m_PadShape != PAD_OVAL) && (aPad->m_PadShape == PAD_OVAL) ) @@ -602,6 +616,7 @@ bool DRC::checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad ) * aPad is also a PAD_RECT or a PAD_TRAPEZOID */ bool diag = true; + switch( aRefPad->m_PadShape ) { case PAD_CIRCLE: @@ -623,6 +638,7 @@ bool DRC::checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad ) // pad_angle = pad orient relative to the aRefPad orient pad_angle = aRefPad->m_Orient + aPad->m_Orient; NORMALIZE_ANGLE_POS( pad_angle ); + if( aPad->m_PadShape == PAD_RECT ) { wxSize size = aPad->m_Size; @@ -657,9 +673,11 @@ bool DRC::checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad ) wxPoint polycompare[4]; // Shape of aPad aRefPad->BuildPadPolygon( polyref, wxSize( 0, 0 ), aRefPad->m_Orient ); aPad->BuildPadPolygon( polycompare, wxSize( 0, 0 ), aPad->m_Orient ); + // Move aPad shape to relativePadPos for( int ii = 0; ii < 4; ii++ ) polycompare[ii] += relativePadPos; + // And now test polygons: if( !trapezoid2trapezoidDRC( polyref, polycompare, dist_min ) ) diag = false; @@ -694,6 +712,7 @@ bool DRC::checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad ) */ int segm_width; m_segmAngle = aRefPad->m_Orient; // Segment orient. + if( aRefPad->m_Size.y < aRefPad->m_Size.x ) // Build an horizontal equiv segment { segm_width = aRefPad->m_Size.y; @@ -776,6 +795,7 @@ bool DRC::checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMi seuil = segmHalfWidth + aMinDist; padHalfsize.x = aPad->m_Size.x >> 1; padHalfsize.y = aPad->m_Size.y >> 1; + if( aPad->m_PadShape == PAD_TRAPEZOID ) // The size is bigger, due to m_DeltaSize extra size { padHalfsize.x += ABS(aPad->m_DeltaSize.y) / 2; // Remember: m_DeltaSize.y is the m_Size.x change @@ -830,9 +850,11 @@ bool DRC::checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMi { EXCHG( padHalfsize.x, padHalfsize.y ); orient += 900; + if( orient >= 3600 ) orient -= 3600; } + deltay = padHalfsize.y - padHalfsize.x; // here: padHalfsize.x = radius, delta = dist centre cercles a centre pad @@ -842,6 +864,7 @@ bool DRC::checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMi m_ycliplo = m_padToTestPos.y - segmHalfWidth - deltay; m_xcliphi = m_padToTestPos.x + seuil + padHalfsize.x; m_ycliphi = m_padToTestPos.y + segmHalfWidth + deltay; + if( !checkLine( startPoint, endPoint ) ) { return false; @@ -856,6 +879,7 @@ bool DRC::checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMi // Calculate the actual position of the circle in the new X,Y axis: RotatePoint( &startPoint, m_segmAngle ); + if( !checkMarginToCircle( startPoint, padHalfsize.x + seuil, m_segmLength ) ) { return false; @@ -871,6 +895,7 @@ bool DRC::checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMi { return false; } + break; case PAD_RECT: /* 2 rectangle + 4 1/4 cercles a tester */ @@ -898,6 +923,7 @@ bool DRC::checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMi startPoint.y = m_padToTestPos.y - padHalfsize.y; RotatePoint( &startPoint, m_padToTestPos, orient ); RotatePoint( &startPoint, m_segmAngle ); + if( !checkMarginToCircle( startPoint, seuil, m_segmLength ) ) return false; @@ -906,6 +932,7 @@ bool DRC::checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMi startPoint.y = m_padToTestPos.y - padHalfsize.y; RotatePoint( &startPoint, m_padToTestPos, orient ); RotatePoint( &startPoint, m_segmAngle ); + if( !checkMarginToCircle( startPoint, seuil, m_segmLength ) ) return false; @@ -914,6 +941,7 @@ bool DRC::checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMi startPoint.y = m_padToTestPos.y + padHalfsize.y; RotatePoint( &startPoint, m_padToTestPos, orient ); RotatePoint( &startPoint, m_segmAngle ); + if( !checkMarginToCircle( startPoint, seuil, m_segmLength ) ) return false; @@ -922,6 +950,7 @@ bool DRC::checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMi startPoint.y = m_padToTestPos.y + padHalfsize.y; RotatePoint( &startPoint, m_padToTestPos, orient ); RotatePoint( &startPoint, m_segmAngle ); + if( !checkMarginToCircle( startPoint, seuil, m_segmLength ) ) return false; @@ -1006,50 +1035,55 @@ bool DRC::checkLine( wxPoint aSegStart, wxPoint aSegEnd ) { WHEN_OUTSIDE; } + if( aSegStart.y < aSegEnd.y ) { if( (aSegEnd.y < m_ycliplo) || (aSegStart.y > m_ycliphi) ) { WHEN_OUTSIDE; } + if( aSegStart.y < m_ycliplo ) { - temp = - USCALE( (aSegEnd.x - aSegStart.x), (m_ycliplo - aSegStart.y), - (aSegEnd.y - aSegStart.y) ); + temp = USCALE( (aSegEnd.x - aSegStart.x), (m_ycliplo - aSegStart.y), + (aSegEnd.y - aSegStart.y) ); + if( (aSegStart.x += temp) > m_xcliphi ) { WHEN_OUTSIDE; } + aSegStart.y = m_ycliplo; WHEN_INSIDE; } + if( aSegEnd.y > m_ycliphi ) { - temp = - USCALE( (aSegEnd.x - aSegStart.x), (aSegEnd.y - m_ycliphi), - (aSegEnd.y - aSegStart.y) ); + temp = USCALE( (aSegEnd.x - aSegStart.x), (aSegEnd.y - m_ycliphi), + (aSegEnd.y - aSegStart.y) ); + if( (aSegEnd.x -= temp) < m_xcliplo ) { WHEN_OUTSIDE; } + aSegEnd.y = m_ycliphi; WHEN_INSIDE; } + if( aSegStart.x < m_xcliplo ) { - temp = - USCALE( (aSegEnd.y - aSegStart.y), (m_xcliplo - aSegStart.x), - (aSegEnd.x - aSegStart.x) ); + temp = USCALE( (aSegEnd.y - aSegStart.y), (m_xcliplo - aSegStart.x), + (aSegEnd.x - aSegStart.x) ); aSegStart.y += temp; aSegStart.x = m_xcliplo; WHEN_INSIDE; } + if( aSegEnd.x > m_xcliphi ) { - temp = - USCALE( (aSegEnd.y - aSegStart.y), (aSegEnd.x - m_xcliphi), - (aSegEnd.x - aSegStart.x) ); + temp = USCALE( (aSegEnd.y - aSegStart.y), (aSegEnd.x - m_xcliphi), + (aSegEnd.x - aSegStart.x) ); aSegEnd.y -= temp; aSegEnd.x = m_xcliphi; WHEN_INSIDE; @@ -1061,44 +1095,48 @@ bool DRC::checkLine( wxPoint aSegStart, wxPoint aSegEnd ) { WHEN_OUTSIDE; } + if( aSegStart.y > m_ycliphi ) { - temp = - USCALE( (aSegEnd.x - aSegStart.x), (aSegStart.y - m_ycliphi), - (aSegStart.y - aSegEnd.y) ); + temp = USCALE( (aSegEnd.x - aSegStart.x), (aSegStart.y - m_ycliphi), + (aSegStart.y - aSegEnd.y) ); + if( (aSegStart.x += temp) > m_xcliphi ) { WHEN_OUTSIDE; } + aSegStart.y = m_ycliphi; WHEN_INSIDE; } + if( aSegEnd.y < m_ycliplo ) { - temp = - USCALE( (aSegEnd.x - aSegStart.x), (m_ycliplo - aSegEnd.y), - (aSegStart.y - aSegEnd.y) ); + temp = USCALE( (aSegEnd.x - aSegStart.x), (m_ycliplo - aSegEnd.y), + (aSegStart.y - aSegEnd.y) ); + if( (aSegEnd.x -= temp) < m_xcliplo ) { WHEN_OUTSIDE; } + aSegEnd.y = m_ycliplo; WHEN_INSIDE; } + if( aSegStart.x < m_xcliplo ) { - temp = - USCALE( (aSegStart.y - aSegEnd.y), (m_xcliplo - aSegStart.x), - (aSegEnd.x - aSegStart.x) ); + temp = USCALE( (aSegStart.y - aSegEnd.y), (m_xcliplo - aSegStart.x), + (aSegEnd.x - aSegStart.x) ); aSegStart.y -= temp; aSegStart.x = m_xcliplo; WHEN_INSIDE; } + if( aSegEnd.x > m_xcliphi ) { - temp = - USCALE( (aSegStart.y - aSegEnd.y), (aSegEnd.x - m_xcliphi), - (aSegEnd.x - aSegStart.x) ); + temp = USCALE( (aSegStart.y - aSegEnd.y), (aSegEnd.x - m_xcliphi), + (aSegEnd.x - aSegStart.x) ); aSegEnd.y += temp; aSegEnd.x = m_xcliphi; WHEN_INSIDE; @@ -1113,5 +1151,7 @@ bool DRC::checkLine( wxPoint aSegStart, wxPoint aSegEnd ) return false; } else + { return true; + } } diff --git a/pcbnew/edgemod.cpp b/pcbnew/edgemod.cpp index ab81379c9a..c6e8fc87e5 100644 --- a/pcbnew/edgemod.cpp +++ b/pcbnew/edgemod.cpp @@ -40,7 +40,7 @@ void FOOTPRINT_EDIT_FRAME::Start_Move_EdgeMod( EDGE_MODULE* Edge, wxDC* DC ) CursorInitialPosition = GetScreen()->GetCrossHairPosition(); DrawPanel->SetMouseCapture( ShowCurrentOutlineWhileMoving, Abort_Move_ModuleOutline ); SetCurItem( Edge ); - DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, FALSE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false ); } @@ -48,6 +48,7 @@ void FOOTPRINT_EDIT_FRAME::Place_EdgeMod( EDGE_MODULE* Edge ) { if( Edge == NULL ) return; + Edge->m_Start -= MoveVector; Edge->m_End -= MoveVector; @@ -59,7 +60,7 @@ void FOOTPRINT_EDIT_FRAME::Place_EdgeMod( EDGE_MODULE* Edge ) SetCurItem( NULL ); OnModify(); MODULE* Module = (MODULE*) Edge->GetParent(); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); DrawPanel->Refresh( ); } @@ -87,7 +88,7 @@ static void ShowCurrentOutlineWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, Edge->Draw( aPanel, aDC, GR_XOR, MoveVector ); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); } @@ -105,7 +106,7 @@ static void ShowNewEdgeModule( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& MODULE* Module = (MODULE*) Edge->GetParent(); - // if( erase ) + // if( erase ) { Edge->Draw( aPanel, aDC, GR_XOR ); } @@ -118,7 +119,7 @@ static void ShowNewEdgeModule( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& Edge->Draw( aPanel, aDC, GR_XOR ); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); } @@ -131,18 +132,22 @@ void FOOTPRINT_EDIT_FRAME::Edit_Edge_Width( EDGE_MODULE* aEdge ) if( aEdge == NULL ) { aEdge = (EDGE_MODULE*) (BOARD_ITEM*) Module->m_Drawings; + for( ; aEdge != NULL; aEdge = aEdge->Next() ) { if( aEdge->Type() != TYPE_EDGE_MODULE ) continue; + aEdge->m_Width = g_ModuleSegmentWidth; } } else + { aEdge->m_Width = g_ModuleSegmentWidth; + } OnModify(); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); Module->m_LastEdit_Time = time( NULL ); } @@ -155,9 +160,9 @@ void FOOTPRINT_EDIT_FRAME::Edit_Edge_Layer( EDGE_MODULE* Edge ) if( Edge != NULL ) new_layer = Edge->GetLayer(); - /* Ask for the new layer */ new_layer = SelectLayer( new_layer, FIRST_COPPER_LAYER, LAST_NO_COPPER_LAYER ); + if( new_layer < 0 ) return; @@ -190,7 +195,7 @@ void FOOTPRINT_EDIT_FRAME::Edit_Edge_Layer( EDGE_MODULE* Edge ) } OnModify(); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); Module->m_LastEdit_Time = time( NULL ); } @@ -214,7 +219,7 @@ void FOOTPRINT_EDIT_FRAME::Enter_Edge_Width( EDGE_MODULE* aEdge ) { MODULE* Module = GetBoard()->m_Modules; aEdge->m_Width = g_ModuleSegmentWidth; - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); OnModify(); } } @@ -236,7 +241,7 @@ void FOOTPRINT_EDIT_FRAME::Delete_Edge_Module( EDGE_MODULE* Edge ) /* Delete segment. */ Edge->DeleteStructure(); Module->m_LastEdit_Time = time( NULL ); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); OnModify(); } @@ -256,7 +261,7 @@ static void Abort_Move_ModuleOutline( EDA_DRAW_PANEL* Panel, wxDC* DC ) MODULE* Module = (MODULE*) Edge->GetParent(); Edge->Draw( Panel, DC, GR_XOR, MoveVector ); Edge->DeleteStructure(); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); } else // On aborting, move existing outline to its initial position. { @@ -319,7 +324,7 @@ EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* Edge, RotatePoint( &Edge->m_Start0, -module->m_Orient ); Edge->m_End0 = Edge->m_Start0; - module->Set_Rectangle_Encadrement(); + module->CalculateBoundingBox(); DrawPanel->SetMouseCapture( ShowNewEdgeModule, Abort_Move_ModuleOutline ); } /* Segment creation in progress. @@ -356,7 +361,7 @@ EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* Edge, Edge->m_End0 = Edge->m_Start0; - module->Set_Rectangle_Encadrement(); + module->CalculateBoundingBox(); module->m_LastEdit_Time = time( NULL ); OnModify(); } @@ -384,7 +389,7 @@ void FOOTPRINT_EDIT_FRAME::End_Edge_Module( EDGE_MODULE* Edge ) Edge->DeleteStructure(); } - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); Module->m_LastEdit_Time = time( NULL ); OnModify(); DrawPanel->SetMouseCapture( NULL, NULL ); diff --git a/pcbnew/edit.cpp b/pcbnew/edit.cpp index 54637cc52b..d4080c55e8 100644 --- a/pcbnew/edit.cpp +++ b/pcbnew/edit.cpp @@ -881,18 +881,18 @@ void PCB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) break; case ID_POPUP_PCB_MOVE_MIRE_REQUEST: - StartMove_Mire( (MIREPCB*) GetCurItem(), &dc ); + BeginMoveTarget( (PCB_TARGET*) GetCurItem(), &dc ); DrawPanel->MoveCursorToCrossHair(); break; case ID_POPUP_PCB_EDIT_MIRE: - InstallMireOptionsFrame( (MIREPCB*) GetCurItem(), &dc ); + ShowTargetOptionsDialog( (PCB_TARGET*) GetCurItem(), &dc ); DrawPanel->MoveCursorToCrossHair(); break; case ID_POPUP_PCB_DELETE_MIRE: DrawPanel->MoveCursorToCrossHair(); - Delete_Mire( (MIREPCB*) GetCurItem(), &dc ); + DeleteTarget( (PCB_TARGET*) GetCurItem(), &dc ); SetCurItem( NULL ); break; @@ -1096,8 +1096,8 @@ void PCB_EDIT_FRAME::RemoveStruct( BOARD_ITEM* Item, wxDC* DC ) Delete_Dimension( (DIMENSION*) Item, DC ); break; - case TYPE_MIRE: - Delete_Mire( (MIREPCB*) Item, DC ); + case PCB_TARGET_T: + DeleteTarget( (PCB_TARGET*) Item, DC ); break; case TYPE_DRAWSEGMENT: diff --git a/pcbnew/edit_pcb_text.cpp b/pcbnew/edit_pcb_text.cpp index c944637272..281705ec45 100644 --- a/pcbnew/edit_pcb_text.cpp +++ b/pcbnew/edit_pcb_text.cpp @@ -111,7 +111,7 @@ void PCB_EDIT_FRAME::StartMoveTextePcb( TEXTE_PCB* TextePcb, wxDC* DC ) DrawPanel->SetMouseCapture( Move_Texte_Pcb, Abort_Edit_Pcb_Text ); SetCurItem( TextePcb ); - DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, FALSE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false ); } @@ -160,6 +160,7 @@ TEXTE_PCB* PCB_EDIT_FRAME::Create_Texte_Pcb( wxDC* DC ) TextePcb->m_Flags = IS_NEW; TextePcb->SetLayer( ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer ); TextePcb->m_Mirror = false; + if( TextePcb->GetLayer() == LAYER_N_BACK ) TextePcb->m_Mirror = true; @@ -168,13 +169,16 @@ TEXTE_PCB* PCB_EDIT_FRAME::Create_Texte_Pcb( wxDC* DC ) TextePcb->m_Thickness = GetBoard()->GetBoardDesignSettings()->m_PcbTextWidth; InstallTextPCBOptionsFrame( TextePcb, DC ); + if( TextePcb->m_Text.IsEmpty() ) { TextePcb->DeleteStructure(); TextePcb = NULL; } else + { StartMoveTextePcb( TextePcb, DC ); + } return TextePcb; } @@ -197,6 +201,7 @@ void PCB_EDIT_FRAME::Rotate_Texte_Pcb( TEXTE_PCB* TextePcb, wxDC* DC ) /* Redraw text in new position. */ TextePcb->Draw( DrawPanel, DC, drawmode ); TextePcb->DisplayInfo( this ); + if( TextePcb->m_Flags == 0 ) // i.e. not edited, or moved SaveCopyInUndoList( TextePcb, UR_ROTATED, TextePcb->m_Pos ); else // set flag edit, to show it was a complex command diff --git a/pcbnew/edit_track_width.cpp b/pcbnew/edit_track_width.cpp index 1d1f648b7d..225bf4ba15 100644 --- a/pcbnew/edit_track_width.cpp +++ b/pcbnew/edit_track_width.cpp @@ -41,17 +41,22 @@ bool PCB_EDIT_FRAME::SetTrackSegmentWidth( TRACK* aTrackItem, new_width = net->GetTrackWidth(); else new_width = GetBoard()->GetCurrentTrackWidth(); + if( aTrackItem->Type() == TYPE_VIA ) { if( !aTrackItem->IsDrillDefault() ) initial_drill = aTrackItem->GetDrillValue(); + if( net ) + { new_width = net->GetViaSize(); + } else { new_width = GetBoard()->GetCurrentViaSize(); new_drill = GetBoard()->GetCurrentViaDrill(); } + if( aTrackItem->m_Shape == VIA_MICROVIA ) { if( net ) @@ -59,29 +64,36 @@ bool PCB_EDIT_FRAME::SetTrackSegmentWidth( TRACK* aTrackItem, else new_width = net->GetMicroViaSize(); } - } aTrackItem->m_Width = new_width; + if( initial_width < new_width ) /* make a DRC test because the new size is bigger than the old size */ { int diagdrc = OK_DRC; + if( Drc_On ) diagdrc = m_drc->Drc( aTrackItem, GetBoard()->m_Track ); + if( diagdrc == OK_DRC ) change_ok = true; } else if( initial_width > new_width ) + { change_ok = true; + } // if new width == initial_width: do nothing, // unless a via has its drill value changed else if( (aTrackItem->Type() == TYPE_VIA) && (initial_drill != new_drill) ) + { change_ok = true; + } if( change_ok ) { OnModify(); + if( aItemsListPicker ) { aTrackItem->m_Width = initial_width; @@ -89,18 +101,21 @@ bool PCB_EDIT_FRAME::SetTrackSegmentWidth( TRACK* aTrackItem, picker.m_Link = aTrackItem->Copy(); aItemsListPicker->PushItem( picker ); aTrackItem->m_Width = new_width; + if( aTrackItem->Type() == TYPE_VIA ) { // Set new drill value. Note: currently microvias have only a default drill value if( new_drill > 0 ) aTrackItem->SetDrillValue(new_drill); else - aTrackItem->SetDrillDefault( ); + aTrackItem->SetDrillDefault(); } } } else + { aTrackItem->m_Width = initial_width; + } return change_ok; } @@ -125,11 +140,12 @@ void PCB_EDIT_FRAME::Edit_TrackSegm_Width( wxDC* aDC, TRACK* aTrackItem ) { TRACK* oldsegm = (TRACK*) itemsListPicker.GetPickedItemLink( 0 ); wxASSERT( oldsegm ); - DrawPanel->CrossHairOff( aDC ); // Erase cursor shape + DrawPanel->CrossHairOff( aDC ); // Erase cursor shape oldsegm->Draw( DrawPanel, aDC, GR_XOR ); // Erase old track shape aTrackItem->Draw( DrawPanel, aDC, GR_OR ); // Display new track shape - DrawPanel->CrossHairOn( aDC ); // Display cursor shape + DrawPanel->CrossHairOn( aDC ); // Display cursor shape } + SaveCopyInUndoList( itemsListPicker, UR_CHANGED ); } @@ -137,7 +153,8 @@ void PCB_EDIT_FRAME::Edit_TrackSegm_Width( wxDC* aDC, TRACK* aTrackItem ) /** * Function Edit_Track_Width * Modify a full track width (using DRC control). - * a full track is the set of track segments between 2 ends: pads or a point that has more than 2 segments ends connected + * a full track is the set of track segments between 2 ends: pads or a point that has + * more than 2 segments ends connected * @param aDC = the curred device context (can be NULL) * @param aTrackSegment = a segment or via on the track to change */ @@ -149,13 +166,15 @@ void PCB_EDIT_FRAME::Edit_Track_Width( wxDC* aDC, TRACK* aTrackSegment ) if( aTrackSegment == NULL ) return; - pt_track = Marque_Une_Piste( GetBoard(), aTrackSegment, &nb_segm, NULL, NULL, true ); + pt_track = MarkTrace( GetBoard(), aTrackSegment, &nb_segm, NULL, NULL, true ); PICKED_ITEMS_LIST itemsListPicker; bool change = false; + for( int ii = 0; ii < nb_segm; ii++, pt_track = pt_track->Next() ) { pt_track->SetState( BUSY, OFF ); + if( SetTrackSegmentWidth( pt_track, &itemsListPicker, false ) ) change = true; } @@ -190,9 +209,7 @@ void PCB_EDIT_FRAME::Edit_Track_Width( wxDC* aDC, TRACK* aTrackSegment ) * @param aNetcode : the netcode of the net to edit * @param aUseNetclassValue : bool. True to use netclass values, false to use current values */ -/***********************************************************/ bool PCB_EDIT_FRAME::Change_Net_Tracks_And_Vias_Sizes( int aNetcode, bool aUseNetclassValue ) -/***********************************************************/ { TRACK* pt_segm; @@ -202,10 +219,12 @@ bool PCB_EDIT_FRAME::Change_Net_Tracks_And_Vias_Sizes( int aNetcode, bool aUseNe /* Examine segments */ PICKED_ITEMS_LIST itemsListPicker; bool change = false; + for( pt_segm = GetBoard()->m_Track; pt_segm != NULL; pt_segm = pt_segm->Next() ) { if( aNetcode != pt_segm->GetNet() ) /* not in net */ continue; + /* we have found a item member of the net */ if( SetTrackSegmentWidth( pt_segm, &itemsListPicker, aUseNetclassValue ) ) change = true; @@ -220,15 +239,14 @@ bool PCB_EDIT_FRAME::Change_Net_Tracks_And_Vias_Sizes( int aNetcode, bool aUseNe } -/*************************************************************************/ bool PCB_EDIT_FRAME::Reset_All_Tracks_And_Vias_To_Netclass_Values( bool aTrack, bool aVia ) -/*************************************************************************/ { TRACK* pt_segm; /* read and edit tracks and vias if required */ PICKED_ITEMS_LIST itemsListPicker; bool change = false; + for( pt_segm = GetBoard()->m_Track; pt_segm != NULL; pt_segm = pt_segm->Next() ) { if( (pt_segm->Type() == TYPE_VIA ) && aVia ) diff --git a/pcbnew/editedge.cpp b/pcbnew/editedge.cpp index 0cf6382ac4..8478c3fb08 100644 --- a/pcbnew/editedge.cpp +++ b/pcbnew/editedge.cpp @@ -14,8 +14,7 @@ static void Abort_EditEdge( EDA_DRAW_PANEL* Panel, wxDC* DC ); -static void Montre_Position_NewSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, - const wxPoint& aPosition, bool aErase ); +static void DrawSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ); static void Move_Segment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ); @@ -29,6 +28,7 @@ void PCB_EDIT_FRAME::Start_Move_DrawItem( DRAWSEGMENT* drawitem, wxDC* DC ) { if( drawitem == NULL ) return; + drawitem->Draw( DrawPanel, DC, GR_XOR ); drawitem->m_Flags |= IS_MOVED; s_InitialPosition = s_LastPosition = GetScreen()->GetCrossHairPosition(); @@ -94,8 +94,10 @@ void PCB_EDIT_FRAME::Delete_Segment_Edge( DRAWSEGMENT* Segment, wxDC* DC ) Segment->Draw( DrawPanel, DC, GR_XOR ); PtStruct = Segment->Back(); Segment ->DeleteStructure(); + if( PtStruct && (PtStruct->Type() == TYPE_DRAWSEGMENT ) ) Segment = (DRAWSEGMENT*) PtStruct; + DisplayOpt.DisplayDrawItems = track_fill_copy; SetCurItem( NULL ); } @@ -120,6 +122,7 @@ void PCB_EDIT_FRAME::Delete_Drawings_All_Layer( int aLayer ) } wxString msg = _( "Delete Layer " ) + GetBoard()->GetLayerName( aLayer ); + if( !IsOK( this, msg ) ) return; @@ -136,13 +139,14 @@ void PCB_EDIT_FRAME::Delete_Drawings_All_Layer( int aLayer ) case TYPE_DRAWSEGMENT: case TYPE_TEXTE: case TYPE_DIMENSION: - case TYPE_MIRE: + case PCB_TARGET_T: if( item->GetLayer() == aLayer ) { item->UnLink(); picker.m_PickedItem = item; pickList.PushItem( picker ); } + break; default: @@ -218,10 +222,10 @@ DRAWSEGMENT* PCB_EDIT_FRAME::Begin_DrawSegment( DRAWSEGMENT* Segment, int shape, Segment->m_Shape = shape; Segment->m_Angle = 900; Segment->m_Start = Segment->m_End = GetScreen()->GetCrossHairPosition(); - DrawPanel->SetMouseCapture( Montre_Position_NewSegment, Abort_EditEdge ); + DrawPanel->SetMouseCapture( DrawSegment, Abort_EditEdge ); } else /* The ending point ccordinate Segment->m_End was updated by he function - * Montre_Position_NewSegment() called on a move mouse event + * DrawSegment() called on a move mouse event * during the segment creation */ { @@ -248,7 +252,7 @@ DRAWSEGMENT* PCB_EDIT_FRAME::Begin_DrawSegment( DRAWSEGMENT* Segment, int shape, Segment->m_Type = DrawItem->m_Type; Segment->m_Angle = DrawItem->m_Angle; Segment->m_Start = Segment->m_End = DrawItem->m_End; - Montre_Position_NewSegment( DrawPanel, DC, wxDefaultPosition, false ); + DrawSegment( DrawPanel, DC, wxDefaultPosition, false ); } else { @@ -266,12 +270,14 @@ void PCB_EDIT_FRAME::End_Edge( DRAWSEGMENT* Segment, wxDC* DC ) { if( Segment == NULL ) return; + Segment->Draw( DrawPanel, DC, GR_OR ); /* Delete if segment length is zero. */ if( Segment->m_Start == Segment->m_End ) + { Segment ->DeleteStructure(); - + } else { Segment->m_Flags = 0; @@ -287,8 +293,7 @@ void PCB_EDIT_FRAME::End_Edge( DRAWSEGMENT* Segment, wxDC* DC ) /* Redraw segment during cursor movement */ -static void Montre_Position_NewSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, - const wxPoint& aPosition, bool aErase ) +static void DrawSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { DRAWSEGMENT* Segment = (DRAWSEGMENT*) aPanel->GetScreen()->GetCurItem(); int t_fill = DisplayOpt.DisplayDrawItems; @@ -303,9 +308,9 @@ static void Montre_Position_NewSegment( EDA_DRAW_PANEL* aPanel, wxDC* aDC, if( Segments_45_Only && ( Segment->m_Shape == S_SEGMENT ) ) { - Calcule_Coord_Extremite_45( aPanel->GetScreen()->GetCrossHairPosition(), - Segment->m_Start.x, Segment->m_Start.y, - &Segment->m_End.x, &Segment->m_End.y ); + CalculateSegmentEndPoint( aPanel->GetScreen()->GetCrossHairPosition(), + Segment->m_Start.x, Segment->m_Start.y, + &Segment->m_End.x, &Segment->m_End.y ); } else /* here the angle is arbitrary */ { diff --git a/pcbnew/editmod.cpp b/pcbnew/editmod.cpp index 386a3a81d3..5142b9a276 100644 --- a/pcbnew/editmod.cpp +++ b/pcbnew/editmod.cpp @@ -1,6 +1,6 @@ /************************************************/ -/* Module editor: Dialog box for editing module */ -/* properties and characteristics */ +/* Module editor: Dialog box for editing module */ +/* properties and characteristics */ /************************************************/ #include "fctsys.h" @@ -23,8 +23,7 @@ void PCB_EDIT_FRAME::InstallModuleOptionsFrame( MODULE* Module, wxDC* DC ) if( Module == NULL ) return; - DIALOG_MODULE_BOARD_EDITOR* dialog = - new DIALOG_MODULE_BOARD_EDITOR( this, Module, DC ); + DIALOG_MODULE_BOARD_EDITOR* dialog = new DIALOG_MODULE_BOARD_EDITOR( this, Module, DC ); int retvalue = dialog->ShowModal(); /* retvalue = * -1 if abort, @@ -47,8 +46,8 @@ void PCB_EDIT_FRAME::InstallModuleOptionsFrame( MODULE* Module, wxDC* DC ) m_ModuleEditFrame->Load_Module_From_BOARD( Module ); SetCurItem( NULL ); - m_ModuleEditFrame->Show( TRUE ); - m_ModuleEditFrame->Iconize( FALSE ); + m_ModuleEditFrame->Show( true ); + m_ModuleEditFrame->Iconize( false ); } } @@ -107,7 +106,7 @@ void FOOTPRINT_EDIT_FRAME::Place_Ancre( MODULE* pt_mod ) } } - pt_mod->Set_Rectangle_Encadrement(); + pt_mod->CalculateBoundingBox(); } @@ -125,16 +124,19 @@ void FOOTPRINT_EDIT_FRAME::RemoveStruct( EDA_ITEM* Item ) case TYPE_TEXTE_MODULE: { TEXTE_MODULE* text = (TEXTE_MODULE*) Item; + if( text->m_Type == TEXT_is_REFERENCE ) { DisplayError( this, _( "Text is REFERENCE!" ) ); break; } + if( text->m_Type == TEXT_is_VALUE ) { DisplayError( this, _( "Text is VALUE!" ) ); break; } + DeleteTextModule( text ); } break; diff --git a/pcbnew/editrack-part2.cpp b/pcbnew/editrack-part2.cpp index f3c815a208..77cf7eb03d 100644 --- a/pcbnew/editrack-part2.cpp +++ b/pcbnew/editrack-part2.cpp @@ -1,6 +1,6 @@ -/*******************************/ +/************************/ /* Edit tracks */ -/*******************************/ +/************************/ #include "fctsys.h" #include "class_drawpanel.h" @@ -33,12 +33,14 @@ void PCB_EDIT_FRAME::ExChange_Track_Layer( TRACK* pt_segm, wxDC* DC ) l1 = Route_Layer_TOP; l2 = Route_Layer_BOTTOM; - pt_track = Marque_Une_Piste( GetBoard(), pt_segm, &nb_segm, NULL, NULL, true ); + pt_track = MarkTrace( GetBoard(), pt_segm, &nb_segm, NULL, NULL, true ); + if ( DC ) - Trace_Une_Piste( DrawPanel, DC, pt_track, nb_segm, GR_XOR ); + DrawTraces( DrawPanel, DC, pt_track, nb_segm, GR_XOR ); /* Clear the BUSY flag and backup member. Param layer original. */ ii = nb_segm; pt_segm = pt_track; + for( ; ii > 0; ii--, pt_segm = (TRACK*) pt_segm->Next() ) { pt_segm->SetState( BUSY, OFF ); @@ -46,6 +48,7 @@ void PCB_EDIT_FRAME::ExChange_Track_Layer( TRACK* pt_segm, wxDC* DC ) } ii = 0; pt_segm = pt_track; + for( ; ii < nb_segm; ii++, pt_segm = (TRACK*) pt_segm->Next() ) { if( pt_segm->Type() == TYPE_VIA ) @@ -69,15 +72,19 @@ void PCB_EDIT_FRAME::ExChange_Track_Layer( TRACK* pt_segm, wxDC* DC ) } if( DC ) - Trace_Une_Piste( DrawPanel, DC, pt_track, nb_segm, GR_OR ); - DisplayError( this, _( "Drc error, canceled" ), 10 ); + DrawTraces( DrawPanel, DC, pt_track, nb_segm, GR_OR ); + + DisplayError( this, _( "Drc error, canceled" ) ); return; } } - Trace_Une_Piste( DrawPanel, DC, pt_track, nb_segm, GR_OR | GR_SURBRILL ); + DrawTraces( DrawPanel, DC, pt_track, nb_segm, GR_OR | GR_SURBRILL ); + /* Control of segment end point, is it on a pad? */ - ii = 0; pt_segm = pt_track; + ii = 0; + pt_segm = pt_track; + for( ; ii < nb_segm; pt_segm = pt_segm->Next(), ii++ ) { pt_segm->start = Locate_Pad_Connecte( GetBoard(), pt_segm, START ); @@ -96,8 +103,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) if( aTrack == NULL ) { - if( getActiveLayer() != - ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ) + if( getActiveLayer() != ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ) setActiveLayer( ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP ); else setActiveLayer(((PCB_SCREEN*)GetScreen())->m_Route_Layer_BOTTOM ); @@ -107,14 +113,12 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) } /* Avoid more than one via on the current location: */ - if( Locate_Via( GetBoard(), g_CurrentTrackSegment->m_End, - g_CurrentTrackSegment->GetLayer() ) ) + if( Locate_Via( GetBoard(), g_CurrentTrackSegment->m_End, g_CurrentTrackSegment->GetLayer() ) ) return false; for( TRACK* segm = g_FirstTrackSegment; segm; segm = segm->Next() ) { - if( segm->Type()==TYPE_VIA - && g_CurrentTrackSegment->m_End==segm->m_Start ) + if( segm->Type() == TYPE_VIA && g_CurrentTrackSegment->m_End == segm->m_Start ) return false; } @@ -128,8 +132,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) // Handle 2 segments. if( g_TwoSegmentTrackBuild && g_CurrentTrackSegment->Back() ) { - if( BAD_DRC == m_drc->Drc( g_CurrentTrackSegment->Back(), - GetBoard()->m_Track ) ) + if( BAD_DRC == m_drc->Drc( g_CurrentTrackSegment->Back(), GetBoard()->m_Track ) ) return false; } } @@ -140,7 +143,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) itmp = g_CurrentTrackList.GetCount(); Begin_Route( g_CurrentTrackSegment, DC ); - DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, FALSE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false ); /* create the via */ SEGVIA* via = new SEGVIA( GetBoard() ); @@ -149,6 +152,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) via->m_Width = GetBoard()->GetCurrentViaSize(); via->SetNet( GetBoard()->GetHightLightNetCode() ); via->m_Start = via->m_End = g_CurrentTrackSegment->m_End; + // Usual via is from copper to component. // layer pair is LAYER_N_BACK and LAYER_N_FRONT. via->SetLayerPair( LAYER_N_BACK, LAYER_N_FRONT ); @@ -156,6 +160,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) int first_layer = getActiveLayer(); int last_layer; + // prepare switch to new active layer: if( first_layer != GetScreen()->m_Route_Layer_TOP ) last_layer = GetScreen()->m_Route_Layer_TOP; @@ -180,6 +185,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) last_layer = LAYER_N_BACK; else if ( first_layer == last_inner_layer ) last_layer = LAYER_N_FRONT; + // else error: will be removed later via->SetLayerPair( first_layer, last_layer ); { @@ -198,7 +204,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) /* DRC fault: the Via cannot be placed here ... */ delete via; - DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, FALSE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false ); // delete the track(s) added in Begin_Route() while( g_CurrentTrackList.GetCount() > itmp ) @@ -252,7 +258,7 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) g_CurrentTrackList.PushBack( g_CurrentTrackSegment->Copy() ); } - DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, FALSE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false ); via->DisplayInfo( this ); UpdateStatusBar(); @@ -265,13 +271,13 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC ) * The status of the net on top of the screen segment advanced by mouse. * PCB status or bottom of screen if no segment peak. */ -void PCB_EDIT_FRAME::Affiche_Status_Net( wxDC* DC ) +void PCB_EDIT_FRAME::DisplayNetStatus( wxDC* DC ) { TRACK* pt_segm; - int masquelayer = (1 << getActiveLayer()); + int layerMask = (1 << getActiveLayer()); wxPoint pos = GetScreen()->RefPos( true ); - pt_segm = Locate_Pistes( GetBoard(), GetBoard()->m_Track, pos, masquelayer ); + pt_segm = GetTrace( GetBoard(), GetBoard()->m_Track, pos, layerMask ); if( pt_segm == NULL ) GetBoard()->DisplayInfo( this ); @@ -294,7 +300,7 @@ void PCB_EDIT_FRAME::Show_1_Ratsnest( EDA_ITEM* item, wxDC* DC ) return; if( ( GetBoard()->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK ) == 0 ) - Compile_Ratsnest( DC, TRUE ); + Compile_Ratsnest( DC, true ); if( item ) { @@ -307,14 +313,18 @@ void PCB_EDIT_FRAME::Show_1_Ratsnest( EDA_ITEM* item, wxDC* DC ) if( pt_pad ) /* Displaying the ratsnest of the corresponding net. */ { pt_pad->DisplayInfo( this ); + for( unsigned ii = 0; ii < GetBoard()->GetRatsnestsCount(); ii++ ) { RATSNEST_ITEM* net = &GetBoard()->m_FullRatsnest[ii]; + if( net->GetNet() == pt_pad->GetNet() ) { if( ( net->m_Status & CH_VISIBLE ) != 0 ) continue; + net->m_Status |= CH_VISIBLE; + if( ( net->m_Status & CH_ACTIF ) == 0 ) continue; @@ -326,8 +336,7 @@ void PCB_EDIT_FRAME::Show_1_Ratsnest( EDA_ITEM* item, wxDC* DC ) { if( item->Type() == TYPE_TEXTE_MODULE ) { - if( item->GetParent() - && ( item->GetParent()->Type() == TYPE_MODULE ) ) + if( item->GetParent() && ( item->GetParent()->Type() == TYPE_MODULE ) ) Module = (MODULE*) item->GetParent(); } else if( item->Type() == TYPE_MODULE ) @@ -339,19 +348,20 @@ void PCB_EDIT_FRAME::Show_1_Ratsnest( EDA_ITEM* item, wxDC* DC ) { Module->DisplayInfo( this ); pt_pad = Module->m_Pads; + for( ; pt_pad != NULL; pt_pad = (D_PAD*) pt_pad->Next() ) { - for( unsigned ii = 0; ii < GetBoard()->GetRatsnestsCount(); - ii++ ) + for( unsigned ii = 0; ii < GetBoard()->GetRatsnestsCount(); ii++ ) { RATSNEST_ITEM* net = &GetBoard()->m_FullRatsnest[ii]; - if( ( net->m_PadStart == pt_pad ) - || ( net->m_PadEnd == pt_pad ) ) + + if( ( net->m_PadStart == pt_pad ) || ( net->m_PadEnd == pt_pad ) ) { if( net->m_Status & CH_VISIBLE ) continue; net->m_Status |= CH_VISIBLE; + if( (net->m_Status & CH_ACTIF) == 0 ) continue; @@ -378,11 +388,12 @@ void PCB_EDIT_FRAME::Show_1_Ratsnest( EDA_ITEM* item, wxDC* DC ) /* High light the unconnected pads */ -void PCB_EDIT_FRAME::Affiche_PadsNoConnect( wxDC* DC ) +void PCB_EDIT_FRAME::HighlightUnconnectedPads( wxDC* DC ) { for( unsigned ii = 0; ii < GetBoard()->GetRatsnestsCount(); ii++ ) { RATSNEST_ITEM* net = &GetBoard()->m_FullRatsnest[ii]; + if( (net->m_Status & CH_ACTIF) == 0 ) continue; diff --git a/pcbnew/editrack.cpp b/pcbnew/editrack.cpp index 293b0d1162..fbcf43afea 100644 --- a/pcbnew/editrack.cpp +++ b/pcbnew/editrack.cpp @@ -26,8 +26,7 @@ static void EnsureEndTrackOnPad( D_PAD* Pad ); static PICKED_ITEMS_LIST s_ItemsListPicker; -/* Routine to cancel the route if a track is being drawn, or exit the - * application EDITRACK. +/* Routine to cancel the route if a track is being drawn, or exit the application EDITRACK. */ static void Abort_Create_Track( EDA_DRAW_PANEL* Panel, wxDC* DC ) { @@ -39,10 +38,12 @@ static void Abort_Create_Track( EDA_DRAW_PANEL* Panel, wxDC* DC ) { /* Erase the current drawing */ ShowNewTrackWhenMovingCursor( Panel, DC, wxDefaultPosition, false ); + if( pcb->IsHightLightNetON() ) frame->High_Light( DC ); pcb->PopHightLight(); + if( pcb->IsHightLightNetON() ) pcb->DrawHighLight( Panel, DC, pcb->GetHightLightNetCode() ); @@ -80,8 +81,7 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) { D_PAD* pt_pad = NULL; TRACK* TrackOnStartPoint = NULL; - int masquelayer = - g_TabOneLayerMask[( (PCB_SCREEN*) GetScreen() )->m_Active_Layer]; + int layerMask = g_TabOneLayerMask[( (PCB_SCREEN*) GetScreen() )->m_Active_Layer]; BOARD_ITEM* LockPoint; wxPoint pos = GetScreen()->GetCrossHairPosition(); @@ -90,9 +90,7 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) DrawPanel->SetMouseCapture( ShowNewTrackWhenMovingCursor, Abort_Create_Track ); // Prepare the undo command info - s_ItemsListPicker.ClearListAndDeleteItems(); // Should not be - // necessary, - // but... + s_ItemsListPicker.ClearListAndDeleteItems(); // Should not be necessary, but... GetBoard()->PushHightLight(); @@ -106,7 +104,7 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) GetBoard()->SetHightLightNet(0); // Search for a starting point of the new track, a track or pad - LockPoint = LocateLockPoint( GetBoard(), pos, masquelayer ); + LockPoint = LocateLockPoint( GetBoard(), pos, layerMask ); if( LockPoint ) // An item (pad or track) is found { @@ -122,9 +120,7 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) { TrackOnStartPoint = (TRACK*) LockPoint; GetBoard()->SetHightLightNet( TrackOnStartPoint->GetNet() ); - CreateLockPoint( GetBoard(), pos, - TrackOnStartPoint, - &s_ItemsListPicker ); + CreateLockPoint( GetBoard(), pos, TrackOnStartPoint, &s_ItemsListPicker ); } } else // no starting point, but a filled zone area can exist. This is @@ -158,6 +154,7 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) if( TrackOnStartPoint && TrackOnStartPoint->Type() == TYPE_TRACK ) g_CurrentTrackSegment->m_Width = TrackOnStartPoint->m_Width; } + g_CurrentTrackSegment->m_Start = pos; g_CurrentTrackSegment->m_End = pos; @@ -167,7 +164,9 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) g_CurrentTrackSegment->SetState( BEGIN_ONPAD, ON ); } else + { g_CurrentTrackSegment->start = TrackOnStartPoint; + } if( g_TwoSegmentTrackBuild ) { @@ -190,8 +189,7 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) if( Drc_On ) { - if( BAD_DRC == - m_drc->Drc( g_CurrentTrackSegment, GetBoard()->m_Track ) ) + if( BAD_DRC == m_drc->Drc( g_CurrentTrackSegment, GetBoard()->m_Track ) ) { return g_CurrentTrackSegment; } @@ -202,16 +200,13 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) /* Tst for a D.R.C. error: */ if( Drc_On ) { - if( BAD_DRC == - m_drc->Drc( g_CurrentTrackSegment, GetBoard()->m_Track ) ) + if( BAD_DRC == m_drc->Drc( g_CurrentTrackSegment, GetBoard()->m_Track ) ) return NULL; // We must handle 2 segments if( g_TwoSegmentTrackBuild && g_CurrentTrackSegment->Back() ) { - if( BAD_DRC == - m_drc->Drc( g_CurrentTrackSegment->Back(), - GetBoard()->m_Track ) ) + if( BAD_DRC == m_drc->Drc( g_CurrentTrackSegment->Back(), GetBoard()->m_Track ) ) return NULL; } } @@ -221,6 +216,7 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) * if a 2 segments track build. */ bool CanCreateNewSegment = true; + if( !g_TwoSegmentTrackBuild && g_CurrentTrackSegment->IsNull() ) CanCreateNewSegment = false; @@ -251,13 +247,14 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) newTrack->SetState( BEGIN_ONPAD | END_ONPAD, OFF ); - oneBeforeLatest->end = Locate_Pad_Connecte( - GetBoard(), oneBeforeLatest, END ); + oneBeforeLatest->end = Locate_Pad_Connecte( GetBoard(), oneBeforeLatest, END ); + if( oneBeforeLatest->end ) { oneBeforeLatest->SetState( END_ONPAD, ON ); newTrack->SetState( BEGIN_ONPAD, ON ); } + newTrack->start = oneBeforeLatest->end; D( g_CurrentTrackList.VerifyListIntegrity(); ); @@ -265,6 +262,7 @@ TRACK* PCB_EDIT_FRAME::Begin_Route( TRACK* aTrack, wxDC* DC ) newTrack->m_Start = newTrack->m_End; newTrack->SetLayer( ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer ); + if( !GetBoard()->GetBoardDesignSettings()->m_UseConnectedTrackWidth ) { newTrack->m_Width = GetBoard()->GetCurrentTrackWidth(); @@ -310,6 +308,7 @@ bool PCB_EDIT_FRAME::Add_45_degrees_Segment( wxDC* DC ) } int segm_step_45 = wxRound( GetScreen()->GetGridSize().x / 2 ); + if( segm_step_45 < ( curTrack->m_Width * 2 ) ) segm_step_45 = curTrack->m_Width * 2; @@ -415,17 +414,15 @@ bool PCB_EDIT_FRAME::Add_45_degrees_Segment( wxDC* DC ) */ bool PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* DC ) { - int masquelayer = - g_TabOneLayerMask[( (PCB_SCREEN*) GetScreen() )->m_Active_Layer]; + int layerMask = g_TabOneLayerMask[( (PCB_SCREEN*) GetScreen() )->m_Active_Layer]; if( aTrack == NULL ) return false; - if( Drc_On && BAD_DRC== - m_drc->Drc( g_CurrentTrackSegment, GetBoard()->m_Track ) ) + if( Drc_On && BAD_DRC == m_drc->Drc( g_CurrentTrackSegment, GetBoard()->m_Track ) ) return false; - /* Sauvegarde des coord du point terminal de la piste */ + /* Saving the coordinate of end point of the trace */ wxPoint pos = g_CurrentTrackSegment->m_End; D( g_CurrentTrackList.VerifyListIntegrity(); ); @@ -454,7 +451,7 @@ bool PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* DC ) * This helps to reduce the computing time */ /* Attaching the end of the track. */ - BOARD_ITEM* LockPoint = LocateLockPoint( GetBoard(), pos, masquelayer ); + BOARD_ITEM* LockPoint = LocateLockPoint( GetBoard(), pos, layerMask ); if( LockPoint ) /* End of trace is on a pad. */ { @@ -490,8 +487,8 @@ bool PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* DC ) // Put entire new current segment list in BOARD, and prepare undo // command TRACK* track; - TRACK* insertBeforeMe = g_CurrentTrackSegment->GetBestInsertPoint( - GetBoard() ); + TRACK* insertBeforeMe = g_CurrentTrackSegment->GetBestInsertPoint( GetBoard() ); + while( ( track = g_CurrentTrackList.PopFront() ) != NULL ) { ITEM_PICKER picker( track, UR_NEW ); @@ -501,9 +498,10 @@ bool PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* DC ) trace_ratsnest_pad( DC ); - Trace_Une_Piste( DrawPanel, DC, firstTrack, newCount, GR_OR ); + DrawTraces( DrawPanel, DC, firstTrack, newCount, GR_OR ); int i = 0; + for( track = firstTrack; track && iNext() ) { track->m_Flags = 0; @@ -515,6 +513,7 @@ bool PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* DC ) { EraseRedundantTrack( DC, firstTrack, newCount, &s_ItemsListPicker ); } + SaveCopyInUndoList( s_ItemsListPicker, UR_UNSPECIFIED ); s_ItemsListPicker.ClearItemsList(); // s_ItemsListPicker is no more // owner of picked items @@ -524,9 +523,9 @@ bool PCB_EDIT_FRAME::End_Route( TRACK* aTrack, wxDC* DC ) GetBoard()->DisplayInfo( this ); } - wxASSERT( g_FirstTrackSegment==NULL ); - wxASSERT( g_CurrentTrackSegment==NULL ); - wxASSERT( g_CurrentTrackList.GetCount()==0 ); + wxASSERT( g_FirstTrackSegment == NULL ); + wxASSERT( g_CurrentTrackSegment == NULL ); + wxASSERT( g_CurrentTrackList.GetCount() == 0 ); if( GetBoard()->IsHightLightNetON() ) High_Light( DC ); @@ -632,10 +631,7 @@ static void PushTrack( EDA_DRAW_PANEL* panel ) if( !det ) return; - dist = - (track->m_Width + - 1) / 2 + (other->m_Width + 1) / 2 + track->GetClearance( - other ) + 2; + dist = (track->m_Width + 1) / 2 + (other->m_Width + 1) / 2 + track->GetClearance( other ) + 2; /* * DRC wants >, so +1. @@ -653,6 +649,7 @@ static void PushTrack( EDA_DRAW_PANEL* panel ) n.x = -vec.y; n.y = vec.x; } + f = dist / hypot( double(n.x), double(n.y) ); n.x = wxRound( f * n.x ); n.y = wxRound( f * n.y ); @@ -688,7 +685,7 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo /* Erase old track */ if( aErase ) { - Trace_Une_Piste( aPanel, aDC, g_FirstTrackSegment, g_CurrentTrackList.GetCount(), GR_XOR ); + DrawTraces( aPanel, aDC, g_FirstTrackSegment, g_CurrentTrackList.GetCount(), GR_XOR ); frame->trace_ratsnest_pad( aDC ); @@ -744,7 +741,7 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo /* Calculate of the end of the path for the permitted directions: * horizontal, vertical or 45 degrees. */ - Calcule_Coord_Extremite_45( screen->GetCrossHairPosition(), + CalculateSegmentEndPoint( screen->GetCrossHairPosition(), g_CurrentTrackSegment->m_Start.x, g_CurrentTrackSegment->m_Start.y, &g_CurrentTrackSegment->m_End.x, @@ -758,7 +755,7 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo /* Redraw the new track */ D( g_CurrentTrackList.VerifyListIntegrity(); ); - Trace_Une_Piste( aPanel, aDC, g_FirstTrackSegment, g_CurrentTrackList.GetCount(), GR_XOR ); + DrawTraces( aPanel, aDC, g_FirstTrackSegment, g_CurrentTrackList.GetCount(), GR_XOR ); if( showTrackClearanceMode >= SHOW_CLEARANCE_NEW_TRACKS_AND_VIA_AREAS ) { @@ -776,6 +773,7 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo * interesting segment. */ TRACK* isegm = g_CurrentTrackSegment; + if( isegm->GetLength() == 0 && g_CurrentTrackSegment->Back() ) isegm = g_CurrentTrackSegment->Back(); @@ -787,12 +785,14 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo double trackLen = 0.0; double lenDie = 0.0; wxString msg; + // If the starting point is on a pad, add current track length+ lenght die if( g_FirstTrackSegment->GetState( BEGIN_ONPAD ) ) { D_PAD * pad = (D_PAD *) g_FirstTrackSegment->start; lenDie = (double) pad->m_LengthDie; - } + } + // calculate track len on board: for( TRACK* track = g_FirstTrackSegment; track; track = track->Next() ) trackLen += track->GetLength(); @@ -823,7 +823,7 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo /* Determine the coordinate to advanced the the current segment * in 0, 90, or 45 degrees, depending on position of origin and \a aPosition. */ -void Calcule_Coord_Extremite_45( const wxPoint& aPosition, int ox, int oy, int* fx, int* fy ) +void CalculateSegmentEndPoint( const wxPoint& aPosition, int ox, int oy, int* fx, int* fy ) { int deltax, deltay, angle; @@ -865,6 +865,7 @@ void Calcule_Coord_Extremite_45( const wxPoint& aPosition, int ox, int oy, int* /* Recalculate the signs fo deltax and deltaY. */ if( ( aPosition.x - ox ) < 0 ) deltax = -deltax; + if( ( aPosition.y - oy ) < 0 ) deltay = -deltay; @@ -891,12 +892,14 @@ void ComputeBreakPoint( TRACK* track, int SegmentCount, wxPoint end ) if( SegmentCount <= 0 ) return; + if( track == NULL ) return; TRACK* newTrack = track; track = track->Back(); SegmentCount--; + if( track ) { iDx = end.x - track->m_Start.x; @@ -907,6 +910,7 @@ void ComputeBreakPoint( TRACK* track, int SegmentCount, wxPoint end ) } TRACK* lastTrack = track ? track->Back() : NULL; + if( lastTrack ) { if(( (lastTrack->m_End.x == lastTrack->m_Start.x) @@ -915,10 +919,13 @@ void ComputeBreakPoint( TRACK* track, int SegmentCount, wxPoint end ) { iAngle = 45; } - } else { - if (g_Alternate_Track_Posture) { - iAngle = 45; - } + } + else + { + if( g_Alternate_Track_Posture ) + { + iAngle = 45; + } } if( iAngle == 0 ) @@ -942,6 +949,7 @@ void ComputeBreakPoint( TRACK* track, int SegmentCount, wxPoint end ) track->m_End.x = end.x + iDy; else track->m_End.x = end.x - iDy; + track->m_End.y = track->m_Start.y; break; @@ -952,6 +960,7 @@ void ComputeBreakPoint( TRACK* track, int SegmentCount, wxPoint end ) /* Recalculate the signs fo deltax and deltaY. */ if( ( end.x - track->m_Start.x ) < 0 ) iDx = -iDx; + if( ( end.y - track->m_Start.y ) < 0 ) iDy = -iDy; @@ -976,6 +985,7 @@ void ComputeBreakPoint( TRACK* track, int SegmentCount, wxPoint end ) newTrack->m_Start = track->m_End; } + newTrack->m_End = end; } @@ -993,10 +1003,12 @@ void DeleteNullTrackSegments( BOARD* pcb, DLIST& aTrackList ) TRACK* oldtrack; BOARD_ITEM* LockPoint = track->start; + while( track != NULL ) { oldtrack = track; track = track->Next(); + if( !oldtrack->IsNull() ) { continue; @@ -1015,6 +1027,7 @@ void DeleteNullTrackSegments( BOARD* pcb, DLIST& aTrackList ) // we must set the pointers on connected items and the connection status oldtrack = track = firsttrack; firsttrack->start = NULL; + while( track != NULL ) { oldtrack = track; @@ -1028,24 +1041,29 @@ void DeleteNullTrackSegments( BOARD* pcb, DLIST& aTrackList ) } firsttrack->start = LockPoint; + if( LockPoint && LockPoint->Type()==TYPE_PAD ) firsttrack->SetState( BEGIN_ONPAD, ON ); track = firsttrack; + while( track != NULL ) { TRACK* next_track = track->Next(); LockPoint = Locate_Pad_Connecte( pcb, track, END ); + if( LockPoint ) { track->end = LockPoint; track->SetState( END_ONPAD, ON ); + if( next_track ) { next_track->start = LockPoint; next_track->SetState( BEGIN_ONPAD, ON ); } } + track = next_track; } } @@ -1065,6 +1083,7 @@ void EnsureEndTrackOnPad( D_PAD* Pad ) } TRACK* lasttrack = g_CurrentTrackSegment; + if( !g_CurrentTrackSegment->IsNull() ) { /* Must create a new segment, from track end to pad center */ diff --git a/pcbnew/edtxtmod.cpp b/pcbnew/edtxtmod.cpp index 8093f4a5ca..1c4af156f9 100644 --- a/pcbnew/edtxtmod.cpp +++ b/pcbnew/edtxtmod.cpp @@ -45,8 +45,7 @@ TEXTE_MODULE* PCB_BASE_FRAME::CreateTextModule( MODULE* Module, wxDC* DC ) Text->m_Text = wxT( "text" ); g_ModuleTextWidth = Clamp_Text_PenSize( g_ModuleTextWidth, - MIN( g_ModuleTextSize.x, - g_ModuleTextSize.y ), true ); + MIN( g_ModuleTextSize.x, g_ModuleTextSize.y ), true ); Text->m_Size = g_ModuleTextSize; Text->m_Thickness = g_ModuleTextWidth; Text->m_Pos = GetScreen()->GetCrossHairPosition(); @@ -56,6 +55,7 @@ TEXTE_MODULE* PCB_BASE_FRAME::CreateTextModule( MODULE* Module, wxDC* DC ) DrawPanel->MoveCursorToCrossHair(); Text->m_Flags = 0; + if( DC ) Text->Draw( DrawPanel, DC, GR_OR ); @@ -74,8 +74,7 @@ void PCB_BASE_FRAME::RotateTextModule( TEXTE_MODULE* Text, wxDC* DC ) MODULE* module = (MODULE*) Text->GetParent(); - if( module && module->m_Flags == 0 && Text->m_Flags == 0 ) // prepare undo - // command + if( module && module->m_Flags == 0 && Text->m_Flags == 0 ) // prepare undo command { if( this->m_Ident == PCB_FRAME ) SaveCopyInUndoList( module, UR_CHANGED ); @@ -85,6 +84,7 @@ void PCB_BASE_FRAME::RotateTextModule( TEXTE_MODULE* Text, wxDC* DC ) Text->Draw( DrawPanel, DC, GR_XOR, MoveVector ); Text->m_Orient += 900; + while( Text->m_Orient >= 1800 ) Text->m_Orient -= 1800; @@ -93,6 +93,7 @@ void PCB_BASE_FRAME::RotateTextModule( TEXTE_MODULE* Text, wxDC* DC ) if( module ) module->m_LastEdit_Time = time( NULL ); + OnModify(); } @@ -185,7 +186,7 @@ void PCB_BASE_FRAME::StartMoveTexteModule( TEXTE_MODULE* Text, wxDC* DC ) SetCurItem( Text ); DrawPanel->SetMouseCapture( Show_MoveTexte_Module, AbortMoveTextModule ); - DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, TRUE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, true ); } @@ -200,14 +201,17 @@ void PCB_BASE_FRAME::PlaceTexteModule( TEXTE_MODULE* Text, wxDC* DC ) /* Update the coordinates for anchor. */ MODULE* Module = (MODULE*) Text->GetParent(); + if( Module ) { // Prepare undo command (a rotation can be made while moving) EXCHG( Text->m_Orient, TextInitialOrientation ); + if( m_Ident == PCB_FRAME ) SaveCopyInUndoList( Module, UR_CHANGED ); else SaveCopyInUndoList( Module, UR_MODEDIT ); + EXCHG( Text->m_Orient, TextInitialOrientation ); // Set the new position for text. @@ -224,7 +228,9 @@ void PCB_BASE_FRAME::PlaceTexteModule( TEXTE_MODULE* Text, wxDC* DC ) DrawPanel->RefreshDrawingRect( Text->GetBoundingBox() ); } else + { Text->m_Pos = GetScreen()->GetCrossHairPosition(); + } } // leave it at (0,0) so we can use it Rotate when not moving. @@ -276,12 +282,14 @@ void PCB_BASE_FRAME::ResetTextSize( BOARD_ITEM* aItem, wxDC* aDC ) pcbText = (TEXTE_PCB*) aItem; text = (EDA_TEXT*) pcbText; break; + case TYPE_TEXTE_MODULE: newSize = g_ModuleTextSize; newThickness = g_ModuleTextWidth; moduleText = (TEXTE_MODULE*) aItem; text = (EDA_TEXT*) moduleText; break; + default: // Exit if aItem is not a text field return; @@ -289,8 +297,7 @@ void PCB_BASE_FRAME::ResetTextSize( BOARD_ITEM* aItem, wxDC* aDC ) } // Exit if there's nothing to do - if( text->GetSize() == newSize - && text->GetThickness() == newThickness ) + if( text->GetSize() == newSize && text->GetThickness() == newThickness ) return; // Push item to undo list @@ -299,9 +306,11 @@ void PCB_BASE_FRAME::ResetTextSize( BOARD_ITEM* aItem, wxDC* aDC ) case TYPE_TEXTE: SaveCopyInUndoList( pcbText, UR_CHANGED ); break; + case TYPE_TEXTE_MODULE: SaveCopyInUndoList( moduleText->GetParent(), UR_CHANGED ); break; + default: break; } @@ -333,28 +342,33 @@ void PCB_BASE_FRAME::ResetModuleTextSizes( int aType, wxDC* aDC ) while( module ) { itemWrapper.m_PickedItem = module; + switch( aType ) { case TEXT_is_REFERENCE: item = module->m_Reference; - if( item->GetSize() != g_ModuleTextSize - || item->GetThickness() != g_ModuleTextWidth ) + + if( item->GetSize() != g_ModuleTextSize || item->GetThickness() != g_ModuleTextWidth ) undoItemList.PushItem( itemWrapper ); + break; + case TEXT_is_VALUE: item = module->m_Value; - if( item->GetSize() != g_ModuleTextSize - || item->GetThickness() != g_ModuleTextWidth ) + + if( item->GetSize() != g_ModuleTextSize || item->GetThickness() != g_ModuleTextWidth ) undoItemList.PushItem( itemWrapper ); + break; + case TEXT_is_DIVERS: // Go through all other module text fields - for( boardItem = module->m_Drawings; boardItem; - boardItem = boardItem->Next() ) + for( boardItem = module->m_Drawings; boardItem; boardItem = boardItem->Next() ) { if( boardItem->Type() == TYPE_TEXTE_MODULE ) { item = (TEXTE_MODULE*) boardItem; + if( item->GetSize() != g_ModuleTextSize || item->GetThickness() != g_ModuleTextWidth ) { @@ -363,7 +377,9 @@ void PCB_BASE_FRAME::ResetModuleTextSizes( int aType, wxDC* aDC ) } } } + break; + default: break; } @@ -380,19 +396,21 @@ void PCB_BASE_FRAME::ResetModuleTextSizes( int aType, wxDC* aDC ) for( ii = 0; ii < undoItemList.GetCount(); ii++ ) { module = (MODULE*) undoItemList.GetPickedItem( ii ); + switch( aType ) { case TEXT_is_REFERENCE: module->m_Reference->SetThickness( g_ModuleTextWidth ); module->m_Reference->SetSize( g_ModuleTextSize ); break; + case TEXT_is_VALUE: module->m_Value->SetThickness( g_ModuleTextWidth ); module->m_Value->SetSize( g_ModuleTextSize ); break; + case TEXT_is_DIVERS: - for( boardItem = module->m_Drawings; boardItem; - boardItem = boardItem->Next() ) + for( boardItem = module->m_Drawings; boardItem; boardItem = boardItem->Next() ) { if( boardItem->Type() == TYPE_TEXTE_MODULE ) { @@ -401,6 +419,7 @@ void PCB_BASE_FRAME::ResetModuleTextSizes( int aType, wxDC* aDC ) item->SetSize( g_ModuleTextSize ); } } + break; } } diff --git a/pcbnew/export_gencad.cpp b/pcbnew/export_gencad.cpp index 1430db6174..db2b9b276d 100644 --- a/pcbnew/export_gencad.cpp +++ b/pcbnew/export_gencad.cpp @@ -92,7 +92,7 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& event ) offsetX = m_Auxiliary_Axis_Position.x; offsetY = m_Auxiliary_Axis_Position.y; - Compile_Ratsnest( NULL, TRUE ); + Compile_Ratsnest( NULL, true ); /* Temporary modification of footprints that are flipped (i.e. on bottom * layer) to convert them to non flipped footprints. @@ -101,9 +101,11 @@ void PCB_EDIT_FRAME::ExportToGenCAD( wxCommandEvent& event ) * these changes will be undone later */ MODULE* module; + for( module = GetBoard()->m_Modules; module != NULL; module = module->Next() ) { module->flag = 0; + if( module->GetLayer() == LAYER_N_BACK ) { module->Flip( module->m_Pos ); @@ -198,12 +200,12 @@ void CreatePadsShapesSection( FILE* file, BOARD* pcb ) pads.insert( pads.end(), pcb->m_NetInfo->m_PadsFullList.begin(), pcb->m_NetInfo->m_PadsFullList.end() ); - qsort( &pads[0], pcb->GetPadsCount(), sizeof( D_PAD* ), - Pad_list_Sort_by_Shapes ); + qsort( &pads[0], pcb->GetPadsCount(), sizeof( D_PAD* ), Pad_list_Sort_by_Shapes ); } D_PAD* old_pad = NULL; int pad_name_number = 0; + for( unsigned i = 0; i= 0 ) // Horizontal oval { - int rayon = dy; + int radius = dy; fprintf( file, "LINE %d %d %d %d\n", - -dr + pad->m_Offset.x, -pad->m_Offset.y - rayon, - dr + pad->m_Offset.x, -pad->m_Offset.y - rayon ); + -dr + pad->m_Offset.x, -pad->m_Offset.y - radius, + dr + pad->m_Offset.x, -pad->m_Offset.y - radius ); fprintf( file, "ARC %d %d %d %d %d %d\n", - dr + pad->m_Offset.x, -pad->m_Offset.y - rayon, - dr + pad->m_Offset.x, -pad->m_Offset.y + rayon, + dr + pad->m_Offset.x, -pad->m_Offset.y - radius, + dr + pad->m_Offset.x, -pad->m_Offset.y + radius, dr + pad->m_Offset.x, -pad->m_Offset.y ); fprintf( file, "LINE %d %d %d %d\n", - dr + pad->m_Offset.x, -pad->m_Offset.y + rayon, - -dr + pad->m_Offset.x, -pad->m_Offset.y + rayon ); + dr + pad->m_Offset.x, -pad->m_Offset.y + radius, + -dr + pad->m_Offset.x, -pad->m_Offset.y + radius ); fprintf( file, "ARC %d %d %d %d %d %d\n", - -dr + pad->m_Offset.x, -pad->m_Offset.y + rayon, - -dr + pad->m_Offset.x, -pad->m_Offset.y - rayon, + -dr + pad->m_Offset.x, -pad->m_Offset.y + radius, + -dr + pad->m_Offset.x, -pad->m_Offset.y - radius, -dr + pad->m_Offset.x, -pad->m_Offset.y ); } else // Vertical oval { dr = -dr; - int rayon = dx; + int radius = dx; fprintf( file, "LINE %d %d %d %d\n", - -rayon + pad->m_Offset.x, -pad->m_Offset.y - dr, - -rayon + pad->m_Offset.x, -pad->m_Offset.y + dr ); + -radius + pad->m_Offset.x, -pad->m_Offset.y - dr, + -radius + pad->m_Offset.x, -pad->m_Offset.y + dr ); fprintf( file, "ARC %d %d %d %d %d %d\n", - -rayon + pad->m_Offset.x, -pad->m_Offset.y + dr, - rayon + pad->m_Offset.x, -pad->m_Offset.y + dr, + -radius + pad->m_Offset.x, -pad->m_Offset.y + dr, + radius + pad->m_Offset.x, -pad->m_Offset.y + dr, pad->m_Offset.x, -pad->m_Offset.y + dr ); fprintf( file, "LINE %d %d %d %d\n", - rayon + pad->m_Offset.x, -pad->m_Offset.y + dr, - rayon + pad->m_Offset.x, -pad->m_Offset.y - dr ); + radius + pad->m_Offset.x, -pad->m_Offset.y + dr, + radius + pad->m_Offset.x, -pad->m_Offset.y - dr ); fprintf( file, "ARC %d %d %d %d %d %d\n", - rayon + pad->m_Offset.x, -pad->m_Offset.y - dr, - -rayon + pad->m_Offset.x, -pad->m_Offset.y - dr, + radius + pad->m_Offset.x, -pad->m_Offset.y - dr, + -radius + pad->m_Offset.x, -pad->m_Offset.y - dr, pad->m_Offset.x, -pad->m_Offset.y - dr ); } break; @@ -349,17 +351,19 @@ void CreateShapesSection( FILE* file, BOARD* pcb ) for( module = pcb->m_Modules; module != NULL; module = module->Next() ) { FootprintWriteShape( file, module ); + for( pad = module->m_Pads; pad != NULL; pad = pad->Next() ) { layer = "ALL"; - if( ( pad->m_Masque_Layer & ALL_CU_LAYERS ) == LAYER_BACK ) + + if( ( pad->m_layerMask & ALL_CU_LAYERS ) == LAYER_BACK ) { if( module->GetLayer() == LAYER_N_FRONT ) layer = "BOTTOM"; else layer = "TOP"; } - else if( ( pad->m_Masque_Layer & ALL_CU_LAYERS ) == LAYER_FRONT ) + else if( ( pad->m_layerMask & ALL_CU_LAYERS ) == LAYER_FRONT ) { if( module->GetLayer() == LAYER_N_FRONT ) layer = "TOP"; @@ -368,6 +372,7 @@ void CreateShapesSection( FILE* file, BOARD* pcb ) } pad->ReturnStringPadName( pinname ); + if( pinname.IsEmpty() ) pinname = wxT( "noname" ); @@ -377,8 +382,10 @@ void CreateShapesSection( FILE* file, BOARD* pcb ) TO_UTF8( pinname ), pad->GetSubRatsnest(), pad->m_Pos0.x, -pad->m_Pos0.y, layer, orient / 10, mirror ); + if( orient % 10 ) fprintf( file, " .%d", orient % 10 ); + fprintf( file, "\n" ); } } @@ -406,6 +413,7 @@ void CreateComponentsSection( FILE* file, BOARD* pcb ) for( ; module != NULL; module = module->Next() ) { int orient = module->m_Orient; + if( module->flag ) { mirror = "MIRRORX"; // Mirrored relative to X axis @@ -420,24 +428,22 @@ void CreateComponentsSection( FILE* file, BOARD* pcb ) flip = "0"; } - fprintf( file, "COMPONENT %s\n", - TO_UTF8( module->m_Reference->m_Text ) ); - fprintf( file, "DEVICE %s\n", - TO_UTF8( module->m_Reference->m_Text ) ); - fprintf( file, "PLACE %d %d\n", mapXto( module->m_Pos.x ), - mapYto( module->m_Pos.y ) ); + fprintf( file, "COMPONENT %s\n", TO_UTF8( module->m_Reference->m_Text ) ); + fprintf( file, "DEVICE %s\n", TO_UTF8( module->m_Reference->m_Text ) ); + fprintf( file, "PLACE %d %d\n", mapXto( module->m_Pos.x ), mapYto( module->m_Pos.y ) ); fprintf( file, "LAYER %s\n", (module->flag) ? "BOTTOM" : "TOP" ); - fprintf( file, "ROTATION %d", orient / 10 ); + if( orient % 10 ) fprintf( file, ".%d", orient % 10 ); + fputs( "\n", file ); - fprintf( file, "SHAPE %s %s %s\n", - TO_UTF8( module->m_Reference->m_Text ), mirror, flip ); + fprintf( file, "SHAPE %s %s %s\n", TO_UTF8( module->m_Reference->m_Text ), mirror, flip ); /* creates texts (ref and value) */ PtTexte = module->m_Reference; + for( ii = 0; ii < 2; ii++ ) { int orient = PtTexte->m_Orient; @@ -489,8 +495,8 @@ void CreateSignalsSection( FILE* file, BOARD* pcb ) for( unsigned ii = 0; ii < pcb->m_NetInfo->GetCount(); ii++ ) { net = pcb->m_NetInfo->GetNetItem( ii ); - if( net->GetNetname() == wxEmptyString ) // dummy netlist (no - // connection) + + if( net->GetNetname() == wxEmptyString ) // dummy netlist (no connection) { wxString msg; msg << wxT( "NoConnection" ) << NbNoConn++; net->SetNetname( msg ); @@ -509,6 +515,7 @@ void CreateSignalsSection( FILE* file, BOARD* pcb ) for( pad = module->m_Pads; pad != NULL; pad = pad->Next() ) { wxString padname; + if( pad->GetNet() != net->GetNet() ) continue; @@ -536,13 +543,11 @@ bool CreateHeaderInfoData( FILE* file, PCB_EDIT_FRAME* frame ) fputs( "$HEADER\n", file ); fputs( "GENCAD 1.4\n", file ); - msg = wxT( "USER " ) + wxGetApp().GetAppName() + wxT( " " ) + - GetBuildVersion(); + msg = wxT( "USER " ) + wxGetApp().GetAppName() + wxT( " " ) + GetBuildVersion(); fputs( TO_UTF8( msg ), file ); fputs( "\n", file ); msg = wxT( "DRAWING " ) + screen->GetFileName(); fputs( TO_UTF8( msg ), file ); fputs( "\n", file ); - msg = wxT( "REVISION " ) + screen->m_Revision + wxT( " " ) + - screen->m_Date; + msg = wxT( "REVISION " ) + screen->m_Revision + wxT( " " ) + screen->m_Date; fputs( TO_UTF8( msg ), file ); fputs( "\n", file ); msg.Printf( wxT( "UNITS USER %d" ), PCB_INTERNAL_UNIT ); fputs( TO_UTF8( msg ), file ); fputs( "\n", file ); @@ -553,7 +558,7 @@ bool CreateHeaderInfoData( FILE* file, PCB_EDIT_FRAME* frame ) fputs( "INTERTRACK 0\n", file ); fputs( "$ENDHEADER\n\n", file ); - return TRUE; + return true; } @@ -568,10 +573,13 @@ static int Track_list_Sort_by_Netcode( const void* refptr, const void* objptr ) ref = *( (TRACK**) refptr ); cmp = *( (TRACK**) objptr ); + if( ( diff = ref->GetNet() - cmp->GetNet() ) ) return diff; + if( ( diff = ref->m_Width - cmp->m_Width ) ) return diff; + if( ( diff = ref->GetLayer() - cmp->GetLayer() ) ) return diff; @@ -625,6 +633,7 @@ void CreateRoutesSection( FILE* file, BOARD* pcb ) fputs( "$ROUTES\n", file ); old_netcode = -1; old_width = -1; old_layer = -1; + for( ii = 0; ii < nbitems; ii++ ) { track = tracklist[ii]; @@ -633,10 +642,12 @@ void CreateRoutesSection( FILE* file, BOARD* pcb ) old_netcode = track->GetNet(); NETINFO_ITEM* net = pcb->FindNet( track->GetNet() ); wxString netname; + if( net && (net->GetNetname() != wxEmptyString) ) netname = net->GetNetname(); else netname = wxT( "_noname_" ); + fprintf( file, "ROUTE %s\n", TO_UTF8( netname ) ); } @@ -652,8 +663,7 @@ void CreateRoutesSection( FILE* file, BOARD* pcb ) { old_layer = track->GetLayer(); fprintf( file, "LAYER %s\n", - TO_UTF8( GenCAD_Layer_Name[track->GetLayer() & - 0x1F] ) ); + TO_UTF8( GenCAD_Layer_Name[track->GetLayer() & 0x1F] ) ); } fprintf( file, "LINE %d %d %d %d\n", @@ -688,21 +698,21 @@ void CreateDevicesSection( FILE* file, BOARD* pcb ) for( module = pcb->m_Modules; module != NULL; module = module->Next() ) { - fprintf( file, "DEVICE %s\n", - TO_UTF8( module->m_Reference->m_Text ) ); + fprintf( file, "DEVICE %s\n", TO_UTF8( module->m_Reference->m_Text ) ); fprintf( file, "PART %s\n", TO_UTF8( module->m_LibRef ) ); fprintf( file, "TYPE %s\n", "UNKNOWN" ); + for( pad = module->m_Pads; pad != NULL; pad = pad->Next() ) { fprintf( file, "PINDESCR %.4s", pad->m_Padname ); + if( pad->GetNetname() == wxEmptyString ) fputs( " NoConn\n", file ); else fprintf( file, " %.4s\n", pad->m_Padname ); } - fprintf( file, "ATTRIBUTE %s\n", - TO_UTF8( module->m_Value->m_Text ) ); + fprintf( file, "ATTRIBUTE %s\n", TO_UTF8( module->m_Value->m_Text ) ); } fputs( "$ENDDEVICES\n\n", file ); @@ -760,6 +770,7 @@ void CreateTracksInfoData( FILE* file, BOARD* pcb ) std::vector trackinfo; unsigned ii; + for( track = pcb->m_Track; track != NULL; track = track->Next() ) { if( last_width != track->m_Width ) // Find a thickness already used. @@ -796,6 +807,7 @@ void CreateTracksInfoData( FILE* file, BOARD* pcb ) // Write data fputs( "$TRACKS\n", file ); + for( ii = 0; ii < trackinfo.size(); ii++ ) { fprintf( file, "TRACK TRACK%d %d\n", trackinfo[ii], trackinfo[ii] ); @@ -824,22 +836,25 @@ void FootprintWriteShape( FILE* file, MODULE* module ) /* creates header: */ fprintf( file, "SHAPE %s\n", TO_UTF8( module->m_Reference->m_Text ) ); - fprintf( file, "INSERT %s\n", - (module->m_Attributs & MOD_CMS) ? "SMD" : "TH" ); + fprintf( file, "INSERT %s\n", (module->m_Attributs & MOD_CMS) ? "SMD" : "TH" ); /* creates Attributes */ if( module->m_Attributs != MOD_DEFAULT ) { fprintf( file, "ATTRIBUTE" ); + if( module->m_Attributs & MOD_CMS ) fprintf( file, " PAD_SMD" ); + if( module->m_Attributs & MOD_VIRTUAL ) fprintf( file, " VIRTUAL" ); + fprintf( file, "\n" ); } /* creates Drawing */ item = module->m_Drawings; + for( ; item != NULL; item = item->Next() ) { switch( item->Type() ) @@ -860,12 +875,10 @@ void FootprintWriteShape( FILE* file, MODULE* module ) case S_CIRCLE: { - int rayon = (int) hypot( - (double) ( edge->m_End0.x - edge->m_Start0.x ), - (double) ( edge->m_End0.y - edge->m_Start0.y ) ); + int radius = (int) hypot( (double) ( edge->m_End0.x - edge->m_Start0.x ), + (double) ( edge->m_End0.y - edge->m_Start0.y ) ); fprintf( file, "CIRCLE %d %d %d\n", - edge->m_Start0.x, y_axis_sign * edge->m_Start0.y, - rayon ); + edge->m_Start0.x, y_axis_sign * edge->m_Start0.y, radius ); break; } @@ -876,7 +889,8 @@ void FootprintWriteShape( FILE* file, MODULE* module ) // edge->m_Start0 is the arc center relative to the shape position // edge->m_End0 is the arc start point relative to the shape position arcStart = edge->m_End0; - // calculate arcEnd arc end point relative to the shape position, in pcbnew coordinates + // calculate arcEnd arc end point relative to the shape position, in pcbnew + // coordinates arcEnd = arcStart; RotatePoint( &arcEnd, edge->m_Start0, -edge->m_Angle ); // due to difference between pcbnew and gencad, swap arc start and arc end diff --git a/pcbnew/export_vrml.cpp b/pcbnew/export_vrml.cpp index 630f5dec9c..8ed490377b 100644 --- a/pcbnew/export_vrml.cpp +++ b/pcbnew/export_vrml.cpp @@ -168,8 +168,7 @@ static void bag_flat_triangle( int layer, /*{{{*/ { double z = layer_z[layer]; - layer_triangles[layer].push_back( Triangle( x1, y1, z, - x2, y2, z, x3, y3, z ) ); + layer_triangles[layer].push_back( Triangle( x1, y1, z, x2, y2, z, x3, y3, z ) ); } @@ -178,12 +177,10 @@ void FlatFan::bag( int layer, bool close ) /*{{{*/ unsigned i; for( i = 0; i < pts.size() - 1; i++ ) - bag_flat_triangle( layer, c.x, c.y, pts[i].x, pts[i].y, - pts[i + 1].x, pts[i + 1].y ); + bag_flat_triangle( layer, c.x, c.y, pts[i].x, pts[i].y, pts[i + 1].x, pts[i + 1].y ); if( close ) - bag_flat_triangle( layer, c.x, c.y, pts[i].x, pts[i].y, - pts[0].x, pts[0].y ); + bag_flat_triangle( layer, c.x, c.y, pts[i].x, pts[i].y, pts[0].x, pts[0].y ); } @@ -222,14 +219,12 @@ static void bag_vquad( TriangleBag& triangles, /*{{{*/ double x1, double y1, double x2, double y2, double z1, double z2 ) { - triangles.push_back( Triangle( - x1, y1, z1, - x2, y2, z1, - x2, y2, z2 ) ); - triangles.push_back( Triangle( - x1, y1, z1, - x2, y2, z2, - x1, y1, z2 ) ); + triangles.push_back( Triangle( x1, y1, z1, + x2, y2, z1, + x2, y2, z2 ) ); + triangles.push_back( Triangle( x1, y1, z1, + x2, y2, z2, + x1, y1, z2 ) ); } @@ -345,8 +340,7 @@ static void write_triangle_bag( FILE* output_file, int color_index, /*{{{*/ i != triangles.end(); i++ ) { - fprintf( output_file, "%d %d %d -1\n", - j, j + 1, j + 2 ); + fprintf( output_file, "%d %d %d -1\n", j, j + 1, j + 2 ); j += 3; } } @@ -408,6 +402,7 @@ static void export_vrml_line( int layer, double startx, double starty, /*{{{*/ /* Output the 'bone' as a triangle fan, this is the fan centre */ fan.c.x = (startx + endx) / 2; fan.c.y = (starty + endy) / 2; + /* The 'end' side cap */ for( alpha = angle - PI2; alpha < angle + PI2; alpha += PI2 / divisions ) fan.add( endx + r * cos( alpha ), endy + r * sin( alpha ) ); @@ -428,16 +423,16 @@ static void export_vrml_line( int layer, double startx, double starty, /*{{{*/ static void export_vrml_circle( int layer, double startx, double starty, /*{{{*/ double endx, double endy, double width, int divisions ) { - double hole, rayon; + double hole, radius; FlatRing ring; - rayon = hypot( startx - endx, starty - endy ) + ( width / 2); - hole = rayon - width; + radius = hypot( startx - endx, starty - endy ) + ( width / 2); + hole = radius - width; for( double alpha = 0; alpha < M_PI * 2; alpha += M_PI * 2 / divisions ) { ring.add_inner( startx + hole * cos( alpha ), starty + hole * sin( alpha ) ); - ring.add_outer( startx + rayon * cos( alpha ), starty + rayon * sin( alpha ) ); + ring.add_outer( startx + radius * cos( alpha ), starty + radius * sin( alpha ) ); } ring.bag( layer ); @@ -454,6 +449,7 @@ static void export_vrml_slot( TriangleBag& triangles, /*{{{*/ loop.z_top = layer_z[top_layer]; loop.z_bottom = layer_z[bottom_layer]; double angle = orient / 1800.0 * M_PI; + if( dy > dx ) { EXCHG( dx, dy ); @@ -466,14 +462,17 @@ static void export_vrml_slot( TriangleBag& triangles, /*{{{*/ /* The first side cap */ capx = xc + cos( angle ) * dx / 2; capy = yc + sin( angle ) * dx / 2; + for( alpha = angle - PI2; alpha < angle + PI2; alpha += PI2 / divisions ) loop.add( capx + r * cos( alpha ), capy + r * sin( alpha ) ); alpha = angle + PI2; loop.add( capx + r * cos( alpha ), capy + r * sin( alpha ) ); + /* The other side cap */ capx = xc - cos( angle ) * dx / 2; capy = yc - sin( angle ) * dx / 2; + for( alpha = angle + PI2; alpha < angle + 3 * PI2; alpha += PI2 / divisions ) loop.add( capx + r * cos( alpha ), capy + r * sin( alpha ) ); @@ -491,6 +490,7 @@ static void export_vrml_hole( TriangleBag& triangles, /*{{{*/ loop.z_top = layer_z[top_layer]; loop.z_bottom = layer_z[bottom_layer]; + for( double alpha = 0; alpha < M_PI * 2; alpha += M_PI * 2 / divisions ) loop.add( xc + cos( alpha ) * hole, yc + sin( alpha ) * hole ); @@ -507,10 +507,11 @@ static void export_vrml_varc( TriangleBag& triangles, /*{{{*/ loop.z_top = layer_z[top_layer]; loop.z_bottom = layer_z[bottom_layer]; double angle = atan2( endx - startx, endy - starty ); - double rayon = hypot( startx - endx, starty - endy ); + double radius = hypot( startx - endx, starty - endy ); + for( double alpha = angle; alpha < angle + PI2; alpha += PI2 / divisions ) { - loop.add( startx + cos( alpha ) * rayon, starty + sin( alpha ) * rayon ); + loop.add( startx + cos( alpha ) * radius, starty + sin( alpha ) * radius ); } loop.bag( triangles ); @@ -527,6 +528,7 @@ static void export_vrml_oval_pad( int layer, /*{{{*/ fan.c.x = xc; fan.c.y = yc; double angle = orient / 1800.0 * M_PI; + if( dy > dx ) { EXCHG( dx, dy ); @@ -536,9 +538,11 @@ static void export_vrml_oval_pad( int layer, /*{{{*/ /* The exchange above means that cutter radius is alvays dy/2 */ double r = dy / 2; double alpha; + /* The first side cap */ capx = xc + cos( angle ) * dx / 2; capy = yc + sin( angle ) * dx / 2; + for( alpha = angle - PI2; alpha < angle + PI2; alpha += PI2 / divisions ) fan.add( capx + r * cos( alpha ), capy + r * sin( alpha ) ); @@ -547,6 +551,7 @@ static void export_vrml_oval_pad( int layer, /*{{{*/ /* The other side cap */ capx = xc - cos( angle ) * dx / 2; capy = yc - sin( angle ) * dx / 2; + for( alpha = angle + PI2; alpha < angle + 3 * PI2; alpha += PI2 / divisions ) fan.add( capx + r * cos( alpha ), capy + r * sin( alpha ) ); @@ -560,16 +565,16 @@ static void export_vrml_arc( int layer, double startx, double starty, /*{{{*/ double endx, double endy, double width, int divisions ) { FlatRing ring; - double hole, rayon; + double hole, radius; double angle = atan2( endx - startx, endy - starty ); - rayon = hypot( startx - endx, starty - endy ) + ( width / 2); - hole = rayon - width; + radius = hypot( startx - endx, starty - endy ) + ( width / 2); + hole = radius - width; for( double alpha = angle; alpha < angle + PI2; alpha += PI2 / divisions ) { ring.add_inner( startx + cos( alpha ) * hole, starty + sin( alpha ) * hole ); - ring.add_outer( startx + cos( alpha ) * rayon, starty + sin( alpha ) * rayon ); + ring.add_outer( startx + cos( alpha ) * radius, starty + sin( alpha ) * radius ); } ring.bag( layer, false ); @@ -650,9 +655,11 @@ static void export_vrml_pcbtext( TEXTE_PCB* text ) /* Coupling by globals! Ewwww... */ s_text_layer = text->GetLayer(); s_text_width = text->m_Thickness; + wxSize size = text->m_Size; if( text->m_Mirror ) NEGATE( size.x ); + if( text->m_MultilineAllowed ) { wxPoint pos = text->m_Pos; @@ -720,6 +727,7 @@ static void export_round_padstack( BOARD* pcb, double x, double y, double r, /*{ /* The last layer is always the component one, unless it's single face */ if( (layer > FIRST_COPPER_LAYER) && (layer == copper_layers - 1) ) layer = LAST_COPPER_LAYER; + if( layer <= top_layer ) export_vrml_circle( layer, x, y, x + r / 2, y, r, divisions ); } @@ -890,7 +898,7 @@ static void export_vrml_pad( BOARD* pcb, D_PAD* pad ) /*{{{*/ } /* The pad proper, on the selected layers */ - unsigned long layer_mask = pad->m_Masque_Layer; + unsigned long layer_mask = pad->m_layerMask; int copper_layers = pcb->GetCopperLayerCount( ); /* The (maybe offseted) pad position */ wxPoint pad_pos = pad->ReturnShapePos(); @@ -901,6 +909,7 @@ static void export_vrml_pad( BOARD* pcb, D_PAD* pad ) /*{{{*/ double pad_dy = pad_delta.y / 2; double pad_w = pad->m_Size.x / 2; double pad_h = pad->m_Size.y / 2; + for( int layer = FIRST_COPPER_LAYER; layer < copper_layers; layer++ ) { /* The last layer is always the component one, unless it's single face */ @@ -973,6 +982,7 @@ static void build_quat( double x, double y, double z, double a, double q[4] ) static void from_quat( double q[4], double rot[4] ) { rot[3] = acos( q[3] ) * 2; + for( int i = 0; i < 3; i++ ) { rot[i] = q[i] / sin( rot[3] / 2 ); @@ -995,8 +1005,8 @@ static void compose_quat( double q1[4], double q2[4], double qr[4] ) static void export_vrml_module( BOARD* aPcb, MODULE* aModule, - FILE* aOutputFile, double aScalingFactor, - bool aExport3DFiles, const wxString & a3D_Subdir ) + FILE* aOutputFile, double aScalingFactor, + bool aExport3DFiles, const wxString & a3D_Subdir ) { /* Reference and value */ export_vrml_text_module( aModule->m_Reference ); @@ -1021,17 +1031,16 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule, } /* Export pads */ - for( D_PAD* pad = aModule->m_Pads; - pad != 0; - pad = pad->Next() ) + for( D_PAD* pad = aModule->m_Pads; pad != 0; pad = pad->Next() ) export_vrml_pad( aPcb, pad ); bool isFlipped = aModule->GetLayer() == LAYER_N_BACK; + /* Export the object VRML model(s) */ - for( S3D_MASTER* vrmlm = aModule->m_3D_Drawings; - vrmlm != 0; vrmlm = vrmlm->Next() ) + for( S3D_MASTER* vrmlm = aModule->m_3D_Drawings; vrmlm != 0; vrmlm = vrmlm->Next() ) { wxString fname = vrmlm->m_Shape3DName; + if( fname.IsEmpty() ) continue; @@ -1039,16 +1048,19 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule, { wxFileName fn = fname; fname = wxGetApp().FindLibraryPath( fn ); + if( fname.IsEmpty() ) // keep "short" name if full filemane not found fname = vrmlm->m_Shape3DName; } fname.Replace(wxT("\\"), wxT("/" ) ); wxString source_fname = fname; + if( aExport3DFiles ) // Change illegal characters in short filename { ChangeIllegalCharacters( fname, true ); fname = a3D_Subdir + wxT("/") + fname; + if( !wxFileExists( fname ) ) wxCopyFile( source_fname, fname ); } @@ -1061,6 +1073,7 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule, double rotx = - vrmlm->m_MatRotation.x; double roty = - vrmlm->m_MatRotation.y; double rotz = - vrmlm->m_MatRotation.z; + if ( isFlipped ) { rotx += 180.0; @@ -1085,13 +1098,14 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule, /* A null rotation would fail the acos! */ if( rot[3] != 0.0 ) { - fprintf( aOutputFile, " rotation %g %g %g %g\n", - rot[0], rot[1], rot[2], rot[3] ); + fprintf( aOutputFile, " rotation %g %g %g %g\n", rot[0], rot[1], rot[2], rot[3] ); } + fprintf( aOutputFile, " scale %g %g %g\n", vrmlm->m_MatScale.x * aScalingFactor, vrmlm->m_MatScale.y * aScalingFactor, vrmlm->m_MatScale.z * aScalingFactor ); + /* adjust 3D shape offset position (offset is given inch) */ #define UNITS_3D_TO_PCB_UNITS PCB_INTERNAL_UNIT int offsetx = wxRound( vrmlm->m_MatPosition.x * UNITS_3D_TO_PCB_UNITS ); @@ -1110,16 +1124,14 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule, - (double)(offsety + aModule->m_Pos.y), // Y axis is reversed in pcbnew offsetz + layer_z[aModule->GetLayer()] ); fprintf( aOutputFile, - " children [\n Inline {\n url \"%s\"\n } ]\n", - TO_UTF8( fname ) ); + " children [\n Inline {\n url \"%s\"\n } ]\n", + TO_UTF8( fname ) ); fprintf( aOutputFile, " }\n" ); - } } -static void write_and_empty_triangle_bag( FILE* output_file, - TriangleBag& triangles, int color ) +static void write_and_empty_triangle_bag( FILE* output_file, TriangleBag& triangles, int color ) { if( !triangles.empty() ) { @@ -1158,8 +1170,10 @@ wxBusyCursor dummy; wxString fullFilename = dlg.FilePicker()->GetPath(); subDirFor3Dshapes = dlg.GetSubdir(); + if( ! wxDirExists( subDirFor3Dshapes ) ) wxMkdir( subDirFor3Dshapes ); + if( ! ExportVRML_File( fullFilename, scale, export3DFiles, subDirFor3Dshapes ) ) { wxString msg = _( "Unable to create " ) + fullFilename; @@ -1215,12 +1229,13 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName, /* scaling factor to convert internal units (decimils) to inches */ double board_scaling_factor = 0.0001; + /* auxiliary scale to export to a different scale. */ double general_scaling_factor = board_scaling_factor * aScale; - fprintf(output_file, "Transform {\n"); - fprintf(output_file, " scale %g %g %g\n", - general_scaling_factor, general_scaling_factor, general_scaling_factor ); + fprintf( output_file, "Transform {\n" ); + fprintf( output_file, " scale %g %g %g\n", + general_scaling_factor, general_scaling_factor, general_scaling_factor ); /* Define the translation to have the board centre to the 2D axis origin * more easy for rotations... @@ -1228,9 +1243,9 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName, pcb->ComputeBoundingBox(); double dx = board_scaling_factor * pcb->m_BoundaryBox.Centre().x * aScale; double dy = board_scaling_factor * pcb->m_BoundaryBox.Centre().y * aScale; - fprintf(output_file, " translation %g %g 0.0\n", -dx, dy ); + fprintf( output_file, " translation %g %g 0.0\n", -dx, dy ); - fprintf(output_file, " children [\n" ); + fprintf( output_file, " children [\n" ); /* scaling factor to convert 3D models to board units (decimils) * Usually we use Wings3D to create thems. @@ -1238,7 +1253,8 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName, * So the scaling factor from 0.1 inch to board units * is 0.1 / board_scaling_factor */ - double wrml_3D_models_scaling_factor = 0.1 / board_scaling_factor; + + double wrml_3D_models_scaling_factor = 0.1 / board_scaling_factor; /* Preliminary computation: the z value for each layer */ compute_layer_Zs( pcb ); @@ -1253,9 +1269,7 @@ bool PCB_EDIT_FRAME::ExportVRML_File( const wxString & aFullFileName, */ /* Export footprints */ - for( MODULE* module = pcb->m_Modules; - module != 0; - module = module->Next() ) + for( MODULE* module = pcb->m_Modules; module != 0; module = module->Next() ) export_vrml_module( pcb, module, output_file, wrml_3D_models_scaling_factor, aExport3DFiles, a3D_Subdir ); @@ -1291,6 +1305,7 @@ static void ChangeIllegalCharacters( wxString & aFileName, bool aDirSepIsIllegal { if( aDirSepIsIllegal ) aFileName.Replace(wxT("/"), wxT("_" ) ); + aFileName.Replace(wxT(" "), wxT("_" ) ); aFileName.Replace(wxT(":"), wxT("_" ) ); } diff --git a/pcbnew/find.cpp b/pcbnew/find.cpp index 51813cce0a..cc7ced1a55 100644 --- a/pcbnew/find.cpp +++ b/pcbnew/find.cpp @@ -36,7 +36,7 @@ void WinEDA_PcbFindFrame::FindItem( wxCommandEvent& event ) PCB_SCREEN* screen = (PCB_SCREEN*) ( m_Parent->GetScreen() ); wxPoint locate_pos; wxString msg; - bool FindMarker = FALSE; + bool FindMarker = false; BOARD_ITEM* foundItem = 0; switch( event.GetId() ) @@ -51,7 +51,7 @@ void WinEDA_PcbFindFrame::FindItem( wxCommandEvent& event ) // fall thru case ID_FIND_NEXT_MARKER: - FindMarker = TRUE; + FindMarker = true; break; } @@ -63,6 +63,7 @@ void WinEDA_PcbFindFrame::FindItem( wxCommandEvent& event ) if( FindMarker ) { MARKER_PCB* marker = m_Parent->GetBoard()->GetMARKER( s_MarkerCount++ ); + if( marker ) { foundItem = marker; @@ -72,14 +73,13 @@ void WinEDA_PcbFindFrame::FindItem( wxCommandEvent& event ) else { int StartCount = 0; - for( MODULE* module = m_Parent->GetBoard()->m_Modules; - module; - module = module->Next() ) + + for( MODULE* module = m_Parent->GetBoard()->m_Modules; module; module = module->Next() ) { - if( WildCompareString( s_OldStringFound, - module->GetReference().GetData(), FALSE ) ) + if( WildCompareString( s_OldStringFound, module->GetReference().GetData(), false ) ) { StartCount++; + if( StartCount > s_ItemCount ) { foundItem = module; @@ -88,10 +88,11 @@ void WinEDA_PcbFindFrame::FindItem( wxCommandEvent& event ) break; } } - if( WildCompareString( s_OldStringFound, - module->m_Value->m_Text.GetData(), FALSE ) ) + + if( WildCompareString( s_OldStringFound, module->m_Value->m_Text.GetData(), false ) ) { StartCount++; + if( StartCount > s_ItemCount ) { foundItem = module; @@ -201,10 +202,12 @@ bool WinEDA_PcbFindFrame::Create( wxWindow* parent, wxDialog::Create( parent, id, caption, pos, size, style ); CreateControls(); + if( GetSizer() ) { GetSizer()->SetSizeHints( this ); } + Centre(); ////@end WinEDA_PcbFindFrame creation diff --git a/pcbnew/gen_drill_report_files.cpp b/pcbnew/gen_drill_report_files.cpp index f558fe1d1f..4a7dab80aa 100644 --- a/pcbnew/gen_drill_report_files.cpp +++ b/pcbnew/gen_drill_report_files.cpp @@ -119,15 +119,12 @@ void GenDrillMapFile( BOARD* aPcb, FILE* aFile, const wxString& aFullFileName, /* Draw items on edge layer */ - for( PtStruct = aPcb->m_Drawings; - PtStruct != NULL; - PtStruct = PtStruct->Next() ) + for( PtStruct = aPcb->m_Drawings; PtStruct != NULL; PtStruct = PtStruct->Next() ) { switch( PtStruct->Type() ) { case TYPE_DRAWSEGMENT: - PlotDrawSegment( plotter, (DRAWSEGMENT*) PtStruct, EDGE_LAYER, - FILLED ); + PlotDrawSegment( plotter, (DRAWSEGMENT*) PtStruct, EDGE_LAYER, FILLED ); break; case TYPE_TEXTE: @@ -138,8 +135,8 @@ void GenDrillMapFile( BOARD* aPcb, FILE* aFile, const wxString& aFullFileName, PlotDimension( plotter, (DIMENSION*) PtStruct, EDGE_LAYER, FILLED ); break; - case TYPE_MIRE: - PlotMirePcb( plotter, (MIREPCB*) PtStruct, EDGE_LAYER, FILLED ); + case PCB_TARGET_T: + PlotPcbTarget( plotter, (PCB_TARGET*) PtStruct, EDGE_LAYER, FILLED ); break; case TYPE_MARKER_PCB: // do not draw @@ -181,6 +178,7 @@ void GenDrillMapFile( BOARD* aPcb, FILE* aFile, const wxString& aFullFileName, for( unsigned ii = 0; ii < aToolListBuffer.size(); ii++ ) { int plot_diam; + if( aToolListBuffer[ii].m_TotalCount == 0 ) continue; @@ -203,6 +201,7 @@ void GenDrillMapFile( BOARD* aPcb, FILE* aFile, const wxString& aFullFileName, sprintf( line, "%2.2fmm / %2.3f\" ", double (aToolListBuffer[ii].m_Diameter) * 0.00254, double (aToolListBuffer[ii].m_Diameter) * 0.0001 ); + msg = FROM_UTF8( line ); // Now list how many holes and ovals are associated with each drill. @@ -212,16 +211,15 @@ void GenDrillMapFile( BOARD* aPcb, FILE* aFile, const wxString& aFullFileName, else if( aToolListBuffer[ii].m_TotalCount == 1 ) // && ( aToolListBuffer[ii]m_OvalCount == 1 ) sprintf( line, "(1 slot)" ); else if( aToolListBuffer[ii].m_OvalCount == 0 ) - sprintf( line, "(%d holes)", - aToolListBuffer[ii].m_TotalCount ); + sprintf( line, "(%d holes)", aToolListBuffer[ii].m_TotalCount ); else if( aToolListBuffer[ii].m_OvalCount == 1 ) - sprintf( line, "(%d holes + 1 slot)", - aToolListBuffer[ii].m_TotalCount - 1 ); + sprintf( line, "(%d holes + 1 slot)", aToolListBuffer[ii].m_TotalCount - 1 ); else // if ( aToolListBuffer[ii]m_OvalCount > 1 ) sprintf( line, "(%d holes + %d slots)", aToolListBuffer[ii].m_TotalCount - aToolListBuffer[ii].m_OvalCount, aToolListBuffer[ii].m_OvalCount ); + msg += FROM_UTF8( line ); plotter->text( wxPoint( plotX, y ), BLACK, msg, @@ -258,8 +256,7 @@ void Gen_Drill_PcbMap( BOARD* aPcb, PLOTTER* aPlotter, if( aToolListBuffer.size() > 13 ) { DisplayInfoMessage( NULL, - _( - " Drill map: Too many diameter values to draw to draw one symbol per drill value (max 13)\nPlot uses circle shape for some drill values" ), + _( " Drill map: Too many diameter values to draw to draw one symbol per drill value (max 13)\nPlot uses circle shape for some drill values" ), 10 ); } @@ -271,13 +268,14 @@ void Gen_Drill_PcbMap( BOARD* aPcb, PLOTTER* aPlotter, /* Always plot the drill symbol (for slots identifies the needed * cutter!) */ aPlotter->marker( pos, aHoleListBuffer[ii].m_Hole_Diameter, - aHoleListBuffer[ii].m_Tool_Reference - 1 ); + aHoleListBuffer[ii].m_Tool_Reference - 1 ); + if( aHoleListBuffer[ii].m_Hole_Shape != 0 ) { wxSize oblong_size; oblong_size = aHoleListBuffer[ii].m_Hole_Size; aPlotter->flash_pad_oval( pos, oblong_size, - aHoleListBuffer[ii].m_Hole_Orient, FILAIRE ); + aHoleListBuffer[ii].m_Hole_Orient, FILAIRE ); } } } @@ -345,8 +343,8 @@ void GenDrillReportFile( FILE* aFile, BOARD* aPcb, } sprintf( line, "Drill report for holes from layer %s to layer %s\n", - TO_UTF8( aPcb->GetLayerName( layer1 ) ), - TO_UTF8( aPcb->GetLayerName( layer2 ) ) ); + TO_UTF8( aPcb->GetLayerName( layer1 ) ), + TO_UTF8( aPcb->GetLayerName( layer2 ) ) ); } fputs( line, aFile ); @@ -366,6 +364,7 @@ void GenDrillReportFile( FILE* aFile, BOARD* aPcb, ii + 1, double (aToolListBuffer[ii].m_Diameter) * 0.00254, double (aToolListBuffer[ii].m_Diameter) * 0.0001 ); + fputs( line, aFile ); // Now list how many holes and ovals are associated with each drill. @@ -375,15 +374,14 @@ void GenDrillReportFile( FILE* aFile, BOARD* aPcb, else if( aToolListBuffer[ii].m_TotalCount == 1 ) sprintf( line, "(1 hole) (with 1 oblong)\n" ); else if( aToolListBuffer[ii].m_OvalCount == 0 ) - sprintf( line, "(%d holes)\n", - aToolListBuffer[ii].m_TotalCount ); + sprintf( line, "(%d holes)\n", aToolListBuffer[ii].m_TotalCount ); else if( aToolListBuffer[ii].m_OvalCount == 1 ) - sprintf( line, "(%d holes) (with 1 oblong)\n", - aToolListBuffer[ii].m_TotalCount ); + sprintf( line, "(%d holes) (with 1 oblong)\n", aToolListBuffer[ii].m_TotalCount ); else // if ( buffer[ii]m_OvalCount > 1 ) sprintf( line, "(%d holes) (with %d oblongs)\n", aToolListBuffer[ii].m_TotalCount, aToolListBuffer[ii].m_OvalCount ); + fputs( line, aFile ); TotalHoleCount += aToolListBuffer[ii].m_TotalCount; @@ -393,6 +391,7 @@ void GenDrillReportFile( FILE* aFile, BOARD* aPcb, sprintf( line, "\ntotal Not Plated holes count %d\n\n\n", TotalHoleCount ); else sprintf( line, "\ntotal plated holes count %d\n\n\n", TotalHoleCount ); + fputs( line, aFile ); if( gen_NPTH_holes ) @@ -408,7 +407,9 @@ void GenDrillReportFile( FILE* aFile, BOARD* aPcb, } if( gen_through_holes ) + { layer2 = layer1 + 1; + } else { if( layer2 >= LAYER_N_FRONT ) // no more layer pair to consider @@ -416,6 +417,7 @@ void GenDrillReportFile( FILE* aFile, BOARD* aPcb, gen_NPTH_holes = true; continue; } + layer1++; layer2++; // use next layer pair if( layer2 == aPcb->GetCopperLayerCount() - 1 ) diff --git a/pcbnew/gen_modules_placefile.cpp b/pcbnew/gen_modules_placefile.cpp index 901e8aea7f..1cdbdde36a 100644 --- a/pcbnew/gen_modules_placefile.cpp +++ b/pcbnew/gen_modules_placefile.cpp @@ -189,6 +189,7 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event ) Liste = (LIST_MOD*) MyZMalloc( moduleCount * sizeof(LIST_MOD) ); module = GetBoard()->m_Modules; + for( int ii = 0; module; module = module->Next() ) { if( module->m_Attributs & MOD_VIRTUAL ) @@ -206,8 +207,7 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event ) qsort( Liste, moduleCount, sizeof(LIST_MOD), ListeModCmp ); // Write file header - sprintf( line, "### Module positions - created on %s ###\n", - DateAndTime( Buff ) ); + sprintf( line, "### Module positions - created on %s ###\n", DateAndTime( Buff ) ); fputs( line, fpFront ); if( doBoardBack ) @@ -238,6 +238,7 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event ) sprintf( line, "# Ref Val PosX PosY Rot Side\n" ); fputs( line, fpFront ); + if( doBoardBack ) fputs( line, fpBack ); @@ -246,8 +247,7 @@ void PCB_EDIT_FRAME::GenModulesPosition( wxCommandEvent& event ) wxPoint module_pos; wxString ref = Liste[ii].m_Reference; wxString val = Liste[ii].m_Value; - sprintf( line, "%-8.8s %-16.16s ", TO_UTF8( ref ), - TO_UTF8( val ) ); + sprintf( line, "%-8.8s %-16.16s ", TO_UTF8( ref ), TO_UTF8( val ) ); module_pos = Liste[ii].m_Module->m_Pos; module_pos.x -= File_Place_Offset.x; @@ -351,7 +351,7 @@ void PCB_EDIT_FRAME::GenModuleReport( wxCommandEvent& event ) // Switch the locale to standard C (needed to print floating point // numbers like 1.3) - SetLocaleTo_C_standard( ); + SetLocaleTo_C_standard(); /* Generate header file comments.) */ sprintf( line, "## Module report - date %s\n", DateAndTime( Buff ) ); @@ -381,6 +381,7 @@ void PCB_EDIT_FRAME::GenModuleReport( wxCommandEvent& event ) fputs( "$EndBOARD\n\n", rptfile ); Module = (MODULE*) GetBoard()->m_Modules; + for( ; Module != NULL; Module = Module->Next() ) { sprintf( line, "$MODULE %s\n", EscapedUTF8( Module->m_Reference->m_Text ).c_str() ); @@ -394,12 +395,16 @@ void PCB_EDIT_FRAME::GenModuleReport( wxCommandEvent& event ) fputs( line, rptfile ); msg = wxT( "attribut" ); + if( Module->m_Attributs & MOD_VIRTUAL ) msg += wxT( " virtual" ); + if( Module->m_Attributs & MOD_CMS ) msg += wxT( " smd" ); + if( ( Module->m_Attributs & (MOD_VIRTUAL | MOD_CMS) ) == 0 ) msg += wxT( " none" ); + msg += wxT( "\n" ); fputs( TO_UTF8( msg ), rptfile ); @@ -413,12 +418,14 @@ void PCB_EDIT_FRAME::GenModuleReport( wxCommandEvent& event ) fputs( line, rptfile ); sprintf( line, "orientation %.2f\n", (double) Module->m_Orient / 10 ); + if( Module->GetLayer() == LAYER_N_FRONT ) strcat( line, "layer component\n" ); else if( Module->GetLayer() == LAYER_N_BACK ) strcat( line, "layer copper\n" ); else strcat( line, "layer other\n" ); + fputs( line, rptfile ); Module->Write_3D_Descr( rptfile ); @@ -445,16 +452,18 @@ void PCB_EDIT_FRAME::GenModuleReport( wxCommandEvent& event ) sprintf( line, "orientation %.2f\n", double(pad->m_Orient - Module->m_Orient) / 10 ); fputs( line, rptfile ); - const char* shape_name[6] = - { "??? ", "Circ", "Rect", "Oval", "trap", "spec" }; + const char* shape_name[6] = { "??? ", "Circ", "Rect", "Oval", "trap", "spec" }; sprintf( line, "Shape %s\n", shape_name[pad->m_PadShape] ); fputs( line, rptfile ); int layer = 0; - if( pad->m_Masque_Layer & LAYER_BACK ) + + if( pad->m_layerMask & LAYER_BACK ) layer = 1; - if( pad->m_Masque_Layer & LAYER_FRONT ) + + if( pad->m_layerMask & LAYER_FRONT ) layer |= 2; + const char* layer_name[4] = { "??? ", "copper", "component", "all" }; sprintf( line, "Layer %s\n", layer_name[layer] ); fputs( line, rptfile ); @@ -475,6 +484,7 @@ void PCB_EDIT_FRAME::GenModuleReport( wxCommandEvent& event ) if( ( (DRAWSEGMENT*) PtStruct )->GetLayer() != EDGE_N ) continue; + WriteDrawSegmentPcb( (DRAWSEGMENT*) PtStruct, rptfile ); } @@ -499,7 +509,7 @@ void PCB_EDIT_FRAME::GenModuleReport( wxCommandEvent& event ) void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile ) { double conv_unit, ux0, uy0, dx, dy; - double rayon, width; + double radius, width; char line[1024]; conv_unit = 0.0001; /* units = INCHES */ @@ -515,10 +525,10 @@ void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile ) switch( PtDrawSegment->m_Shape ) { case S_CIRCLE: - rayon = hypot( dx - ux0, dy - uy0 ); + radius = hypot( dx - ux0, dy - uy0 ); fprintf( rptfile, "$CIRCLE \n" ); fprintf( rptfile, "centre %.6lf %.6lf\n", ux0, uy0 ); - fprintf( rptfile, "radius %.6lf\n", rayon ); + fprintf( rptfile, "radius %.6lf\n", radius ); fprintf( rptfile, "width %.6lf\n", width ); fprintf( rptfile, "$EndCIRCLE \n" ); break; @@ -526,7 +536,7 @@ void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile ) case S_ARC: { int endx = PtDrawSegment->m_End.x, endy = PtDrawSegment->m_End.y; - rayon = hypot( dx - ux0, dy - uy0 ); + radius = hypot( dx - ux0, dy - uy0 ); RotatePoint( &endx, &endy, PtDrawSegment->m_Start.x, diff --git a/pcbnew/globaleditpad.cpp b/pcbnew/globaleditpad.cpp index 8d8f7e56bd..f11305b46d 100644 --- a/pcbnew/globaleditpad.cpp +++ b/pcbnew/globaleditpad.cpp @@ -121,8 +121,7 @@ void PCB_BASE_FRAME::Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw ) if( Module == NULL ) { - DisplayError( this, - wxT( "Global_Import_Pad_Settings() Error: NULL module" ) ); + DisplayError( this, wxT( "Global_Import_Pad_Settings() Error: NULL module" ) ); return; } @@ -135,6 +134,7 @@ void PCB_BASE_FRAME::Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw ) if( diag == -1 ) return; + if( diag == 1 ) edit_Same_Modules = true; @@ -155,6 +155,7 @@ void PCB_BASE_FRAME::Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw ) bool saveMe = false; D_PAD* pt_pad = (D_PAD*) Module->m_Pads; + for( ; pt_pad != NULL; pt_pad = pt_pad->Next() ) { /* Filters changes prohibited. */ @@ -167,7 +168,7 @@ void PCB_BASE_FRAME::Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw ) continue; if( DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter - && ( pt_pad->m_Masque_Layer != aPad->m_Masque_Layer ) ) + && ( pt_pad->m_layerMask != aPad->m_layerMask ) ) continue; saveMe = true; @@ -185,6 +186,7 @@ void PCB_BASE_FRAME::Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw ) /* Update the current module and same others modules if requested. */ Module = (MODULE*) m_Pcb->m_Modules; + for( ; Module != NULL; Module = Module->Next() ) { if( !edit_Same_Modules && (Module != Module_Ref) ) @@ -202,6 +204,7 @@ void PCB_BASE_FRAME::Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw ) } D_PAD* pt_pad = (D_PAD*) Module->m_Pads; + for( ; pt_pad != NULL; pt_pad = pt_pad->Next() ) { /* Filters changes prohibited. */ @@ -215,18 +218,17 @@ void PCB_BASE_FRAME::Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw ) if( DIALOG_GLOBAL_PADS_EDITION::m_Pad_Layer_Filter ) { - if( pt_pad->m_Masque_Layer != aPad->m_Masque_Layer ) + if( pt_pad->m_layerMask != aPad->m_layerMask ) continue; else - m_Pcb->m_Status_Pcb &= - ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK); + m_Pcb->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK); } /* Change characteristics.: */ pt_pad->m_Attribut = aPad->m_Attribut; pt_pad->m_PadShape = aPad->m_PadShape; - pt_pad->m_Masque_Layer = aPad->m_Masque_Layer; + pt_pad->m_layerMask = aPad->m_layerMask; pt_pad->m_Size = aPad->m_Size; pt_pad->m_DeltaSize = aPad->m_DeltaSize; @@ -269,7 +271,8 @@ void PCB_BASE_FRAME::Global_Import_Pad_Settings( D_PAD* aPad, bool aDraw ) pt_pad->ComputeShapeMaxRadius(); } - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); + if( aDraw ) DrawPanel->RefreshDrawingRect( Module->GetBoundingBox() ); } diff --git a/pcbnew/gpcb_exchange.cpp b/pcbnew/gpcb_exchange.cpp index 2e72ab331e..17b3bb23fd 100644 --- a/pcbnew/gpcb_exchange.cpp +++ b/pcbnew/gpcb_exchange.cpp @@ -17,10 +17,6 @@ static void Extract_Parameters( wxArrayString& param_list, char* text ); static bool TestFlags( const wxString& flg_string, long flg_mask, const wxChar* flg_name ); -/**************************************************************/ -bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) -/**************************************************************/ - /** * Function Read_GPCB_Descr * Read a footprint description in GPCB (Newlib) format @@ -148,6 +144,7 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) * For pads, set to prevent a solderpaste stencil opening for the pad. Primarily * used for pads used as fiducials. */ +bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) { #define TEXT_DEFAULT_SIZE 400 #define OLD_GPCB_UNIT_CONV 10 @@ -187,12 +184,13 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) // Test symbol after "Element": if [ units = 0.01 mils, and if ( units = 1 mil iprmcnt++; + if( params[iprmcnt] == wxT( "(" ) ) conv_unit = OLD_GPCB_UNIT_CONV; /* Analyse first line : * Element [element_flags, description, pcb-name, value, mark_x, mark_y, text_x, text_y, - * text_direction, text_scale, text_flags] + * text_direction, text_scale, text_flags] */ // Read flags (unused) @@ -212,6 +210,7 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) // Read other infos iprmcnt++; + for( int ii = 0; ii < 6; ii++ ) { if( iprmcnt < icnt_max ) @@ -220,7 +219,10 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) ibuf[ii] = 0; } else + { params[iprmcnt].ToLong( &ibuf[ii] ); + } + iprmcnt++; } @@ -267,6 +269,7 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) for( unsigned ii = 0; ii < 5; ii++ ) { long dim; + if( ii < (params.GetCount() - 2) ) { if( params[ii + 2].ToLong( &dim ) ) @@ -301,7 +304,7 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) ibuf[ii] = 0; } - int rayon = (ibuf[2] + ibuf[3]) / 4; // for and arc: ibuf[3] = ibuf[4]. pcbnew does not know ellipses + int radius = (ibuf[2] + ibuf[3]) / 4; // for and arc: ibuf[3] = ibuf[4]. pcbnew does not know ellipses wxPoint centre; centre.x = wxRound( ibuf[0] * conv_unit ); centre.y = wxRound( ibuf[1] * conv_unit ); @@ -309,9 +312,9 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) int start_angle = ibuf[4] * 10; // Pcbnew uses 0.1 degrees as units start_angle -= 1800; // Use normal X axis as reference DrawSegm->m_Angle = ibuf[5] * 10; // Angle value is clockwise in gpcb and pcbnew - DrawSegm->m_End0.x = wxRound( rayon * conv_unit ); + DrawSegm->m_End0.x = wxRound( radius * conv_unit ); DrawSegm->m_End0.y = 0; - RotatePoint( &DrawSegm->m_End0, -start_angle ); // Calculate start point coordinate of arc + RotatePoint( &DrawSegm->m_End0, -start_angle );// Calculate start point coordinate of arc DrawSegm->m_End0 += centre; DrawSegm->m_Width = wxRound( ibuf[6] * conv_unit ); @@ -323,23 +326,27 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) { // format: Pad [x1 y1 x2 y2 thickness clearance mask "name" "pad_number" flags] Pad = new D_PAD( this ); Pad->m_PadShape = PAD_RECT; - Pad->m_Masque_Layer = LAYER_FRONT | SOLDERMASK_LAYER_FRONT | SOLDERPASTE_LAYER_FRONT; + Pad->m_layerMask = LAYER_FRONT | SOLDERMASK_LAYER_FRONT | SOLDERPASTE_LAYER_FRONT; // Set shape from flags iflgidx = params.GetCount() - 2; + if( TestFlags( params[iflgidx], 0x0080, wxT( "onsolder" ) ) ) - Pad->m_Masque_Layer = LAYER_BACK | SOLDERMASK_LAYER_BACK | SOLDERPASTE_LAYER_BACK; + Pad->m_layerMask = LAYER_BACK | SOLDERMASK_LAYER_BACK | SOLDERPASTE_LAYER_BACK; for( unsigned ii = 0; ii < 5; ii++ ) { if( ii < params.GetCount() - 2 ) { long dim; + if( params[ii + 2].ToLong( &dim ) ) ibuf[ii] = wxRound( dim * conv_unit ); } else + { ibuf[ii] = 0; + } } // Read name: @@ -356,6 +363,7 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) Pad->m_Size.y = ibuf[4] + abs( ibuf[1] - ibuf[3] ); Pad->m_Pos.x += m_Pos.x; Pad->m_Pos.y += m_Pos.y; + if( !TestFlags( params[iflgidx], 0x0100, wxT( "square" ) ) ) { if( Pad->m_Size.x == Pad->m_Size.y ) @@ -372,7 +380,7 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) { // format: Pin[x y Thickness Clearance Mask DrillHole Name Number Flags] Pad = new D_PAD( this ); Pad->m_PadShape = PAD_ROUND; - Pad->m_Masque_Layer = ALL_CU_LAYERS | + Pad->m_layerMask = ALL_CU_LAYERS | SILKSCREEN_LAYER_FRONT | SOLDERMASK_LAYER_FRONT | SOLDERMASK_LAYER_BACK; @@ -390,7 +398,9 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) ibuf[ii] = wxRound( dim * conv_unit ); } else + { ibuf[ii] = 0; + } } // Read name: @@ -401,12 +411,14 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) { strncpy( Pad->m_Padname, TO_UTF8( params[9] ), 4 ); } + Pad->m_Pos.x = ibuf[0]; Pad->m_Pos.y = ibuf[1]; Pad->m_Drill.x = Pad->m_Drill.y = ibuf[5]; Pad->m_Size.x = Pad->m_Size.y = ibuf[3] + Pad->m_Drill.x; Pad->m_Pos.x += m_Pos.x; Pad->m_Pos.y += m_Pos.y; + if( (Pad->m_PadShape == PAD_ROUND) && (Pad->m_Size.x != Pad->m_Size.y) ) Pad->m_PadShape = PAD_OVAL; @@ -417,6 +429,7 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) if( m_Value->m_Text.IsEmpty() ) m_Value->m_Text = wxT( "Val**" ); + if( m_Reference->m_Text.IsEmpty() ) { wxFileName filename( CmpFullFileName ); @@ -424,15 +437,11 @@ bool MODULE::Read_GPCB_Descr( const wxString& CmpFullFileName ) } /* Recalculate the bounding box */ - Set_Rectangle_Encadrement(); + CalculateBoundingBox(); return success; } -/***********************************************************************/ -static void Extract_Parameters( wxArrayString& param_list, char* text ) -/***********************************************************************/ - /* Read a text line and extract params and tokens. * special chars are: * [ ] ( ) Begin and end of parameter list and units indicator @@ -443,8 +452,9 @@ static void Extract_Parameters( wxArrayString& param_list, char* text ) * other are parameters (number or delimited string) * last parameter is ) or ] */ +static void Extract_Parameters( wxArrayString& param_list, char* text ) { - char key; + char key; wxString tmp; while( *text != 0 ) @@ -484,6 +494,7 @@ static void Extract_Parameters( wxArrayString& param_list, char* text ) { key = *text; text++; + if( key == '"' ) { param_list.Add( tmp ); @@ -491,7 +502,9 @@ static void Extract_Parameters( wxArrayString& param_list, char* text ) break; } else + { tmp.Append( key ); + } } break; @@ -504,10 +517,6 @@ static void Extract_Parameters( wxArrayString& param_list, char* text ) } -/***********************************************************************************/ -bool TestFlags( const wxString& flg_string, long flg_mask, const wxChar* flg_name ) -/***********************************************************************************/ - /** * Function TestFlags * Test flag flg_mask or flg_name. @@ -518,19 +527,23 @@ bool TestFlags( const wxString& flg_string, long flg_mask, const wxChar* flg_nam * @param flg_name = flag name to find in list * @return true if found */ +bool TestFlags( const wxString& flg_string, long flg_mask, const wxChar* flg_name ) { wxString strnumber; - if( flg_string.StartsWith( wxT( "0x" ), - &strnumber ) || flg_string.StartsWith( wxT( "0X" ), &strnumber ) ) + if( flg_string.StartsWith( wxT( "0x" ), &strnumber ) + || flg_string.StartsWith( wxT( "0X" ), &strnumber ) ) { long lflags; + if( strnumber.ToLong( &lflags, 16 ) ) if( lflags & flg_mask ) return true; } else if( flg_string.Contains( flg_name ) ) + { return true; + } return false; } diff --git a/pcbnew/graphpcb.cpp b/pcbnew/graphpcb.cpp index a57bde3a6c..c81c8ad8da 100644 --- a/pcbnew/graphpcb.cpp +++ b/pcbnew/graphpcb.cpp @@ -41,7 +41,7 @@ static void TraceFilledCercle( BOARD* Pcb, int cx, int cy, int radius, - int masque_layer, + int aLayerMask, int color, int op_logique ); static void TraceCercle( int ux0, int uy0, int ux1, int uy1, int lg, int layer, @@ -102,7 +102,7 @@ void Place_1_Pad_Board( BOARD* Pcb, if( pt_pad->m_PadShape == PAD_CIRCLE ) { TraceFilledCercle( Pcb, shape_pos.x, shape_pos.y, dx, - pt_pad->m_Masque_Layer, color, op_logique ); + pt_pad->m_layerMask, color, op_logique ); return; } @@ -126,14 +126,14 @@ void Place_1_Pad_Board( BOARD* Pcb, TraceFilledRectangle( Pcb, shape_pos.x - dx, shape_pos.y - dy, shape_pos.x + dx, shape_pos.y + dy, - pt_pad->m_Masque_Layer, color, op_logique ); + pt_pad->m_layerMask, color, op_logique ); } else { TraceFilledRectangle( Pcb, shape_pos.x - dx, shape_pos.y - dy, shape_pos.x + dx, shape_pos.y + dy, (int) pt_pad->m_Orient, - pt_pad->m_Masque_Layer, color, op_logique ); + pt_pad->m_layerMask, color, op_logique ); } } @@ -142,7 +142,7 @@ void Place_1_Pad_Board( BOARD* Pcb, * circle center cx, cy. * Parameters: * radius: a value add to the radius or half the score pad - * masque_layer: layer occupied + * aLayerMask: layer occupied * color: mask write in cells * op_logique: type of writing in the cell (WRITE, OR) */ @@ -150,7 +150,7 @@ void TraceFilledCercle( BOARD* Pcb, int cx, int cy, int radius, - int masque_layer, + int aLayerMask, int color, int op_logique ) { @@ -169,10 +169,10 @@ void TraceFilledCercle( BOARD* Pcb, /* Single routing layer on bitmap and BOTTOM * Route_Layer_B = Route_Layer_A */ - if( masque_layer & g_TabOneLayerMask[Route_Layer_BOTTOM] ) + if( aLayerMask & g_TabOneLayerMask[Route_Layer_BOTTOM] ) trace = 1; /* Trace on BOTTOM */ - if( masque_layer & g_TabOneLayerMask[Route_Layer_TOP] ) + if( aLayerMask & g_TabOneLayerMask[Route_Layer_TOP] ) if( Nb_Sides ) trace |= 2; /* Trace on TOP */ @@ -528,7 +528,7 @@ void TraceLignePcb( int x0, * Contact PCBs. */ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, - int masque_layer, int color, int op_logique ) + int aLayerMask, int color, int op_logique ) { int row, col; int row_min, row_max, col_min, col_max; @@ -536,10 +536,10 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, void (* WriteCell)( int, int, int, MATRIX_CELL ); - if( masque_layer & g_TabOneLayerMask[Route_Layer_BOTTOM] ) + if( aLayerMask & g_TabOneLayerMask[Route_Layer_BOTTOM] ) trace = 1; /* Trace on BOTTOM */ - if( ( masque_layer & g_TabOneLayerMask[Route_Layer_TOP] ) && Nb_Sides ) + if( ( aLayerMask & g_TabOneLayerMask[Route_Layer_TOP] ) && Nb_Sides ) trace |= 2; /* Trace on TOP */ if( trace == 0 ) @@ -615,7 +615,7 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, * contact PCBs. */ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, - int angle, int masque_layer, int color, + int angle, int aLayerMask, int color, int op_logique ) { int row, col; @@ -627,10 +627,10 @@ void TraceFilledRectangle( BOARD* Pcb, int ux0, int uy0, int ux1, int uy1, void (* WriteCell)( int, int, int, MATRIX_CELL ); - if( masque_layer & g_TabOneLayerMask[Route_Layer_BOTTOM] ) + if( aLayerMask & g_TabOneLayerMask[Route_Layer_BOTTOM] ) trace = 1; /* Trace on BOTTOM */ - if( masque_layer & g_TabOneLayerMask[Route_Layer_TOP] ) + if( aLayerMask & g_TabOneLayerMask[Route_Layer_TOP] ) if( Nb_Sides ) trace |= 2; /* Trace on TOP */ diff --git a/pcbnew/hotkeys_board_editor.cpp b/pcbnew/hotkeys_board_editor.cpp index 95edfb757c..0e1cb56875 100644 --- a/pcbnew/hotkeys_board_editor.cpp +++ b/pcbnew/hotkeys_board_editor.cpp @@ -663,7 +663,7 @@ bool PCB_EDIT_FRAME::OnHotkeyEditItem( int aIdCommand ) evt_type = ID_POPUP_PCB_EDIT_MODULE; break; - case TYPE_MIRE: + case PCB_TARGET_T: if( aIdCommand == HK_EDIT_ITEM ) evt_type = ID_POPUP_PCB_EDIT_MIRE; break; @@ -757,8 +757,10 @@ bool PCB_EDIT_FRAME::OnHotkeyMoveItem( int aIdCommand ) // the parent. if( aIdCommand == HK_MOVE_ITEM ) evt_type = ID_POPUP_PCB_MOVE_MODULE_REQUEST; + if( aIdCommand == HK_DRAG_ITEM ) evt_type = ID_POPUP_PCB_DRAG_MODULE_REQUEST; + break; case TYPE_TEXTE: @@ -766,7 +768,7 @@ bool PCB_EDIT_FRAME::OnHotkeyMoveItem( int aIdCommand ) evt_type = ID_POPUP_PCB_MOVE_TEXTEPCB_REQUEST; break; - case TYPE_MIRE: + case PCB_TARGET_T: if( aIdCommand == HK_MOVE_ITEM ) evt_type = ID_POPUP_PCB_MOVE_MIRE_REQUEST; break; @@ -849,8 +851,8 @@ bool PCB_EDIT_FRAME::OnHotkeyPlaceItem( wxDC* aDC ) Place_Module( (MODULE*) item, aDC ); break; - case TYPE_MIRE: - Place_Mire( (MIREPCB*) item, aDC ); + case PCB_TARGET_T: + PlaceTarget( (PCB_TARGET*) item, aDC ); break; case TYPE_DRAWSEGMENT: diff --git a/pcbnew/initpcb.cpp b/pcbnew/initpcb.cpp index 888b2e174f..bd8a724920 100644 --- a/pcbnew/initpcb.cpp +++ b/pcbnew/initpcb.cpp @@ -22,7 +22,7 @@ bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery ) { if( GetBoard() == NULL ) - return FALSE; + return false; if( aQuery ) { @@ -30,8 +30,8 @@ bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery ) || GetBoard()->m_Track || GetBoard()->m_Zone ) { if( !IsOK( this, - _( "Current Board will be lost and this operation cannot be undone. Continue ?" ) ) ) - return FALSE; + _( "Current Board will be lost and this operation cannot be undone. Continue ?" ) ) ) + return false; } } @@ -74,15 +74,15 @@ bool PCB_EDIT_FRAME::Clear_Pcb( bool aQuery ) bool FOOTPRINT_EDIT_FRAME::Clear_Pcb( bool aQuery ) { if( GetBoard() == NULL ) - return FALSE; + return false; if( aQuery && GetScreen()->IsModify() ) { if( GetBoard()->m_Modules ) { if( !IsOK( this, - _( "Current Footprint will be lost and this operation cannot be undone. Continue ?" ) ) ) - return FALSE; + _( "Current Footprint will be lost and this operation cannot be undone. Continue ?" ) ) ) + return false; } } diff --git a/pcbnew/ioascii.cpp b/pcbnew/ioascii.cpp index 31d47e82a5..be508a6d6d 100644 --- a/pcbnew/ioascii.cpp +++ b/pcbnew/ioascii.cpp @@ -149,8 +149,7 @@ int PCB_BASE_FRAME::ReadListeSegmentDescr( LINE_READER* aReader, case TYPE_ZONE: // this is now deprecated, but exits in old boards newTrack = new SEGZONE( GetBoard() ); - GetBoard()->m_Zone.Insert( (SEGZONE*) newTrack, - (SEGZONE*) insertBeforeMe ); + GetBoard()->m_Zone.Insert( (SEGZONE*) newTrack, (SEGZONE*) insertBeforeMe ); break; } @@ -174,8 +173,7 @@ int PCB_BASE_FRAME::ReadListeSegmentDescr( LINE_READER* aReader, if( makeType == TYPE_VIA ) // Ensure layers are OK when possible: { if( newTrack->Shape() == VIA_THROUGH ) - ( (SEGVIA*) newTrack )->SetLayerPair( LAYER_N_FRONT, - LAYER_N_BACK ); + ( (SEGVIA*) newTrack )->SetLayerPair( LAYER_N_FRONT, LAYER_N_BACK ); } newTrack->SetNet( net_code ); @@ -195,6 +193,7 @@ int PCB_BASE_FRAME::ReadGeneralDescrPcb( LINE_READER* aReader ) { Line = aReader->Line(); data = strtok( Line, " =\n\r" ); + if( strnicmp( data, "$EndGENERAL", 10 ) == 0 ) break; @@ -218,10 +217,12 @@ int PCB_BASE_FRAME::ReadGeneralDescrPcb( LINE_READER* aReader ) // Setup layer count int layer_count = 0; + for( ii = 0; ii < NB_COPPER_LAYERS; ii++ ) { if( Masque_Layer & 1 ) layer_count++; + Masque_Layer >>= 1; } @@ -229,6 +230,7 @@ int PCB_BASE_FRAME::ReadGeneralDescrPcb( LINE_READER* aReader ) continue; } + if( stricmp( data, "BoardThickness" ) == 0 ) { data = strtok( NULL, " =\n\r" ); @@ -257,11 +259,9 @@ int PCB_BASE_FRAME::ReadGeneralDescrPcb( LINE_READER* aReader ) data = strtok( NULL, " =\n\r" ); GetBoard()->m_BoundaryBox.SetY( atoi( data ) ); data = strtok( NULL, " =\n\r" ); - GetBoard()->m_BoundaryBox.SetWidth( - atoi( data ) - GetBoard()->m_BoundaryBox.GetX() ); + GetBoard()->m_BoundaryBox.SetWidth( atoi( data ) - GetBoard()->m_BoundaryBox.GetX() ); data = strtok( NULL, " =\n\r" ); - GetBoard()->m_BoundaryBox.SetHeight( - atoi( data ) - GetBoard()->m_BoundaryBox.GetY() ); + GetBoard()->m_BoundaryBox.SetHeight( atoi( data ) - GetBoard()->m_BoundaryBox.GetY() ); continue; } @@ -367,8 +367,10 @@ int PCB_BASE_FRAME::ReadSetup( LINE_READER* aReader ) int gx = 0, gy = 0; gx = atoi( data ); data = strtok( NULL, " =\n\r" ); + if( data ) gy = atoi( data ); + m_Auxiliary_Axis_Position.x = gx; m_Auxiliary_Axis_Position.y = gy; continue; @@ -398,12 +400,14 @@ int PCB_BASE_FRAME::ReadSetup( LINE_READER* aReader ) GetBoard()->SetLayerName( layer, layerName ); data = strtok( NULL, " \n\r" ); + if( data ) { LAYER_T type = LAYER::ParseType( data ); GetBoard()->SetLayerType( layer, type ); } } + continue; } @@ -477,11 +481,13 @@ int PCB_BASE_FRAME::ReadSetup( LINE_READER* aReader ) VIA_DIMENSION via_dim; via_dim.m_Diameter = tmp; data = strtok( NULL, " \n\r" ); + if( data ) { tmp = atoi( data ); via_dim.m_Drill = tmp > 0 ? tmp : 0; } + GetBoard()->m_ViasDimensionsList.push_back( via_dim ); continue; } @@ -567,16 +573,19 @@ int PCB_BASE_FRAME::ReadSetup( LINE_READER* aReader ) g_Pad_Master.m_Drill.y = g_Pad_Master.m_Drill.x; continue; } + if( stricmp( Line, "Pad2MaskClearance" ) == 0 ) { GetBoard()->GetBoardDesignSettings()->m_SolderMaskMargin = atoi( data ); continue; } + if( stricmp( Line, "Pad2PasteClearance" ) == 0 ) { GetBoard()->GetBoardDesignSettings()->m_SolderPasteMargin = atoi( data ); continue; } + if( stricmp( Line, "Pad2PasteClearanceRatio" ) == 0 ) { GetBoard()->GetBoardDesignSettings()->m_SolderPasteMarginRatio = atof( data ); @@ -606,30 +615,23 @@ int PCB_BASE_FRAME::ReadSetup( LINE_READER* aReader ) * Sort lists by by increasing value and remove duplicates * (the first value is not tested, because it is the netclass value */ - sort( GetBoard()->m_ViasDimensionsList.begin() + 1, - GetBoard()->m_ViasDimensionsList.end() ); - sort( GetBoard()->m_TrackWidthList.begin() + 1, - GetBoard()->m_TrackWidthList.end() ); - for( unsigned ii = 1; - ii < GetBoard()->m_ViasDimensionsList.size() - 1; - ii++ ) + sort( GetBoard()->m_ViasDimensionsList.begin() + 1, GetBoard()->m_ViasDimensionsList.end() ); + sort( GetBoard()->m_TrackWidthList.begin() + 1, GetBoard()->m_TrackWidthList.end() ); + + for( unsigned ii = 1; ii < GetBoard()->m_ViasDimensionsList.size() - 1; ii++ ) { - if( GetBoard()->m_ViasDimensionsList[ii] - == GetBoard()->m_ViasDimensionsList[ii + 1] ) + if( GetBoard()->m_ViasDimensionsList[ii] == GetBoard()->m_ViasDimensionsList[ii + 1] ) { - GetBoard()->m_ViasDimensionsList.erase( - GetBoard()->m_ViasDimensionsList.begin() + ii ); + GetBoard()->m_ViasDimensionsList.erase( GetBoard()->m_ViasDimensionsList.begin() + ii ); ii--; } } for( unsigned ii = 1; ii < GetBoard()->m_TrackWidthList.size() - 1; ii++ ) { - if( GetBoard()->m_TrackWidthList[ii] - == GetBoard()->m_TrackWidthList[ii + 1] ) + if( GetBoard()->m_TrackWidthList[ii] == GetBoard()->m_TrackWidthList[ii + 1] ) { - GetBoard()->m_TrackWidthList.erase( - GetBoard()->m_TrackWidthList.begin() + ii ); + GetBoard()->m_TrackWidthList.erase( GetBoard()->m_TrackWidthList.begin() + ii ); ii--; } } @@ -650,8 +652,7 @@ static int WriteSetup( FILE* aFile, PCB_BASE_FRAME* aFrame, BOARD* aBoard ) fprintf( aFile, "Layers %d\n", aBoard->GetCopperLayerCount() ); - unsigned layerMask = - g_TabAllCopperLayerMask[aBoard->GetCopperLayerCount() - 1]; + unsigned layerMask = g_TabAllCopperLayerMask[aBoard->GetCopperLayerCount() - 1]; for( int layer = 0; layerMask; ++layer, layerMask >>= 1 ) { @@ -663,27 +664,22 @@ static int WriteSetup( FILE* aFile, PCB_BASE_FRAME* aFrame, BOARD* aBoard ) } } - // Save current default track width, for compatibility with older - // pcbnew version; + // Save current default track width, for compatibility with older pcbnew version; fprintf( aFile, "TrackWidth %d\n", aBoard->GetCurrentTrackWidth() ); - // Save custom tracks width list (the first is not saved here: this is the - // netclass value + // Save custom tracks width list (the first is not saved here: this is the netclass value for( unsigned ii = 1; ii < aBoard->m_TrackWidthList.size(); ii++ ) fprintf( aFile, "TrackWidthList %d\n", aBoard->m_TrackWidthList[ii] ); fprintf( aFile, "TrackClearence %d\n", netclass_default->GetClearance() ); - fprintf( aFile, - "ZoneClearence %d\n", - g_Zone_Default_Setting.m_ZoneClearance ); + fprintf( aFile, "ZoneClearence %d\n", g_Zone_Default_Setting.m_ZoneClearance ); fprintf( aFile, "TrackMinWidth %d\n", aBoard->GetBoardDesignSettings()->m_TrackMinWidth ); fprintf( aFile, "DrawSegmWidth %d\n", aBoard->GetBoardDesignSettings()->m_DrawSegmentWidth ); fprintf( aFile, "EdgeSegmWidth %d\n", aBoard->GetBoardDesignSettings()->m_EdgeSegmentWidth ); - // Save current default via size, for compatibility with older pcbnew - // version; + // Save current default via size, for compatibility with older pcbnew version; fprintf( aFile, "ViaSize %d\n", netclass_default->GetViaDiameter() ); fprintf( aFile, "ViaDrill %d\n", netclass_default->GetViaDrill() ); fprintf( aFile, "ViaMinSize %d\n", aBoard->GetBoardDesignSettings()->m_ViasMinSize ); @@ -718,18 +714,17 @@ static int WriteSetup( FILE* aFile, PCB_BASE_FRAME* aFrame, BOARD* aBoard ) fprintf( aFile, "EdgeModWidth %d\n", g_ModuleSegmentWidth ); fprintf( aFile, "TextModSize %d %d\n", g_ModuleTextSize.x, g_ModuleTextSize.y ); fprintf( aFile, "TextModWidth %d\n", g_ModuleTextWidth ); - fprintf( aFile, - "PadSize %d %d\n", - g_Pad_Master.m_Size.x, - g_Pad_Master.m_Size.y ); + fprintf( aFile, "PadSize %d %d\n", g_Pad_Master.m_Size.x, g_Pad_Master.m_Size.y ); fprintf( aFile, "PadDrill %d\n", g_Pad_Master.m_Drill.x ); fprintf( aFile, "Pad2MaskClearance %d\n", aBoard->GetBoardDesignSettings()->m_SolderMaskMargin ); + if( aBoard->GetBoardDesignSettings()->m_SolderPasteMargin != 0 ) fprintf( aFile, "Pad2PasteClearance %d\n", aBoard->GetBoardDesignSettings()->m_SolderPasteMargin ); + if( aBoard->GetBoardDesignSettings()->m_SolderPasteMarginRatio != 0 ) fprintf( aFile, "Pad2PasteClearanceRatio %g\n", @@ -756,7 +751,6 @@ static int WriteSetup( FILE* aFile, PCB_BASE_FRAME* aFrame, BOARD* aBoard ) record.Replace( wxT("\n"), wxT(""), true ); record.Replace( wxT(" "), wxT(" "), true); fprintf( aFile, "PcbPlotParams %s\n", TO_UTF8( record ) ); - fprintf( aFile, "$EndSETUP\n\n" ); return 1; } @@ -799,20 +793,18 @@ bool PCB_EDIT_FRAME::WriteGeneralDescrPcb( FILE* File ) NbModules++; PtStruct = GetBoard()->m_Drawings; NbDrawItem = 0; + for( ; PtStruct != NULL; PtStruct = PtStruct->Next() ) NbDrawItem++; fprintf( File, "Ndraw %d\n", NbDrawItem ); fprintf( File, "Ntrack %d\n", GetBoard()->GetNumSegmTrack() ); fprintf( File, "Nzone %d\n", GetBoard()->GetNumSegmZone() ); - fprintf( File, "BoardThickness %d\n", - GetBoard()->GetBoardDesignSettings()->m_BoardThickness ); - + fprintf( File, "BoardThickness %d\n", GetBoard()->GetBoardDesignSettings()->m_BoardThickness ); fprintf( File, "Nmodule %d\n", NbModules ); fprintf( File, "Nnets %d\n", GetBoard()->m_NetInfo->GetCount() ); - fprintf( File, "$EndGENERAL\n\n" ); - return TRUE; + return true; } @@ -839,7 +831,7 @@ bool WriteSheetDescr( BASE_SCREEN* screen, FILE* File ) fprintf( File, "Comment4 %s\n", EscapedUTF8( screen->m_Commentaire4 ).c_str() ); fprintf( File, "$EndSHEETDESCR\n\n" ); - return TRUE; + return true; } @@ -850,8 +842,9 @@ static bool ReadSheetDescr( BASE_SCREEN* screen, LINE_READER* aReader ) while( aReader->ReadLine() ) { Line = aReader->Line(); + if( strnicmp( Line, "$End", 4 ) == 0 ) - return TRUE; + return true; if( strnicmp( Line, "Sheet", 4 ) == 0 ) { @@ -859,20 +852,26 @@ static bool ReadSheetDescr( BASE_SCREEN* screen, LINE_READER* aReader ) text = strtok( NULL, " \t\n\r" ); Ki_PageDescr* sheet = g_SheetSizeList[0]; int ii; + for( ii = 0; sheet != NULL; ii++, sheet = g_SheetSizeList[ii] ) { if( stricmp( TO_UTF8( sheet->m_Name ), text ) == 0 ) { screen->m_CurrentSheetDesc = sheet; + if( sheet == &g_Sheet_user ) { text = strtok( NULL, " \t\n\r" ); + if( text ) sheet->m_Size.x = atoi( text ); + text = strtok( NULL, " \t\n\r" ); + if( text ) sheet->m_Size.y = atoi( text ); } + break; } } @@ -937,7 +936,7 @@ static bool ReadSheetDescr( BASE_SCREEN* screen, LINE_READER* aReader ) } } - return FALSE; + return false; } @@ -1008,8 +1007,7 @@ int PCB_EDIT_FRAME::ReadPcbFile( LINE_READER* aReader, bool Append ) { #ifdef PCBNEW TRACK* insertBeforeMe = Append ? NULL : board->m_Track.GetFirst(); - ReadListeSegmentDescr( aReader, insertBeforeMe, TYPE_TRACK, - NbTrack ); + ReadListeSegmentDescr( aReader, insertBeforeMe, TYPE_TRACK, NbTrack ); #endif continue; } @@ -1054,9 +1052,9 @@ int PCB_EDIT_FRAME::ReadPcbFile( LINE_READER* aReader, bool Append ) continue; } - if( TESTLINE( "MIREPCB" ) ) + if( TESTLINE( "PCB_TARGET" ) ) { - MIREPCB* Mire = new MIREPCB( board ); + PCB_TARGET* Mire = new PCB_TARGET( board ); board->Add( Mire, ADD_APPEND ); Mire->ReadMirePcbDescr( aReader ); continue; @@ -1067,8 +1065,7 @@ int PCB_EDIT_FRAME::ReadPcbFile( LINE_READER* aReader, bool Append ) #ifdef PCBNEW SEGZONE* insertBeforeMe = Append ? NULL : board->m_Zone.GetFirst(); - ReadListeSegmentDescr( aReader, insertBeforeMe, TYPE_ZONE, - NbZone ); + ReadListeSegmentDescr( aReader, insertBeforeMe, TYPE_ZONE, NbZone ); #endif continue; } @@ -1093,12 +1090,15 @@ int PCB_EDIT_FRAME::ReadPcbFile( LINE_READER* aReader, bool Append ) } else { - while( aReader->ReadLine() ) { + while( aReader->ReadLine() ) + { Line = aReader->Line(); + if( TESTLINE( "EndSETUP" ) ) break; } } + continue; } @@ -1144,8 +1144,7 @@ int PCB_EDIT_FRAME::SavePcbFormatAscii( FILE* aFile ) /* Writing file header. */ fprintf( aFile, "PCBNEW-BOARD Version %d date %s\n\n", g_CurrentVersionPCB, DateAndTime( line ) ); - fprintf( aFile, "# Created by Pcbnew%s\n\n", - TO_UTF8( GetBuildVersion() ) ); + fprintf( aFile, "# Created by Pcbnew%s\n\n", TO_UTF8( GetBuildVersion() ) ); GetBoard()->SynchronizeNetsAndNetClasses(); diff --git a/pcbnew/locate.cpp b/pcbnew/locate.cpp index 0359c19f1c..a7cb4bb2c5 100644 --- a/pcbnew/locate.cpp +++ b/pcbnew/locate.cpp @@ -76,32 +76,32 @@ TRACK* Locate_Via_Area( TRACK* aStart, const wxPoint& pos, int layer ) /* Locate the pad CONNECTED to a track - * input: ptr_piste: pointer to the segment of track + * input: ptr_trace: pointer to the segment of track * Extr = flag = START -> beginning of the test segment * END -> end of the segment to be tested * Returns: * A pointer to the description of the pad if found. * NULL pointer if pad NOT FOUND */ -D_PAD* Locate_Pad_Connecte( BOARD* Pcb, TRACK* ptr_piste, int extr ) +D_PAD* Locate_Pad_Connecte( BOARD* Pcb, TRACK* ptr_trace, int extr ) { D_PAD* ptr_pad = NULL; wxPoint ref_pos; - int masque_layer = g_TabOneLayerMask[ptr_piste->GetLayer()]; + int aLayerMask = g_TabOneLayerMask[ptr_trace->GetLayer()]; if( extr == START ) { - ref_pos = ptr_piste->m_Start; + ref_pos = ptr_trace->m_Start; } else { - ref_pos = ptr_piste->m_End; + ref_pos = ptr_trace->m_End; } for( MODULE* module = Pcb->m_Modules; module; module = module->Next() ) { - ptr_pad = Locate_Pads( module, ref_pos, masque_layer ); + ptr_pad = Locate_Pads( module, ref_pos, aLayerMask ); if( ptr_pad != NULL ) break; @@ -140,12 +140,12 @@ D_PAD* Locate_Any_Pad( BOARD* Pcb, const wxPoint& ref_pos, int aLayerMask ) * Returns: * A pointer to the pad if found or NULL */ -D_PAD* Locate_Pads( MODULE* module, const wxPoint& ref_pos, int masque_layer ) +D_PAD* Locate_Pads( MODULE* module, const wxPoint& ref_pos, int aLayerMask ) { for( D_PAD* pt_pad = module->m_Pads; pt_pad; pt_pad = pt_pad->Next() ) { /* ... and on the correct layer. */ - if( ( pt_pad->m_Masque_Layer & masque_layer ) == 0 ) + if( ( pt_pad->m_layerMask & aLayerMask ) == 0 ) continue; if( pt_pad->HitTest( ref_pos ) ) @@ -274,7 +274,8 @@ int dist; } -/** Search for the track (or via) segment which is connected to the track +/** + * Search for the track (or via) segment which is connected to the track * segment PtRefSegm * if extr == START, the starting track segment PtRefSegm is used to locate * a connected segment @@ -294,7 +295,7 @@ int dist; * @param pt_lim = upper limit for search (can be NULL) * @param extr = START or END = end of ref track segment to use in tests */ -TRACK* Locate_Piste_Connectee( TRACK* PtRefSegm, TRACK* pt_base, TRACK* pt_lim, int extr ) +TRACK* GetConnectedTrace( TRACK* PtRefSegm, TRACK* pt_base, TRACK* pt_lim, int extr ) { const int NEIGHTBOUR_COUNT_MAX = 50; @@ -389,6 +390,7 @@ suite1: continue; } + if( PtSegmN == PtRefSegm ) { if( PtSegmN == pt_lim ) @@ -410,6 +412,7 @@ suite1: if( Reflayer & PtSegmN->ReturnMaskLayer() ) return PtSegmN; } + if( PtSegmN == pt_lim ) break; } @@ -425,7 +428,7 @@ suite1: * * The search begins to address start_adresse */ -TRACK* Locate_Pistes( BOARD* aPcb, TRACK* start_adresse, const wxPoint& ref_pos, int MasqueLayer ) +TRACK* GetTrace( BOARD* aPcb, TRACK* start_adresse, const wxPoint& ref_pos, int LayerMask ) { for( TRACK* track = start_adresse; track; track = track->Next() ) { @@ -449,7 +452,7 @@ TRACK* Locate_Pistes( BOARD* aPcb, TRACK* start_adresse, const wxPoint& ref_pos, } else { - if( (g_TabOneLayerMask[layer] & MasqueLayer) == 0 ) + if( (g_TabOneLayerMask[layer] & LayerMask) == 0 ) continue; /* Segments on different layers. */ if( track->HitTest( ref_pos ) ) @@ -486,7 +489,7 @@ TRACK* Locate_Zone( TRACK* start_adresse, const wxPoint& ref_pos, int layer ) /* Find the pad center px, py, - * The layer INDICATED BY masque_layer (bitwise) + * The layer INDICATED BY aLayerMask (bitwise) * (Runway end) * The list of pads must already exist. * @@ -495,7 +498,7 @@ TRACK* Locate_Zone( TRACK* start_adresse, const wxPoint& ref_pos, int layer ) * Pointer to the structure corresponding descr_pad if pad found * (Good position and good layer). */ -D_PAD* Fast_Locate_Pad_Connecte( BOARD* Pcb, const wxPoint& ref_pos, int masque_layer ) +D_PAD* Fast_Locate_Pad_Connecte( BOARD* Pcb, const wxPoint& ref_pos, int aLayerMask ) { for( unsigned i=0; iGetPadsCount(); ++i ) { @@ -505,7 +508,7 @@ D_PAD* Fast_Locate_Pad_Connecte( BOARD* Pcb, const wxPoint& ref_pos, int masque_ continue; /* Pad found, it must be on the correct layer */ - if( pad->m_Masque_Layer & masque_layer ) + if( pad->m_layerMask & aLayerMask ) return pad; } @@ -520,7 +523,7 @@ D_PAD* Fast_Locate_Pad_Connecte( BOARD* Pcb, const wxPoint& ref_pos, int masque_ * The segments of track marks with the flag are not IS_DELETED or taken * into account */ -TRACK* Fast_Locate_Piste( TRACK* start_adr, TRACK* end_adr, const wxPoint& ref_pos, int MaskLayer ) +TRACK* GetTrace( TRACK* start_adr, TRACK* end_adr, const wxPoint& ref_pos, int MaskLayer ) { TRACK* PtSegm; diff --git a/pcbnew/magnetic_tracks_functions.cpp b/pcbnew/magnetic_tracks_functions.cpp index 8008c3a237..dcbe7cf126 100644 --- a/pcbnew/magnetic_tracks_functions.cpp +++ b/pcbnew/magnetic_tracks_functions.cpp @@ -46,6 +46,7 @@ static bool Join( wxPoint* res, wxPoint a0, wxPoint a1, wxPoint b0, wxPoint b1 ) b0 -= a0; denom = (double) b1.y * a1.x - (double) b1.x * a1.y; + if( !denom ) { return false; // parallel @@ -74,7 +75,7 @@ bool Project( wxPoint* res, wxPoint on_grid, const TRACK* track ) wxPoint vec = track->m_End - track->m_Start; double t = double( on_grid.x - track->m_Start.x ) * vec.x + - double( on_grid.y - track->m_Start.y ) * vec.y; + double( on_grid.y - track->m_Start.y ) * vec.y; t /= (double) vec.x * vec.x + (double) vec.y * vec.y; t = min( max( t, 0.0 ), 1.0 ); @@ -192,7 +193,7 @@ bool Magnetize( BOARD* m_Pcb, PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize gr { int layer_mask = g_TabOneLayerMask[layer]; - TRACK* track = Locate_Pistes( m_Pcb, m_Pcb->m_Track, pos, layer_mask ); + TRACK* track = GetTrace( m_Pcb, m_Pcb->m_Track, pos, layer_mask ); if( !track || track->Type() != TYPE_TRACK ) { diff --git a/pcbnew/mirepcb.cpp b/pcbnew/mirepcb.cpp index ce329b4edb..03ecc0ff2c 100644 --- a/pcbnew/mirepcb.cpp +++ b/pcbnew/mirepcb.cpp @@ -22,7 +22,7 @@ static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel, /* Local variables : */ static int MireDefaultSize = 5000; -static MIREPCB s_TargetCopy( NULL ); /* Used to store "old" values of the +static PCB_TARGET s_TargetCopy( NULL ); /* Used to store "old" values of the * current item parameters before * edition (used in undo/redo or * cancel operations) @@ -38,13 +38,13 @@ private: PCB_EDIT_FRAME* m_Parent; wxDC* m_DC; - MIREPCB* m_MirePcb; + PCB_TARGET* m_Target; EDA_VALUE_CTRL* m_MireWidthCtrl; EDA_VALUE_CTRL* m_MireSizeCtrl; wxRadioBox* m_MireShape; public: - TARGET_PROPERTIES_DIALOG_EDITOR( PCB_EDIT_FRAME* parent, MIREPCB* Mire, wxDC* DC ); + TARGET_PROPERTIES_DIALOG_EDITOR( PCB_EDIT_FRAME* parent, PCB_TARGET* Mire, wxDC* DC ); ~TARGET_PROPERTIES_DIALOG_EDITOR() { } private: @@ -60,19 +60,18 @@ BEGIN_EVENT_TABLE( TARGET_PROPERTIES_DIALOG_EDITOR, wxDialog ) END_EVENT_TABLE() -void PCB_EDIT_FRAME::InstallMireOptionsFrame( MIREPCB* MirePcb, wxDC* DC ) +void PCB_EDIT_FRAME::ShowTargetOptionsDialog( PCB_TARGET* aTarget, wxDC* DC ) { TARGET_PROPERTIES_DIALOG_EDITOR* frame = - new TARGET_PROPERTIES_DIALOG_EDITOR( this, MirePcb, DC ); + new TARGET_PROPERTIES_DIALOG_EDITOR( this, aTarget, DC ); frame->ShowModal(); frame->Destroy(); } -TARGET_PROPERTIES_DIALOG_EDITOR::TARGET_PROPERTIES_DIALOG_EDITOR( - PCB_EDIT_FRAME* parent, - MIREPCB* Mire, wxDC* DC ) : +TARGET_PROPERTIES_DIALOG_EDITOR::TARGET_PROPERTIES_DIALOG_EDITOR( PCB_EDIT_FRAME* parent, + PCB_TARGET* aTarget, wxDC* DC ) : wxDialog( parent, wxID_ANY, wxString( _( "Target Properties" ) ) ) { wxString number; @@ -82,7 +81,7 @@ TARGET_PROPERTIES_DIALOG_EDITOR::TARGET_PROPERTIES_DIALOG_EDITOR( m_DC = DC; Centre(); - m_MirePcb = Mire; + m_Target = aTarget; wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL ); SetSizer( MainBoxSizer ); @@ -100,13 +99,13 @@ TARGET_PROPERTIES_DIALOG_EDITOR::TARGET_PROPERTIES_DIALOG_EDITOR( // Size: m_MireSizeCtrl = new EDA_VALUE_CTRL( this, _( "Size" ), - m_MirePcb->m_Size, + m_Target->m_Size, g_UserUnit, LeftBoxSizer, m_Parent->m_InternalUnits ); // Width: m_MireWidthCtrl = new EDA_VALUE_CTRL( this, _( "Width" ), - m_MirePcb->m_Width, + m_Target->m_Width, g_UserUnit, LeftBoxSizer, m_Parent->m_InternalUnits ); @@ -116,7 +115,7 @@ TARGET_PROPERTIES_DIALOG_EDITOR::TARGET_PROPERTIES_DIALOG_EDITOR( _( "Target Shape:" ), wxDefaultPosition, wxSize( -1, -1 ), 2, shape_list, 1 ); - m_MireShape->SetSelection( m_MirePcb->m_Shape ? 1 : 0 ); + m_MireShape->SetSelection( m_Target->m_Shape ? 1 : 0 ); LeftBoxSizer->Add( m_MireShape, 0, wxGROW | wxALL, 5 ); GetSizer()->Fit( this ); @@ -134,143 +133,140 @@ void TARGET_PROPERTIES_DIALOG_EDITOR::OnCancelClick( wxCommandEvent& event ) */ void TARGET_PROPERTIES_DIALOG_EDITOR::OnOkClick( wxCommandEvent& event ) { - m_MirePcb->Draw( m_Parent->DrawPanel, m_DC, GR_XOR ); + m_Target->Draw( m_Parent->DrawPanel, m_DC, GR_XOR ); - // Save old item in undo list, if is is not currently edited (will be later - // if so) - if( m_MirePcb->m_Flags == 0 ) - m_Parent->SaveCopyInUndoList( m_MirePcb, UR_CHANGED ); + // Save old item in undo list, if is is not currently edited (will be later if so) + if( m_Target->m_Flags == 0 ) + m_Parent->SaveCopyInUndoList( m_Target, UR_CHANGED ); - if( m_MirePcb->m_Flags != 0 ) // other edition in progress (MOVE, - // NEW ..) - m_MirePcb->m_Flags |= IN_EDIT; // set flag in edit to force - // undo/redo/abort proper operation + if( m_Target->m_Flags != 0 ) // other edition in progress (MOVE, NEW ..) + m_Target->m_Flags |= IN_EDIT; // set flag in edit to force + // undo/redo/abort proper operation - m_MirePcb->m_Width = m_MireWidthCtrl->GetValue(); - MireDefaultSize = m_MirePcb->m_Size = m_MireSizeCtrl->GetValue(); - m_MirePcb->m_Shape = m_MireShape->GetSelection() ? 1 : 0; + m_Target->m_Width = m_MireWidthCtrl->GetValue(); + MireDefaultSize = m_Target->m_Size = m_MireSizeCtrl->GetValue(); + m_Target->m_Shape = m_MireShape->GetSelection() ? 1 : 0; - m_MirePcb->Draw( m_Parent->DrawPanel, m_DC, - ( m_MirePcb->m_Flags & IS_MOVED ) ? GR_XOR : GR_OR ); + m_Target->Draw( m_Parent->DrawPanel, m_DC, ( m_Target->m_Flags & IS_MOVED ) ? GR_XOR : GR_OR ); m_Parent->OnModify(); EndModal( 1 ); } -void PCB_EDIT_FRAME::Delete_Mire( MIREPCB* MirePcb, wxDC* DC ) +void PCB_EDIT_FRAME::DeleteTarget( PCB_TARGET* aTarget, wxDC* DC ) { - if( MirePcb == NULL ) + if( aTarget == NULL ) return; - MirePcb->Draw( DrawPanel, DC, GR_XOR ); - SaveCopyInUndoList( MirePcb, UR_DELETED ); - MirePcb->UnLink(); + aTarget->Draw( DrawPanel, DC, GR_XOR ); + SaveCopyInUndoList( aTarget, UR_DELETED ); + aTarget->UnLink(); } static void AbortMoveAndEditTarget( EDA_DRAW_PANEL* Panel, wxDC* DC ) { BASE_SCREEN* screen = Panel->GetScreen(); - MIREPCB* MirePcb = (MIREPCB*) screen->GetCurItem(); + PCB_TARGET* target = (PCB_TARGET*) screen->GetCurItem(); ( (PCB_EDIT_FRAME*) Panel->GetParent() )->SetCurItem( NULL ); Panel->SetMouseCapture( NULL, NULL ); - if( MirePcb == NULL ) + if( target == NULL ) return; - MirePcb->Draw( Panel, DC, GR_XOR ); + target->Draw( Panel, DC, GR_XOR ); - if( MirePcb->IsNew() ) // If it is new, delete it + if( target->IsNew() ) // If it is new, delete it { - MirePcb->Draw( Panel, DC, GR_XOR ); - MirePcb->DeleteStructure(); - MirePcb = NULL; + target->Draw( Panel, DC, GR_XOR ); + target->DeleteStructure(); + target = NULL; } else /* it is an existing item: retrieve initial values of parameters */ { - if( ( MirePcb->m_Flags & (IN_EDIT | IS_MOVED) ) ) + if( ( target->m_Flags & (IN_EDIT | IS_MOVED) ) ) { - MirePcb->m_Pos = s_TargetCopy.m_Pos; - MirePcb->m_Width = s_TargetCopy.m_Width; - MirePcb->m_Size = s_TargetCopy.m_Size; - MirePcb->m_Shape = s_TargetCopy.m_Shape; + target->m_Pos = s_TargetCopy.m_Pos; + target->m_Width = s_TargetCopy.m_Width; + target->m_Size = s_TargetCopy.m_Size; + target->m_Shape = s_TargetCopy.m_Shape; } - MirePcb->m_Flags = 0; - MirePcb->Draw( Panel, DC, GR_OR ); + target->m_Flags = 0; + target->Draw( Panel, DC, GR_OR ); } } /* Draw Symbol PCB type MIRE. */ -MIREPCB* PCB_EDIT_FRAME::Create_Mire( wxDC* DC ) +PCB_TARGET* PCB_EDIT_FRAME::CreateTarget( wxDC* DC ) { - MIREPCB* MirePcb = new MIREPCB( GetBoard() ); + PCB_TARGET* target = new PCB_TARGET( GetBoard() ); - MirePcb->m_Flags = IS_NEW; + target->m_Flags = IS_NEW; - GetBoard()->Add( MirePcb ); + GetBoard()->Add( target ); - MirePcb->SetLayer( EDGE_N ); - MirePcb->m_Width = GetBoard()->GetBoardDesignSettings()->m_EdgeSegmentWidth; - MirePcb->m_Size = MireDefaultSize; - MirePcb->m_Pos = DrawPanel->GetScreen()->GetCrossHairPosition(); + target->SetLayer( EDGE_N ); + target->m_Width = GetBoard()->GetBoardDesignSettings()->m_EdgeSegmentWidth; + target->m_Size = MireDefaultSize; + target->m_Pos = DrawPanel->GetScreen()->GetCrossHairPosition(); - Place_Mire( MirePcb, DC ); + PlaceTarget( target, DC ); - return MirePcb; + return target; } /* Routine to initialize the displacement of a focal */ -void PCB_EDIT_FRAME::StartMove_Mire( MIREPCB* MirePcb, wxDC* DC ) +void PCB_EDIT_FRAME::BeginMoveTarget( PCB_TARGET* aTarget, wxDC* DC ) { - if( MirePcb == NULL ) + if( aTarget == NULL ) return; - s_TargetCopy = *MirePcb; - MirePcb->m_Flags |= IS_MOVED; + s_TargetCopy = *aTarget; + aTarget->m_Flags |= IS_MOVED; DrawPanel->SetMouseCapture( ShowTargetShapeWhileMovingMouse, AbortMoveAndEditTarget ); - SetCurItem( MirePcb ); + SetCurItem( aTarget ); } -void PCB_EDIT_FRAME::Place_Mire( MIREPCB* MirePcb, wxDC* DC ) +void PCB_EDIT_FRAME::PlaceTarget( PCB_TARGET* aTarget, wxDC* DC ) { - if( MirePcb == NULL ) + if( aTarget == NULL ) return; - MirePcb->Draw( DrawPanel, DC, GR_OR ); + aTarget->Draw( DrawPanel, DC, GR_OR ); DrawPanel->SetMouseCapture( NULL, NULL ); SetCurItem( NULL ); OnModify(); - if( MirePcb->IsNew() ) + if( aTarget->IsNew() ) { - SaveCopyInUndoList( MirePcb, UR_NEW ); - MirePcb->m_Flags = 0; + SaveCopyInUndoList( aTarget, UR_NEW ); + aTarget->m_Flags = 0; return; } - if( MirePcb->m_Flags == IS_MOVED ) + if( aTarget->m_Flags == IS_MOVED ) { - SaveCopyInUndoList( MirePcb, UR_MOVED, MirePcb->m_Pos - s_TargetCopy.m_Pos ); - MirePcb->m_Flags = 0; + SaveCopyInUndoList( aTarget, UR_MOVED, aTarget->m_Pos - s_TargetCopy.m_Pos ); + aTarget->m_Flags = 0; return; } - if( (MirePcb->m_Flags & IN_EDIT) ) + if( (aTarget->m_Flags & IN_EDIT) ) { - SwapData( MirePcb, &s_TargetCopy ); - SaveCopyInUndoList( MirePcb, UR_CHANGED ); - SwapData( MirePcb, &s_TargetCopy ); + SwapData( aTarget, &s_TargetCopy ); + SaveCopyInUndoList( aTarget, UR_CHANGED ); + SwapData( aTarget, &s_TargetCopy ); } - MirePcb->m_Flags = 0; + aTarget->m_Flags = 0; } @@ -279,15 +275,15 @@ static void ShowTargetShapeWhileMovingMouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { BASE_SCREEN* screen = aPanel->GetScreen(); - MIREPCB* MirePcb = (MIREPCB*) screen->GetCurItem(); + PCB_TARGET* target = (PCB_TARGET*) screen->GetCurItem(); - if( MirePcb == NULL ) + if( target == NULL ) return; if( aErase ) - MirePcb->Draw( aPanel, aDC, GR_XOR ); + target->Draw( aPanel, aDC, GR_XOR ); - MirePcb->m_Pos = screen->GetCrossHairPosition(); + target->m_Pos = screen->GetCrossHairPosition(); - MirePcb->Draw( aPanel, aDC, GR_XOR ); + target->Draw( aPanel, aDC, GR_XOR ); } diff --git a/pcbnew/modedit.cpp b/pcbnew/modedit.cpp index e752e3e603..c6dc186c1a 100644 --- a/pcbnew/modedit.cpp +++ b/pcbnew/modedit.cpp @@ -795,8 +795,10 @@ void FOOTPRINT_EDIT_FRAME::Transform( MODULE* module, int transform ) textmod = (TEXTE_MODULE*) PtStruct; NEGATE( textmod->m_Pos.y ); NEGATE( textmod->m_Pos0.y ); + if( textmod->m_Orient ) textmod->m_Orient = 3600 - textmod->m_Orient; + break; default: @@ -812,7 +814,7 @@ void FOOTPRINT_EDIT_FRAME::Transform( MODULE* module, int transform ) break; } - module->Set_Rectangle_Encadrement(); + module->CalculateBoundingBox(); OnModify(); } diff --git a/pcbnew/modedit_onclick.cpp b/pcbnew/modedit_onclick.cpp index 5deaaf7382..a47997bcd6 100644 --- a/pcbnew/modedit_onclick.cpp +++ b/pcbnew/modedit_onclick.cpp @@ -184,7 +184,7 @@ bool FOOTPRINT_EDIT_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMen { BOARD_ITEM* item = GetCurItem(); wxString msg; - bool append_set_width = FALSE; + bool append_set_width = false; bool blockActive = GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE; // Simple location of elements where possible. @@ -338,7 +338,7 @@ bool FOOTPRINT_EDIT_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMen _( "Edit Layer (All)" ), select_layer_pair_xpm ); msg = AddHotkeyName( _("Delete edge" ), g_Module_Editor_Hokeys_Descr, HK_DELETE ); AddMenuItem( PopMenu, ID_POPUP_PCB_DELETE_EDGE, msg, delete_xpm ); - append_set_width = TRUE; + append_set_width = true; } break; @@ -349,7 +349,7 @@ bool FOOTPRINT_EDIT_FRAME::OnRightClick( const wxPoint& MousePos, wxMenu* PopMen case TYPE_ZONE: case TYPE_MARKER_PCB: case TYPE_DIMENSION: - case TYPE_MIRE: + case PCB_TARGET_T: break; case TYPE_SCREEN: diff --git a/pcbnew/modules.cpp b/pcbnew/modules.cpp index bf962b7781..369ef2a9ea 100644 --- a/pcbnew/modules.cpp +++ b/pcbnew/modules.cpp @@ -35,22 +35,27 @@ MODULE* PCB_BASE_FRAME::GetModuleByName() MODULE* module = NULL; wxTextEntryDialog dlg( this, _( "Name:" ), _( "Search footprint" ), moduleName ); + if( dlg.ShowModal() != wxID_OK ) return NULL; //Aborted by user moduleName = dlg.GetValue(); moduleName.Trim( true ); moduleName.Trim( false ); + if( !moduleName.IsEmpty() ) { module = GetBoard()->m_Modules; + while( module ) { if( module->m_Reference->m_Text.CmpNoCase( moduleName ) == 0 ) break; + module = module->Next(); } } + return module; } @@ -83,6 +88,7 @@ void PCB_EDIT_FRAME::StartMove_Module( MODULE* module, wxDC* DC ) { Build_Drag_Liste( DrawPanel, DC, module ); ITEM_PICKER itemWrapper( NULL, UR_CHANGED ); + for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) { TRACK* segm = g_DragSegmentList[ii].m_Segm; @@ -94,7 +100,7 @@ void PCB_EDIT_FRAME::StartMove_Module( MODULE* module, wxDC* DC ) } GetBoard()->m_Status_Pcb |= DO_NOT_SHOW_GENERAL_RASTNEST; - DrawPanel->SetMouseCapture( Montre_Position_Empreinte, Abort_MoveOrCopyModule ); + DrawPanel->SetMouseCapture( MoveFootprint, Abort_MoveOrCopyModule ); DrawPanel->m_AutoPAN_Request = true; // Erase the module. @@ -229,8 +235,7 @@ MODULE* PCB_BASE_FRAME::Copie_Module( MODULE* module ) /* Redraw the footprint when moving the mouse. */ -void Montre_Position_Empreinte( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, - bool aErase ) +void MoveFootprint( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { MODULE* module = (MODULE*) aPanel->GetScreen()->GetCurItem(); @@ -247,7 +252,7 @@ void Montre_Position_Empreinte( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint g_Offset_Module = module->m_Pos - aPanel->GetScreen()->GetCrossHairPosition(); DrawModuleOutlines( aPanel, aDC, module ); - Dessine_Segments_Dragges( aPanel, aDC ); + DrawSegmentWhileMovingFootprint( aPanel, aDC ); } @@ -274,6 +279,7 @@ bool PCB_EDIT_FRAME::Delete_Module( MODULE* aModule, wxDC* aDC, bool aAskBeforeD msg.Printf( _( "Delete Module %s (value %s) ?" ), GetChars( aModule->m_Reference->m_Text ), GetChars( aModule->m_Value->m_Text ) ); + if( !IsOK( this, msg ) ) { return false; @@ -311,16 +317,16 @@ void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC ) { if( Module == NULL ) return; - if( ( Module->GetLayer() != LAYER_N_FRONT ) - && ( Module->GetLayer() != LAYER_N_BACK ) ) + + if( ( Module->GetLayer() != LAYER_N_FRONT ) && ( Module->GetLayer() != LAYER_N_BACK ) ) return; OnModify(); - if( !( Module->m_Flags & IS_MOVED ) ) /* This is a simple flip, no other - *edition in progress */ + if( !( Module->m_Flags & IS_MOVED ) ) /* This is a simple flip, no other edition in progress */ { GetBoard()->m_Status_Pcb &= ~( LISTE_RATSNEST_ITEM_OK | CONNEXION_OK ); + if( DC ) { int tmp = Module->m_Flags; @@ -342,7 +348,7 @@ void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC ) if( DC ) { DrawModuleOutlines( DrawPanel, DC, Module ); - Dessine_Segments_Dragges( DrawPanel, DC ); + DrawSegmentWhileMovingFootprint( DrawPanel, DC ); } } @@ -356,6 +362,7 @@ void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC ) if( DC ) { Module->Draw( DrawPanel, DC, GR_OR ); + if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) ) Compile_Ratsnest( DC, true ); } @@ -365,8 +372,9 @@ void PCB_EDIT_FRAME::Change_Side_Module( MODULE* Module, wxDC* DC ) if( DC ) { DrawModuleOutlines( DrawPanel, DC, Module ); - Dessine_Segments_Dragges( DrawPanel, DC ); + DrawSegmentWhileMovingFootprint( DrawPanel, DC ); } + GetBoard()->m_Status_Pcb &= ~RATSNEST_ITEM_LOCAL_OK; } } @@ -397,22 +405,19 @@ void PCB_BASE_FRAME::Place_Module( MODULE* module, wxDC* DC, bool aDoNotRecreate ITEM_PICKER picker( module, UR_CHANGED ); picker.m_Link = s_ModuleInitialCopy; s_PickedList.PushItem( picker ); - s_ModuleInitialCopy = NULL; // the picker is now owner of - // s_ModuleInitialCopy. + s_ModuleInitialCopy = NULL; // the picker is now owner of s_ModuleInitialCopy. } if( s_PickedList.GetCount() ) { SaveCopyInUndoList( s_PickedList, UR_UNSPECIFIED ); - // Clear list, but DO NOT delete items, - // because they are owned by the saved undo list and they therefore in - // use + // Clear list, but DO NOT delete items, because they are owned by the saved undo + // list and they therefore in use s_PickedList.ClearItemsList(); } - if( g_Show_Module_Ratsnest && ( GetBoard()->m_Status_Pcb & LISTE_PAD_OK ) - && DC ) + if( g_Show_Module_Ratsnest && ( GetBoard()->m_Status_Pcb & LISTE_PAD_OK ) && DC ) trace_ratsnest_module( DC ); newpos = GetScreen()->GetCrossHairPosition(); @@ -487,7 +492,7 @@ void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, int angle, bool in if( DC ) { DrawModuleOutlines( DrawPanel, DC, module ); - Dessine_Segments_Dragges( DrawPanel, DC ); + DrawSegmentWhileMovingFootprint( DrawPanel, DC ); } } @@ -506,6 +511,7 @@ void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, int angle, bool in { // not beiing moved: redraw the module and update ratsnest module->Draw( DrawPanel, DC, GR_OR ); + if( GetBoard()->IsElementVisible( RATSNEST_VISIBLE ) ) Compile_Ratsnest( DC, true ); } @@ -513,7 +519,7 @@ void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, int angle, bool in { // Beiing moved: just redraw it DrawModuleOutlines( DrawPanel, DC, module ); - Dessine_Segments_Dragges( DrawPanel, DC ); + DrawSegmentWhileMovingFootprint( DrawPanel, DC ); } if( module->m_Flags == 0 ) // module not in edit: redraw full screen @@ -540,6 +546,7 @@ void DrawModuleOutlines( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* module ) DisplayOpt.DisplayPadFill = true; pt_pad = module->m_Pads; + for( ; pt_pad != NULL; pt_pad = pt_pad->Next() ) { pt_pad->Draw( panel, DC, GR_XOR, g_Offset_Module ); diff --git a/pcbnew/move-drag_pads.cpp b/pcbnew/move-drag_pads.cpp index aa09248af5..3930fc2c10 100644 --- a/pcbnew/move-drag_pads.cpp +++ b/pcbnew/move-drag_pads.cpp @@ -51,7 +51,7 @@ static void Abort_Move_Pad( EDA_DRAW_PANEL* Panel, wxDC* DC ) EraseDragList(); s_CurrentSelectedPad = NULL; - g_Drag_Pistes_On = FALSE; + g_Drag_Pistes_On = false; } @@ -109,7 +109,7 @@ void PCB_BASE_FRAME::Export_Pad_Settings( D_PAD* pt_pad ) g_Pad_Master.m_PadShape = pt_pad->m_PadShape; g_Pad_Master.m_Attribut = pt_pad->m_Attribut; - g_Pad_Master.m_Masque_Layer = pt_pad->m_Masque_Layer; + g_Pad_Master.m_layerMask = pt_pad->m_layerMask; g_Pad_Master.m_Orient = pt_pad->m_Orient - ( (MODULE*) pt_pad->GetParent() )->m_Orient; g_Pad_Master.m_Size = pt_pad->m_Size; @@ -137,7 +137,7 @@ void PCB_BASE_FRAME::Import_Pad_Settings( D_PAD* aPad, bool aDraw ) } aPad->m_PadShape = g_Pad_Master.m_PadShape; - aPad->m_Masque_Layer = g_Pad_Master.m_Masque_Layer; + aPad->m_layerMask = g_Pad_Master.m_layerMask; aPad->m_Attribut = g_Pad_Master.m_Attribut; aPad->m_Orient = g_Pad_Master.m_Orient + ( (MODULE*) aPad->GetParent() )->m_Orient; @@ -206,8 +206,7 @@ void PCB_BASE_FRAME::AddPad( MODULE* Module, bool draw ) long num = 0; int ponder = 1; - while( lastPadName.Len() && lastPadName.Last() >= '0' - && lastPadName.Last() <= '9' ) + while( lastPadName.Len() && lastPadName.Last() >= '0' && lastPadName.Last() <= '9' ) { num += ( lastPadName.Last() - '0' ) * ponder; lastPadName.RemoveLast(); @@ -219,8 +218,9 @@ void PCB_BASE_FRAME::AddPad( MODULE* Module, bool draw ) Pad->SetPadName( lastPadName ); g_Pad_Master.SetPadName(lastPadName); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); Pad->DisplayInfo( this ); + if( draw ) DrawPanel->RefreshDrawingRect( Module->GetBoundingBox() ); } @@ -248,8 +248,9 @@ void PCB_BASE_FRAME::DeletePad( D_PAD* aPad, bool aQuery ) { wxString msg; msg.Printf( _( "Delete Pad (module %s %s) " ), - GetChars( Module->m_Reference->m_Text ), - GetChars( Module->m_Value->m_Text ) ); + GetChars( Module->m_Reference->m_Text ), + GetChars( Module->m_Value->m_Text ) ); + if( !IsOK( this, msg ) ) return; } @@ -257,7 +258,7 @@ void PCB_BASE_FRAME::DeletePad( D_PAD* aPad, bool aQuery ) m_Pcb->m_Status_Pcb = 0; aPad->DeleteStructure(); DrawPanel->RefreshDrawingRect( Module->GetBoundingBox() ); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); OnModify(); } @@ -310,6 +311,7 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* Pad, wxDC* DC ) // Set the old state if( g_DragSegmentList[ii].m_Pad_Start ) Track->m_Start = Pad_OldPos; + if( g_DragSegmentList[ii].m_Pad_End ) Track->m_End = Pad_OldPos; @@ -342,6 +344,7 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* Pad, wxDC* DC ) // Set the new state if( g_DragSegmentList[ii].m_Pad_Start ) Track->m_Start = Pad->m_Pos; + if( g_DragSegmentList[ii].m_Pad_End ) Track->m_End = Pad->m_Pos; @@ -351,8 +354,7 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* Pad, wxDC* DC ) Track->Draw( DrawPanel, DC, GR_OR ); } - /* Compute local coordinates (i.e refer to Module position and for Module - * orient = 0) */ + /* Compute local coordinates (i.e refer to Module position and for Module orient = 0) */ dX = Pad->m_Pos.x - Pad_OldPos.x; dY = Pad->m_Pos.y - Pad_OldPos.y; RotatePoint( &dX, &dY, -Module->m_Orient ); @@ -365,7 +367,7 @@ void PCB_BASE_FRAME::PlacePad( D_PAD* Pad, wxDC* DC ) if( DC ) Pad->Draw( DrawPanel, DC, GR_OR ); - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); Module->m_LastEdit_Time = time( NULL ); EraseDragList(); @@ -400,7 +402,7 @@ void PCB_BASE_FRAME::RotatePad( D_PAD* Pad, wxDC* DC ) EXCHG( Pad->m_DeltaSize.x, Pad->m_DeltaSize.y ); Pad->m_DeltaSize.x = -Pad->m_DeltaSize.x; - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); Pad->DisplayInfo( this ); if( DC ) diff --git a/pcbnew/move_or_drag_track.cpp b/pcbnew/move_or_drag_track.cpp index 78bb511fef..2a0d077869 100644 --- a/pcbnew/move_or_drag_track.cpp +++ b/pcbnew/move_or_drag_track.cpp @@ -83,6 +83,7 @@ static void Abort_MoveTrack( EDA_DRAW_PANEL* Panel, wxDC* DC ) TRACK* Track = NewTrack; int dx = s_LastPos.x - PosInit.x; int dy = s_LastPos.y - PosInit.y; + for( ii = 0; ii < NbPtNewTrack; ii++, Track = Track->Next() ) { if( Track == NULL ) @@ -97,7 +98,7 @@ static void Abort_MoveTrack( EDA_DRAW_PANEL* Panel, wxDC* DC ) Track->m_Flags = 0; } - Trace_Une_Piste( Panel, DC, NewTrack, NbPtNewTrack, GR_OR ); + DrawTraces( Panel, DC, NewTrack, NbPtNewTrack, GR_OR ); } NewTrack = NULL; @@ -147,7 +148,7 @@ static void Show_MoveNode( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPo if( aErase ) { if( NewTrack ) - Trace_Une_Piste( aPanel, aDC, NewTrack, NbPtNewTrack, draw_mode ); + DrawTraces( aPanel, aDC, NewTrack, NbPtNewTrack, draw_mode ); } /* set the new track coordinates */ @@ -169,7 +170,7 @@ static void Show_MoveNode( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPo } /* Redraw the current moved track segments */ - Trace_Une_Piste( aPanel, aDC, NewTrack, NbPtNewTrack, draw_mode ); + DrawTraces( aPanel, aDC, NewTrack, NbPtNewTrack, draw_mode ); for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) { @@ -422,13 +423,13 @@ static void Show_Drag_Track_Segment_With_Cte_Slope( EDA_DRAW_PANEL* aPanel, wxDC xi1 = tx1; yi1 = ty1; } + if( tSegmentToEnd == NULL ) { xi2 = tx2; yi2 = ty2; } - if( update ) { s_LastPos = Pos; @@ -492,22 +493,23 @@ bool InitialiseDragParameters() Track = g_DragSegmentList[ii].m_Segm; if( Track == NULL ) return false; + ii--; + if( ii >= 0) { if( s_EndSegmentPresent ) { - tSegmentToEnd = g_DragSegmentList[ii].m_Segm; // Get the segment - // connected to the end - // point + tSegmentToEnd = g_DragSegmentList[ii].m_Segm; // Get the segment connected to + // the end point ii--; } + if( s_StartSegmentPresent ) { if( ii >= 0 ) - tSegmentToStart = g_DragSegmentList[ii].m_Segm; // Get the segment - // connected to the - // start point + tSegmentToStart = g_DragSegmentList[ii].m_Segm; // Get the segment connected to + // the start point } } @@ -549,6 +551,7 @@ bool InitialiseDragParameters() ty2 = (double) Track->m_End.y; RotatePoint( &tx2, &ty2, tx1, ty1, 900 ); } + if( tx1 != tx2 ) { s_StartSegmentSlope = ( ty2 - ty1 ) / ( tx2 - tx1 ); @@ -558,6 +561,7 @@ bool InitialiseDragParameters() { s_StartPointVertical = true; //signal first segment vertical } + if( ty1 == ty2 ) { s_StartPointHorizontal = true; @@ -602,6 +606,7 @@ bool InitialiseDragParameters() { s_EndPointVertical = true; //signal second segment vertical } + if( ty1 == ty2 ) { s_EndPointHorizontal = true; @@ -621,6 +626,7 @@ bool InitialiseDragParameters() { s_MovingSegmentVertical = true; //signal vertical line } + if( ty1 == ty2 ) { s_MovingSegmentHorizontal = true; @@ -634,11 +640,10 @@ bool InitialiseDragParameters() } else { - if( !s_EndPointVertical - && ( s_MovingSegmentSlope == s_EndSegmentSlope ) ) + if( !s_EndPointVertical && ( s_MovingSegmentSlope == s_EndSegmentSlope ) ) return false; - if( !s_StartPointVertical - && ( s_MovingSegmentSlope == s_StartSegmentSlope ) ) + + if( !s_StartPointVertical && ( s_MovingSegmentSlope == s_StartSegmentSlope ) ) return false; } @@ -664,17 +669,20 @@ void PCB_EDIT_FRAME::Start_MoveOneNodeOrSegment( TRACK* track, wxDC* DC, int com if( GetBoard()->IsHightLightNetON() ) High_Light( DC ); + PosInit = GetScreen()->GetCrossHairPosition(); if( track->Type() == TYPE_VIA ) // For a via: always drag it { track->m_Flags = IS_DRAGGED | STARTPOINT | ENDPOINT; + if( command != ID_POPUP_PCB_MOVE_TRACK_SEGMENT ) { Collect_TrackSegmentsToDrag( DrawPanel, DC, track->m_Start, track->ReturnMaskLayer(), track->GetNet() ); } + NewTrack = track; NbPtNewTrack = 1; PosInit = track->m_Start; @@ -719,6 +727,7 @@ void PCB_EDIT_FRAME::Start_MoveOneNodeOrSegment( TRACK* track, wxDC* DC, int com ITEM_PICKER picker( track, UR_CHANGED ); picker.m_Link = track->Copy(); s_ItemsListPicker.PushItem( picker ); + for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) { TRACK* draggedtrack = g_DragSegmentList[ii].m_Segm; @@ -774,13 +783,12 @@ void SortTrackEndPoints( TRACK* track ) * 2 collinear segments can be merged only in no other segment or via is * connected to the common point * and if they have the same width. See cleanup.cpp for merge functions, - * and consider Marque_Une_Piste() to locate segments that can be merged + * and consider MarkTrace() to locate segments that can be merged */ bool PCB_EDIT_FRAME::MergeCollinearTracks( TRACK* track, wxDC* DC, int end ) { - testtrack = (TRACK*) Locate_Piste_Connectee( track, - GetBoard()->m_Track, NULL, - end ); + testtrack = (TRACK*) GetConnectedTrace( track, GetBoard()->m_Track, NULL, end ); + if( testtrack ) { SortTrackEndPoints( track ); @@ -790,14 +798,12 @@ bool PCB_EDIT_FRAME::MergeCollinearTracks( TRACK* track, wxDC* DC, int end ) int tdx = testtrack->m_End.x - testtrack->m_Start.x; int tdy = testtrack->m_End.y - testtrack->m_Start.y; - if( ( dy * tdx == dx * tdy && dy != 0 && dx != 0 && tdy != 0 && tdx != - 0 ) /* angle, same slope */ + if( ( dy * tdx == dx * tdy && dy != 0 && dx != 0 && tdy != 0 && tdx != 0 ) /* angle, same slope */ || ( dy == 0 && tdy == 0 && dx * tdx ) /*horizontal */ || ( dx == 0 && tdx == 0 && dy * tdy ) /*vertical */ ) { - if( track->m_Start == testtrack->m_Start || track->m_End == - testtrack->m_Start ) + if( track->m_Start == testtrack->m_Start || track->m_End == testtrack->m_Start ) { if( ( dx * tdx && testtrack->m_End.x > track->m_End.x ) ||( dy * tdy && testtrack->m_End.y > track->m_End.y ) ) @@ -808,11 +814,11 @@ bool PCB_EDIT_FRAME::MergeCollinearTracks( TRACK* track, wxDC* DC, int end ) return true; } } - if( track->m_Start == testtrack->m_End || track->m_End == - testtrack->m_End ) + + if( track->m_Start == testtrack->m_End || track->m_End == testtrack->m_End ) { if( ( dx * tdx && testtrack->m_Start.x < track->m_Start.x ) - ||( dy * tdy && testtrack->m_Start.y < track->m_Start.y ) ) + || ( dy * tdy && testtrack->m_Start.y < track->m_Start.y ) ) { track->m_Start = testtrack->m_Start; @@ -846,6 +852,7 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC while( MergeCollinearTracks( track, DC, START ) ) { }; + while( MergeCollinearTracks( track, DC, END ) ) { }; @@ -854,32 +861,32 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC s_StartSegmentPresent = s_EndSegmentPresent = true; if( ( track->start == NULL ) || ( track->start->Type() == TYPE_TRACK ) ) - TrackToStartPoint = Locate_Piste_Connectee( track, - GetBoard()->m_Track, NULL, - START ); + TrackToStartPoint = GetConnectedTrace( track, GetBoard()->m_Track, NULL, START ); // Test if more than one segment is connected to this point if( TrackToStartPoint ) { TrackToStartPoint->SetState( BUSY, ON ); + if( ( TrackToStartPoint->Type() == TYPE_VIA ) - || Locate_Piste_Connectee( track, GetBoard()->m_Track, NULL, START ) ) + || GetConnectedTrace( track, GetBoard()->m_Track, NULL, START ) ) error = true; + TrackToStartPoint->SetState( BUSY, OFF ); } if( ( track->end == NULL ) || ( track->end->Type() == TYPE_TRACK ) ) - TrackToEndPoint = Locate_Piste_Connectee( track, - GetBoard()->m_Track, NULL, - END ); + TrackToEndPoint = GetConnectedTrace( track, GetBoard()->m_Track, NULL, END ); // Test if more than one segment is connected to this point if( TrackToEndPoint ) { TrackToEndPoint->SetState( BUSY, ON ); + if( (TrackToEndPoint->Type() == TYPE_VIA) - || Locate_Piste_Connectee( track, GetBoard()->m_Track, NULL, END ) ) + || GetConnectedTrace( track, GetBoard()->m_Track, NULL, END ) ) error = true; + TrackToEndPoint->SetState( BUSY, OFF ); } @@ -898,6 +905,7 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC /* Change high light net: the new one will be highlighted */ GetBoard()->PushHightLight(); + if( GetBoard()->IsHightLightNetON() ) High_Light( DC ); @@ -910,8 +918,10 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC if( TrackToStartPoint ) { int flag = STARTPOINT; + if( track->m_Start != TrackToStartPoint->m_Start ) flag = ENDPOINT; + AddSegmentToDragList( DrawPanel, DC, flag, TrackToStartPoint ); track->m_Flags |= STARTPOINT; } @@ -919,8 +929,10 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC if( TrackToEndPoint ) { int flag = STARTPOINT; + if( track->m_End != TrackToEndPoint->m_Start ) flag = ENDPOINT; + AddSegmentToDragList( DrawPanel, DC, flag, TrackToEndPoint ); track->m_Flags |= ENDPOINT; } @@ -938,6 +950,7 @@ void PCB_EDIT_FRAME::Start_DragTrackSegmentAndKeepSlope( TRACK* track, wxDC* DC // Prepare the Undo command ITEM_PICKER picker( NULL, UR_CHANGED ); + for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) { TRACK* draggedtrack = g_DragSegmentList[ii].m_Segm; @@ -973,12 +986,15 @@ bool PCB_EDIT_FRAME::PlaceDraggedOrMovedTrackSegment( TRACK* Track, wxDC* DC ) if( Drc_On ) { errdrc = m_drc->Drc( Track, GetBoard()->m_Track ); + if( errdrc == BAD_DRC ) return false; + /* Redraw the dragged segments */ for( unsigned ii = 0; ii < g_DragSegmentList.size(); ii++ ) { errdrc = m_drc->Drc( g_DragSegmentList[ii].m_Segm, GetBoard()->m_Track ); + if( errdrc == BAD_DRC ) return false; } @@ -1002,14 +1018,15 @@ bool PCB_EDIT_FRAME::PlaceDraggedOrMovedTrackSegment( TRACK* Track, wxDC* DC ) /* Test the connections modified by the move * (only pad connection must be tested, track connection will be * tested by test_1_net_connexion() ) */ - int masque_layer = g_TabOneLayerMask[Track->GetLayer()]; - Track->start = Fast_Locate_Pad_Connecte( GetBoard(), Track->m_Start, masque_layer ); + int layerMask = g_TabOneLayerMask[Track->GetLayer()]; + Track->start = Fast_Locate_Pad_Connecte( GetBoard(), Track->m_Start, layerMask ); + if( Track->start ) Track->SetState( BEGIN_ONPAD, ON ); else Track->SetState( BEGIN_ONPAD, OFF ); - Track->end = Fast_Locate_Pad_Connecte( GetBoard(), Track->m_End, masque_layer ); + Track->end = Fast_Locate_Pad_Connecte( GetBoard(), Track->m_End, layerMask ); if( Track->end ) Track->SetState( END_ONPAD, ON ); else @@ -1019,8 +1036,7 @@ bool PCB_EDIT_FRAME::PlaceDraggedOrMovedTrackSegment( TRACK* Track, wxDC* DC ) EraseDragList(); SaveCopyInUndoList( s_ItemsListPicker, UR_UNSPECIFIED ); - s_ItemsListPicker.ClearItemsList(); // s_ItemsListPicker is no more owner - // of picked items + s_ItemsListPicker.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items if( GetBoard()->IsHightLightNetON() ) High_Light( DC ); @@ -1061,10 +1077,10 @@ BOARD_ITEM* LocateLockPoint( BOARD* Pcb, wxPoint pos, int LayerMask ) } /* No pad has been located so check for a segment of the trace. */ - TRACK* ptsegm = Fast_Locate_Piste( Pcb->m_Track, NULL, pos, LayerMask ); + TRACK* ptsegm = GetTrace( Pcb->m_Track, NULL, pos, LayerMask ); if( ptsegm == NULL ) - ptsegm = Locate_Pistes( Pcb, Pcb->m_Track, pos, LayerMask ); + ptsegm = GetTrace( Pcb, Pcb->m_Track, pos, LayerMask ); return ptsegm; } @@ -1133,6 +1149,7 @@ TRACK* CreateLockPoint( BOARD* aPcb, newPoint.y += aSegm->m_Start.y; TRACK* newTrack = aSegm->Copy(); + if( aItemsListPicker ) { ITEM_PICKER picker( newTrack, UR_NEW ); @@ -1169,6 +1186,7 @@ TRACK* CreateLockPoint( BOARD* aPcb, newTrack->SetState( BEGIN_ONPAD, OFF ); D_PAD * pad = Locate_Pad_Connecte( aPcb, newTrack, START ); + if ( pad ) { newTrack->start = pad; diff --git a/pcbnew/muonde.cpp b/pcbnew/muonde.cpp index d374dcaf80..f3690cfc7f 100644 --- a/pcbnew/muonde.cpp +++ b/pcbnew/muonde.cpp @@ -199,6 +199,7 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) /* Enter the desired length. */ msg = ReturnStringFromValue( g_UserUnit, Mself.lng, GetScreen()->GetInternalUnits() ); wxTextEntryDialog dlg( this, _( "Length:" ), _( "Length" ), msg ); + if( dlg.ShowModal() != wxID_OK ) return NULL; // cancelled by user @@ -216,8 +217,8 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) Mself.m_Width = GetBoard()->GetCurrentTrackWidth(); std::vector buffer; - ll = BuildCornersList_S_Shape( buffer, Mself.m_Start, Mself.m_End, - Mself.lng, Mself.m_Width ); + ll = BuildCornersList_S_Shape( buffer, Mself.m_Start, Mself.m_End, Mself.lng, Mself.m_Width ); + if( !ll ) { DisplayError( this, _( "Requested length too large" ) ); @@ -228,6 +229,7 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) /* Generate module. */ MODULE* Module; Module = Create_1_Module( wxEmptyString ); + if( Module == NULL ) return NULL; @@ -261,7 +263,7 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) PtPad->m_Pos = Mself.m_End; PtPad->m_Pos0 = PtPad->m_Pos - Module->m_Pos; PtPad->m_Size.x = PtPad->m_Size.y = Mself.m_Width; - PtPad->m_Masque_Layer = g_TabOneLayerMask[Module->GetLayer()]; + PtPad->m_layerMask = g_TabOneLayerMask[Module->GetLayer()]; PtPad->m_Attribut = PAD_SMD; PtPad->m_PadShape = PAD_CIRCLE; PtPad->ComputeShapeMaxRadius(); @@ -279,17 +281,16 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) /* Modify text positions. */ Module->DisplayInfo( this ); Module->m_Value->m_Pos.x = Module->m_Reference->m_Pos.x = - ( Mself.m_Start.x + Mself.m_End.x ) / 2; + ( Mself.m_Start.x + Mself.m_End.x ) / 2; Module->m_Value->m_Pos.y = Module->m_Reference->m_Pos.y = - ( Mself.m_Start.y + Mself.m_End.y ) / 2; + ( Mself.m_Start.y + Mself.m_End.y ) / 2; Module->m_Reference->m_Pos.y -= Module->m_Reference->m_Size.y; Module->m_Value->m_Pos.y += Module->m_Value->m_Size.y; Module->m_Reference->m_Pos0 = Module->m_Reference->m_Pos - Module->m_Pos; Module->m_Value->m_Pos0 = Module->m_Value->m_Pos - Module->m_Pos; - - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); Module->Draw( DrawPanel, DC, GR_OR ); return Module; @@ -394,7 +395,7 @@ int BuildCornersList_S_Shape( std::vector & aBuffer, wxPoint pt = aEndPoint - aStartPoint; int angle = -wxRound( atan2( (double) pt.y, (double) pt.x ) * 1800.0 / M_PI ); int min_len = wxRound( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) ); - int segm_len = 0; // lenght of segments + int segm_len = 0; // length of segments int full_len; // full len of shape (sum of lenght of all segments + arcs) @@ -415,25 +416,29 @@ int BuildCornersList_S_Shape( std::vector & aBuffer, int segm_count; // number of full len segments // the half size segments (first and last segment) are not counted here int stubs_len = 0; // lenght of first or last segment (half size of others segments) + for( segm_count = 0; ; segm_count++ ) { stubs_len = ( size.y - ( radius * 2 * (segm_count + 2 ) ) ) / 2; + if( stubs_len < size.y / 10 ) // Reduce radius. { stubs_len = size.y / 10; radius = ( size.y - (2 * stubs_len) ) / ( 2 * (segm_count + 2) ); + if( radius < aWidth ) // Radius too small. { // Unable to create line: Requested length value is too large for room return 0; } } + segm_len = size.x - ( radius * 2 ); - full_len = 2 * stubs_len; // Length of coil connections. - full_len += segm_len * segm_count; // Length of full length segments. + full_len = 2 * stubs_len; // Length of coil connections. + full_len += segm_len * segm_count; // Length of full length segments. full_len += wxRound( ( segm_count + 2 ) * M_PI * ADJUST_SIZE * radius ); // Ard arcs len - full_len += segm_len - (2 * radius); // Length of first and last segments - // (half size segments len = segm_len/2 - radius). + full_len += segm_len - (2 * radius); // Length of first and last segments + // (half size segments len = segm_len/2 - radius). if( full_len >= aLength ) break; @@ -457,6 +462,7 @@ int BuildCornersList_S_Shape( std::vector & aBuffer, pt = aBuffer.back(); int half_size_seg_len = segm_len / 2 - radius; + if( half_size_seg_len ) { pt.x -= half_size_seg_len; @@ -467,6 +473,7 @@ int BuildCornersList_S_Shape( std::vector & aBuffer, int ii; int sign = 1; segm_count += 1; // increase segm_count to create the last half_size segment + for( ii = 0; ii < segm_count; ii++ ) { int arc_angle; @@ -475,6 +482,7 @@ int BuildCornersList_S_Shape( std::vector & aBuffer, sign = -1; else sign = 1; + arc_angle = 1800 * sign; centre = pt; centre.y += radius; @@ -498,10 +506,10 @@ int BuildCornersList_S_Shape( std::vector & aBuffer, // Rotate point angle += 900; + for( unsigned jj = 0; jj < aBuffer.size(); jj++ ) { - RotatePoint( &aBuffer[jj].x, &aBuffer[jj].y, - aStartPoint.x, aStartPoint.y, angle ); + RotatePoint( &aBuffer[jj].x, &aBuffer[jj].y, aStartPoint.x, aStartPoint.y, angle ); } // push last point (end point) @@ -522,6 +530,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveBasicShape( const wxString& name, int pad_c wxString Line; Module = Create_1_Module( name ); + if( Module == NULL ) return NULL; @@ -546,11 +555,11 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveBasicShape( const wxString& name, int pad_c Module->m_Pads.PushFront( pad ); - pad->m_Size.x = pad->m_Size.y = GetBoard()->GetCurrentTrackWidth(); - pad->m_Pos = Module->m_Pos; - pad->m_PadShape = PAD_RECT; - pad->m_Attribut = PAD_SMD; - pad->m_Masque_Layer = LAYER_FRONT; + pad->m_Size.x = pad->m_Size.y = GetBoard()->GetCurrentTrackWidth(); + pad->m_Pos = Module->m_Pos; + pad->m_PadShape = PAD_RECT; + pad->m_Attribut = PAD_SMD; + pad->m_layerMask = LAYER_FRONT; Line.Printf( wxT( "%d" ), pad_num ); pad->SetPadName( Line ); pad_num++; @@ -566,7 +575,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveBasicShape( const wxString& name, int pad_c * PAD_SMD, rectangular, H size = V size = current track width. * the "gap" is isolation created between this 2 pads */ -MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) +MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) { int oX; D_PAD* pad; @@ -603,8 +612,9 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) } wxString value = ReturnStringFromValue( g_UserUnit, gap_size, - GetScreen()->GetInternalUnits() ); + GetScreen()->GetInternalUnits() ); wxTextEntryDialog dlg( this, msg, _( "Create microwave module" ), value ); + if( dlg.ShowModal() != wxID_OK ) { DrawPanel->MoveCursorToCrossHair(); @@ -615,24 +625,30 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) gap_size = ReturnValueFromString( g_UserUnit, value, GetScreen()->GetInternalUnits() ); bool abort = false; + if( shape_type == 2 ) { double fcoeff = 10.0, fval; msg.Printf( wxT( "%3.1f" ), angle / fcoeff ); - wxTextEntryDialog angledlg( this, _( "Angle (0.1deg):" ), _( - "Create microwave module" ), msg ); + wxTextEntryDialog angledlg( this, _( "Angle (0.1deg):" ), + _( "Create microwave module" ), msg ); + if( angledlg.ShowModal() != wxID_OK ) { DrawPanel->MoveCursorToCrossHair(); return NULL; // cancelled by user } + msg = angledlg.GetValue(); + if( !msg.ToDouble( &fval ) ) { DisplayError( this, _( "Incorrect number, abort" ) ); - abort = TRUE; + abort = true; } + angle = ABS( wxRound( fval * fcoeff ) ); + if( angle > 1800 ) angle = 1800; } @@ -681,6 +697,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) polyPoints.push_back( wxPoint( 0, 0 ) ); int theta = -angle / 2; + for( int ii = 1; ii angle / 2 ) theta = angle / 2; } @@ -703,7 +721,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWaveComponent( int shape_type ) break; } - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); GetBoard()->m_Status_Pcb = 0; OnModify(); return Module; @@ -748,8 +766,7 @@ END_EVENT_TABLE() WinEDA_SetParamShapeFrame::WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent, const wxPoint& framepos ) : - wxDialog( parent, -1, _( "Complex shape" ), framepos, wxSize( 350, 280 ), - DIALOG_STYLE ) + wxDialog( parent, -1, _( "Complex shape" ), framepos, wxSize( 350, 280 ), DIALOG_STYLE ) { m_Parent = parent; @@ -772,9 +789,8 @@ WinEDA_SetParamShapeFrame::WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent, Button = new wxButton( this, wxID_CANCEL, _( "Cancel" ) ); RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 ); - Button = - new wxButton( this, ID_READ_SHAPE_FILE, - _( "Read Shape Description File..." ) ); + Button = new wxButton( this, ID_READ_SHAPE_FILE, + _( "Read Shape Description File..." ) ); RightBoxSizer->Add( Button, 0, wxGROW | wxALL, 5 ); wxString shapelist[3] = @@ -782,6 +798,7 @@ WinEDA_SetParamShapeFrame::WinEDA_SetParamShapeFrame( PCB_EDIT_FRAME* parent, _( "Normal" ), _( "Symmetrical" ), _( "Mirrored" ) }; + m_ShapeOptionCtrl = new wxRadioBox( this, -1, _( "Shape Option" ), wxDefaultPosition, wxDefaultSize, 3, shapelist, 1, @@ -801,6 +818,7 @@ void WinEDA_SetParamShapeFrame::OnCancelClick( wxCommandEvent& event ) { if( PolyEdges ) free( PolyEdges ); + PolyEdges = NULL; PolyEdgesCount = 0; EndModal( -1 ); @@ -849,7 +867,7 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) mask, this, wxFD_OPEN, - TRUE ); + true ); if( FullFileName.IsEmpty() ) return; @@ -869,6 +887,7 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) ptbuf = PolyEdges = (double*) MyZMalloc( bufsize * 2 * sizeof(double) ); SetLocaleTo_C_standard(); + while( reader.ReadLine() ) { Line = reader.Line(); @@ -879,11 +898,14 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) { if( strnicmp( param2, "inch", 4 ) == 0 ) unitconv = 10000; + if( strnicmp( param2, "mm", 2 ) == 0 ) unitconv = 10000 / 25.4; } + if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 ) break; + if( strnicmp( param1, "$COORD", 6 ) == 0 ) { while( reader.ReadLine() ) @@ -891,17 +913,19 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) Line = reader.Line(); param1 = strtok( Line, " \t\n\r" ); param2 = strtok( NULL, " \t\n\r" ); + if( strnicmp( param1, "$ENDCOORD", 8 ) == 0 ) break; + if( bufsize <= PolyEdgesCount ) { int index = ptbuf - PolyEdges; bufsize *= 2; - ptbuf = PolyEdges = (double*) realloc( - PolyEdges, bufsize * 2 * - sizeof(double) ); + ptbuf = PolyEdges = (double*) realloc( PolyEdges, bufsize * 2 * + sizeof(double) ); ptbuf += index; } + *ptbuf = atof( param1 ); ptbuf++; *ptbuf = atof( param2 ); @@ -909,10 +933,12 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) PolyEdgesCount++; } } + if( strnicmp( Line, "XScale", 6 ) == 0 ) { ShapeScaleX = atof( param2 ); } + if( strnicmp( Line, "YScale", 6 ) == 0 ) { ShapeScaleY = atof( param2 ); @@ -924,6 +950,7 @@ void WinEDA_SetParamShapeFrame::ReadDataShapeDescr( wxCommandEvent& event ) free( PolyEdges ); PolyEdges = NULL; } + SetLocaleTo_Default(); // revert to the current locale ShapeScaleX *= unitconv; @@ -942,8 +969,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape() EDGE_MODULE* edge; int ii, npoints; - WinEDA_SetParamShapeFrame* frame = new WinEDA_SetParamShapeFrame( - this, wxPoint( -1, -1 ) ); + WinEDA_SetParamShapeFrame* frame = new WinEDA_SetParamShapeFrame( this, wxPoint( -1, -1 ) ); int ok = frame->ShowModal(); @@ -955,6 +981,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape() { if( PolyEdges ) free( PolyEdges ); + PolyEdges = NULL; PolyEdgesCount = 0; return NULL; @@ -971,6 +998,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape() DisplayError( this, _( "Shape has a null size!" ) ); return NULL; } + if( PolyEdgesCount == 0 ) { DisplayError( this, _( "Shape has no points!" ) ); @@ -1005,6 +1033,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape() double* dptr = PolyEdges; wxPoint first_coordinate, last_coordinate; + for( ii = 0; ii < npoints; ii++ ) // Copy points { last_coordinate.x = wxRound( *dptr++ *ShapeScaleX ) + pad1->m_Pos0.x; @@ -1049,7 +1078,7 @@ MODULE* PCB_EDIT_FRAME::Create_MuWavePolygonShape() PolyEdgesCount = 0; PolyEdges = NULL; - Module->Set_Rectangle_Encadrement(); + Module->CalculateBoundingBox(); GetBoard()->m_Status_Pcb = 0; OnModify(); return Module; @@ -1071,16 +1100,20 @@ void PCB_EDIT_FRAME::Edit_Gap( wxDC* DC, MODULE* Module ) /* Test if module is a gap type (name begins with GAP, and has 2 pads). */ msg = Module->m_Reference->m_Text.Left( 3 ); + if( msg != wxT( "GAP" ) ) return; pad = Module->m_Pads; + if( pad == NULL ) { DisplayError( this, _( "No pad for this module" ) ); return; } + next_pad = (D_PAD*) pad->Next(); + if( next_pad == NULL ) { DisplayError( this, _( "Only one pad for this module" ) ); @@ -1095,6 +1128,7 @@ void PCB_EDIT_FRAME::Edit_Gap( wxDC* DC, MODULE* Module ) /* Entrer the desired length of the gap. */ msg = ReturnStringFromValue( g_UserUnit, gap_size, GetScreen()->GetInternalUnits() ); wxTextEntryDialog dlg( this, _( "Gap:" ), _( "Create Microwave Gap" ), msg ); + if( dlg.ShowModal() != wxID_OK ) return; // cancelled by user diff --git a/pcbnew/onleftclick.cpp b/pcbnew/onleftclick.cpp index 7449ebfeef..c9136ac373 100644 --- a/pcbnew/onleftclick.cpp +++ b/pcbnew/onleftclick.cpp @@ -72,8 +72,8 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) exit = true; break; - case TYPE_MIRE: - Place_Mire( (MIREPCB*) DrawStruct, aDC ); + case PCB_TARGET_T: + PlaceTarget( (PCB_TARGET*) DrawStruct, aDC ); exit = true; break; @@ -171,15 +171,18 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) case ID_PCB_MIRE_BUTT: if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) ) { - SetCurItem( Create_Mire( aDC ) ); + SetCurItem( CreateTarget( aDC ) ); DrawPanel->MoveCursorToCrossHair(); } - else if( DrawStruct->Type() == TYPE_MIRE ) + else if( DrawStruct->Type() == PCB_TARGET_T ) { - Place_Mire( (MIREPCB*) DrawStruct, aDC ); + PlaceTarget( (PCB_TARGET*) DrawStruct, aDC ); } else - DisplayError( this, wxT( "Internal err: Struct not TYPE_MIRE" ) ); + { + DisplayError( this, wxT( "Internal err: Struct not PCB_TARGET_T" ) ); + } + break; case ID_PCB_CIRCLE_BUTT: @@ -286,7 +289,10 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) GetScreen()->SetCurItem( DrawStruct ); } else + { DisplayError( this, wxT( "PCB_EDIT_FRAME::OnLeftClick() zone internal error" ) ); + } + break; case ID_PCB_ADD_TEXT_BUTT: @@ -302,7 +308,10 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) DrawPanel->m_AutoPAN_Request = false; } else + { DisplayError( this, wxT( "Internal err: Struct not TYPE_TEXTE" ) ); + } + break; case ID_PCB_MODULE_BUTT: @@ -311,6 +320,7 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) DrawPanel->MoveCursorToCrossHair(); DrawStruct = Load_Module_From_Library( wxEmptyString, aDC ); SetCurItem( DrawStruct ); + if( DrawStruct ) StartMove_Module( (MODULE*) DrawStruct, aDC ); } @@ -320,7 +330,10 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) DrawPanel->m_AutoPAN_Request = false; } else + { DisplayError( this, wxT( "Internal err: Struct not TYPE_MODULE" ) ); + } + break; case ID_PCB_DIMENSION_BUTT: @@ -344,20 +357,25 @@ void PCB_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) DrawPanel->m_AutoPAN_Request = true; } else + { DisplayError( this, wxT( "PCB_EDIT_FRAME::OnLeftClick() error item is not a DIMENSION" ) ); + } + break; case ID_PCB_DELETE_ITEM_BUTT: if( !DrawStruct || (DrawStruct->m_Flags == 0) ) { DrawStruct = PcbGeneralLocateAndDisplay(); + if( DrawStruct && (DrawStruct->m_Flags == 0) ) { RemoveStruct( DrawStruct, aDC ); SetCurItem( DrawStruct = NULL ); } } + break; case ID_PCB_PLACE_OFFSET_COORD_BUTT: @@ -416,12 +434,13 @@ void PCB_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition ) { Edit_TrackSegm_Width( aDC, (TRACK*) DrawStruct ); } + break; case TYPE_TEXTE: case TYPE_PAD: case TYPE_MODULE: - case TYPE_MIRE: + case PCB_TARGET_T: case TYPE_DIMENSION: case TYPE_TEXTE_MODULE: OnEditItemRequest( aDC, DrawStruct ); @@ -450,6 +469,7 @@ void PCB_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition ) if( End_Route( (TRACK*) DrawStruct, aDC ) ) DrawPanel->m_AutoPAN_Request = false; } + break; case ID_PCB_ZONES_BUTT: @@ -506,8 +526,8 @@ void PCB_EDIT_FRAME::OnEditItemRequest( wxDC* aDC, BOARD_ITEM* aItem ) InstallModuleOptionsFrame( (MODULE*) aItem, aDC ); break; - case TYPE_MIRE: - InstallMireOptionsFrame( (MIREPCB*) aItem, aDC ); + case PCB_TARGET_T: + ShowTargetOptionsDialog( (PCB_TARGET*) aItem, aDC ); break; case TYPE_DIMENSION: diff --git a/pcbnew/onrightclick.cpp b/pcbnew/onrightclick.cpp index 8afb9d9356..ebe3119704 100644 --- a/pcbnew/onrightclick.cpp +++ b/pcbnew/onrightclick.cpp @@ -23,7 +23,7 @@ bool PCB_EDIT_FRAME::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) { wxString msg; int flags = 0; - bool locate_track = FALSE; + bool locate_track = false; bool blockActive = (GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE); wxClientDC dc( DrawPanel ); @@ -223,7 +223,7 @@ bool PCB_EDIT_FRAME::OnRightClick( const wxPoint& aMousePos, wxMenu* aPopMenu ) break; - case TYPE_MIRE: + case PCB_TARGET_T: if( !flags ) { msg = AddHotkeyName( _( "Move Target" ), g_Board_Editor_Hokeys_Descr, diff --git a/pcbnew/pcbnew_config.cpp b/pcbnew/pcbnew_config.cpp index 9b5aad62ee..70ffc1f324 100644 --- a/pcbnew/pcbnew_config.cpp +++ b/pcbnew/pcbnew_config.cpp @@ -2,13 +2,13 @@ /** pcbnew_config.cpp : configuration **/ /****************************************/ -#include - #include "fctsys.h" #include "appl_wxstruct.h" #include "class_drawpanel.h" #include "confirm.h" #include "gestfich.h" +#include "xnode.h" + #include "pcbnew.h" #include "wxPcbStruct.h" #include "class_board_design_settings.h" @@ -405,7 +405,7 @@ PARAM_CFG_ARRAY& PCB_EDIT_FRAME::GetConfigurationSettings() m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "TwoSegT" ), &g_TwoSegmentTrackBuild, true ) ); m_configSettings.push_back( new PARAM_CFG_BOOL( true, wxT( "SegmPcb45Only" ), &Segments_45_Only, - true ) ); + true ) ); return m_configSettings; } @@ -416,8 +416,8 @@ void PCB_EDIT_FRAME::SaveMacros() { wxFileName fn; wxXmlDocument xml; - wxXmlNode *rootNode = new wxXmlNode::wxXmlNode( NULL, wxXML_ELEMENT_NODE, wxT( "macrosrootnode" ), wxEmptyString, NULL); - wxXmlNode *macrosNode, *hkNode; + XNODE *rootNode = new XNODE( wxXML_ELEMENT_NODE, wxT( "macrosrootnode" ), wxEmptyString ); + XNODE *macrosNode, *hkNode; wxXmlProperty *macrosProp, *hkProp, *xProp, *yProp; wxString str, hkStr, xStr, yStr; @@ -432,29 +432,33 @@ void PCB_EDIT_FRAME::SaveMacros() xml.SetRoot( rootNode ); - for( int number = 9; number >= 0; number--) + for( int number = 9; number >= 0; number-- ) { - str.Printf( wxT( "%d" ), number); - macrosProp = new wxXmlProperty::wxXmlProperty( wxT("number"), str); + str.Printf( wxT( "%d" ), number ); + macrosProp = new wxXmlProperty( wxT( "number" ), str ); - macrosNode = new wxXmlNode::wxXmlNode(rootNode, wxXML_ELEMENT_NODE, wxT( "macros" ), wxEmptyString, macrosProp); + macrosNode = new XNODE( rootNode, wxXML_ELEMENT_NODE, wxT( "macros" ), wxEmptyString, + macrosProp ); - for( std::list::reverse_iterator i = m_Macros[number].m_Record.rbegin(); i != m_Macros[number].m_Record.rend(); i++ ) + for( std::list::reverse_iterator i = m_Macros[number].m_Record.rbegin(); + i != m_Macros[number].m_Record.rend(); + i++ ) { - hkStr.Printf( wxT( "%d" ), i->m_HotkeyCode); - xStr.Printf( wxT( "%d" ), i->m_Position.x); - yStr.Printf( wxT( "%d" ), i->m_Position.y); + hkStr.Printf( wxT( "%d" ), i->m_HotkeyCode ); + xStr.Printf( wxT( "%d" ), i->m_Position.x ); + yStr.Printf( wxT( "%d" ), i->m_Position.y ); - yProp = new wxXmlProperty( wxT( "y" ), yStr); - xProp = new wxXmlProperty( wxT( "x" ), xStr, yProp); - hkProp = new wxXmlProperty( wxT( "hkcode" ), hkStr, xProp); + yProp = new wxXmlProperty( wxT( "y" ), yStr ); + xProp = new wxXmlProperty( wxT( "x" ), xStr, yProp ); + hkProp = new wxXmlProperty( wxT( "hkcode" ), hkStr, xProp ); - hkNode = new wxXmlNode(macrosNode, wxXML_ELEMENT_NODE, wxT( "hotkey" ), wxEmptyString, hkProp); + hkNode = new XNODE( macrosNode, wxXML_ELEMENT_NODE, wxT( "hotkey" ), + wxEmptyString, hkProp ); } } - xml.SetFileEncoding(wxT("UTF-8")); - xml.Save(dlg.GetFilename()); + xml.SetFileEncoding( wxT("UTF-8") ); + xml.Save( dlg.GetFilename() ); } @@ -485,11 +489,12 @@ void PCB_EDIT_FRAME::ReadMacros() wxXmlDocument xml; - xml.SetFileEncoding(wxT("UTF-8")); + xml.SetFileEncoding( wxT( "UTF-8" ) ); + if( !xml.Load( dlg.GetFilename() ) ) return; - wxXmlNode *macrosNode = xml.GetRoot()->GetChildren(); + XNODE *macrosNode = (XNODE*) xml.GetRoot()->GetChildren(); while( macrosNode ) { @@ -497,34 +502,34 @@ void PCB_EDIT_FRAME::ReadMacros() if( macrosNode->GetName() == wxT( "macros" ) ) { - number = wxAtoi( macrosNode->GetPropVal( wxT( "number" ), wxT( "-1" ) ) ); + number = wxAtoi( macrosNode->GetAttribute( wxT( "number" ), wxT( "-1" ) ) ); if( number >= 0 && number < 10 ) { m_Macros[number].m_Record.clear(); - wxXmlNode *hotkeyNode = macrosNode->GetChildren(); + XNODE *hotkeyNode = (XNODE*) macrosNode->GetChildren(); + while( hotkeyNode ) { if( hotkeyNode->GetName() == wxT( "hotkey" ) ) { - int x = wxAtoi( hotkeyNode->GetPropVal( wxT( "x" ), wxT( "0" ) ) ); - int y = wxAtoi( hotkeyNode->GetPropVal( wxT( "y" ), wxT( "0" ) ) ); - int hk = wxAtoi( hotkeyNode->GetPropVal( wxT( "hkcode" ), wxT( "0" ) ) ); + int x = wxAtoi( hotkeyNode->GetAttribute( wxT( "x" ), wxT( "0" ) ) ); + int y = wxAtoi( hotkeyNode->GetAttribute( wxT( "y" ), wxT( "0" ) ) ); + int hk = wxAtoi( hotkeyNode->GetAttribute( wxT( "hkcode" ), wxT( "0" ) ) ); MACROS_RECORD macros_record; macros_record.m_HotkeyCode = hk; macros_record.m_Position.x = x; macros_record.m_Position.y = y; - m_Macros[number].m_Record.push_back(macros_record); + m_Macros[number].m_Record.push_back( macros_record ); } - hotkeyNode = hotkeyNode->GetNext(); + hotkeyNode = (XNODE*) hotkeyNode->GetNext(); } } } - macrosNode = macrosNode->GetNext(); + macrosNode = (XNODE*) macrosNode->GetNext(); } - } diff --git a/pcbnew/pcbplot.h b/pcbnew/pcbplot.h index 0ef3985ea2..68b2fa3d07 100644 --- a/pcbnew/pcbplot.h +++ b/pcbnew/pcbplot.h @@ -38,8 +38,8 @@ void PlotDrawSegment( PLOTTER* plotter, DRAWSEGMENT* PtSegm, int masque_layer, void PlotDimension( PLOTTER* plotter, DIMENSION* Dimension, int masque_layer, GRTraceMode trace_mode ); -void PlotMirePcb( PLOTTER* plotter, MIREPCB* PtMire, int masque_layer, - GRTraceMode trace_mode ); +void PlotPcbTarget( PLOTTER* plotter, PCB_TARGET* PtMire, int masque_layer, + GRTraceMode trace_mode ); void Plot_1_EdgeModule( PLOTTER* plotter, EDGE_MODULE* PtEdge, GRTraceMode trace_mode ); diff --git a/pcbnew/plot_rtn.cpp b/pcbnew/plot_rtn.cpp index ad4bc1c486..54fe7ede52 100644 --- a/pcbnew/plot_rtn.cpp +++ b/pcbnew/plot_rtn.cpp @@ -14,7 +14,7 @@ #include "class_board_design_settings.h" -static void Plot_Edges_Modules( PLOTTER* plotter, BOARD* pcb, int masque_layer, +static void Plot_Edges_Modules( PLOTTER* plotter, BOARD* pcb, int aLayerMask, GRTraceMode trace_mode ); static void PlotTextModule( PLOTTER* plotter, TEXTE_MODULE* pt_texte, GRTraceMode trace_mode ); @@ -23,7 +23,7 @@ static void PlotTextModule( PLOTTER* plotter, TEXTE_MODULE* pt_texte, /* Creates the plot for silkscreen layers */ void PCB_BASE_FRAME::Plot_Serigraphie( PLOTTER* plotter, - int masque_layer, + int aLayerMask, GRTraceMode trace_mode ) { bool trace_val, trace_ref; @@ -37,19 +37,19 @@ void PCB_BASE_FRAME::Plot_Serigraphie( PLOTTER* plotter, switch( PtStruct->Type() ) { case TYPE_DRAWSEGMENT: - PlotDrawSegment( plotter, (DRAWSEGMENT*) PtStruct, masque_layer, trace_mode ); + PlotDrawSegment( plotter, (DRAWSEGMENT*) PtStruct, aLayerMask, trace_mode ); break; case TYPE_TEXTE: - PlotTextePcb( plotter, (TEXTE_PCB*) PtStruct, masque_layer, trace_mode ); + PlotTextePcb( plotter, (TEXTE_PCB*) PtStruct, aLayerMask, trace_mode ); break; case TYPE_DIMENSION: - PlotDimension( plotter, (DIMENSION*) PtStruct, masque_layer, trace_mode ); + PlotDimension( plotter, (DIMENSION*) PtStruct, aLayerMask, trace_mode ); break; - case TYPE_MIRE: - PlotMirePcb( plotter, (MIREPCB*) PtStruct, masque_layer, trace_mode ); + case PCB_TARGET_T: + PlotPcbTarget( plotter, (PCB_TARGET*) PtStruct, aLayerMask, trace_mode ); break; case TYPE_MARKER_PCB: @@ -62,13 +62,15 @@ void PCB_BASE_FRAME::Plot_Serigraphie( PLOTTER* plotter, } /* Plot footprint outlines : */ - Plot_Edges_Modules( plotter, m_Pcb, masque_layer, trace_mode ); + Plot_Edges_Modules( plotter, m_Pcb, aLayerMask, trace_mode ); /* Plot pads (creates pads outlines, for pads on silkscreen layers) */ - int layersmask_plotpads = masque_layer; + int layersmask_plotpads = aLayerMask; // Calculate the mask layers of allowed layers for pads + if( !g_PcbPlotOptions.m_PlotPadsOnSilkLayer ) // Do not plot pads on silk screen layers layersmask_plotpads &= ~(SILKSCREEN_LAYER_BACK | SILKSCREEN_LAYER_FRONT ); + if( layersmask_plotpads ) { for( MODULE* Module = m_Pcb->m_Modules; Module; Module = Module->Next() ) @@ -76,7 +78,7 @@ void PCB_BASE_FRAME::Plot_Serigraphie( PLOTTER* plotter, for( D_PAD * pad = Module->m_Pads; pad != NULL; pad = pad->Next() ) { /* See if the pad is on this layer */ - if( (pad->m_Masque_Layer & layersmask_plotpads) == 0 ) + if( (pad->m_layerMask & layersmask_plotpads) == 0 ) continue; wxPoint shape_pos = pad->ReturnShapePos(); @@ -129,11 +131,11 @@ module\n %s's \"reference\" text." ), return; } - if( ( ( 1 << textLayer ) & masque_layer ) == 0 ) - trace_ref = FALSE; + if( ( ( 1 << textLayer ) & aLayerMask ) == 0 ) + trace_ref = false; if( text->m_NoShow && !g_PcbPlotOptions.m_PlotInvisibleTexts ) - trace_ref = FALSE; + trace_ref = false; text = Module->m_Value; textLayer = text->GetLayer(); @@ -149,11 +151,11 @@ module\n %s's \"value\" text." ), return; } - if( ( (1 << textLayer) & masque_layer ) == 0 ) - trace_val = FALSE; + if( ( (1 << textLayer) & aLayerMask ) == 0 ) + trace_val = false; if( text->m_NoShow && !g_PcbPlotOptions.m_PlotInvisibleTexts ) - trace_val = FALSE; + trace_val = false; /* Plot text fields, if allowed */ if( trace_ref ) @@ -171,11 +173,12 @@ module\n %s's \"value\" text." ), if( !g_PcbPlotOptions.m_PlotTextOther ) continue; - if( (pt_texte->m_NoShow) - && !g_PcbPlotOptions.m_PlotInvisibleTexts ) + + if( (pt_texte->m_NoShow) && !g_PcbPlotOptions.m_PlotInvisibleTexts ) continue; textLayer = pt_texte->GetLayer(); + if( textLayer >= 32 ) { wxString errMsg; @@ -188,7 +191,7 @@ for module\n %s's \"module text\" text of %s." ), return; } - if( !( ( 1 << textLayer ) & masque_layer ) ) + if( !( ( 1 << textLayer ) & aLayerMask ) ) continue; PlotTextModule( plotter, pt_texte, trace_mode ); @@ -199,8 +202,10 @@ for module\n %s's \"module text\" text of %s." ), for( int ii = 0; ii < m_Pcb->GetAreaCount(); ii++ ) { ZONE_CONTAINER* edge_zone = m_Pcb->GetArea( ii ); - if( ( ( 1 << edge_zone->GetLayer() ) & masque_layer ) == 0 ) + + if( ( ( 1 << edge_zone->GetLayer() ) & aLayerMask ) == 0 ) continue; + PlotFilledAreas( plotter, edge_zone, trace_mode ); } @@ -208,16 +213,15 @@ for module\n %s's \"module text\" text of %s." ), // compatibility): for( SEGZONE* seg = m_Pcb->m_Zone; seg != NULL; seg = seg->Next() ) { - if( ( ( 1 << seg->GetLayer() ) & masque_layer ) == 0 ) + if( ( ( 1 << seg->GetLayer() ) & aLayerMask ) == 0 ) continue; - plotter->thick_segment( seg->m_Start, seg->m_End, seg->m_Width, - trace_mode ); + + plotter->thick_segment( seg->m_Start, seg->m_End, seg->m_Width, trace_mode ); } } -static void PlotTextModule( PLOTTER* plotter, TEXTE_MODULE* pt_texte, - GRTraceMode trace_mode ) +static void PlotTextModule( PLOTTER* plotter, TEXTE_MODULE* pt_texte, GRTraceMode trace_mode ) { wxSize size; wxPoint pos; @@ -230,6 +234,7 @@ static void PlotTextModule( PLOTTER* plotter, TEXTE_MODULE* pt_texte, orient = pt_texte->GetDrawRotation(); thickness = pt_texte->m_Thickness; + if( trace_mode == FILAIRE ) thickness = -1; @@ -250,12 +255,12 @@ static void PlotTextModule( PLOTTER* plotter, TEXTE_MODULE* pt_texte, } -void PlotDimension( PLOTTER* plotter, DIMENSION* Dimension, int masque_layer, +void PlotDimension( PLOTTER* plotter, DIMENSION* Dimension, int aLayerMask, GRTraceMode trace_mode ) { DRAWSEGMENT* DrawTmp; - if( (g_TabOneLayerMask[Dimension->GetLayer()] & masque_layer) == 0 ) + if( (g_TabOneLayerMask[Dimension->GetLayer()] & aLayerMask) == 0 ) return; DrawTmp = new DRAWSEGMENT( NULL ); @@ -263,61 +268,60 @@ void PlotDimension( PLOTTER* plotter, DIMENSION* Dimension, int masque_layer, DrawTmp->m_Width = (trace_mode==FILAIRE) ? -1 : Dimension->m_Width; DrawTmp->SetLayer( Dimension->GetLayer() ); - PlotTextePcb( plotter, Dimension->m_Text, masque_layer, trace_mode ); + PlotTextePcb( plotter, Dimension->m_Text, aLayerMask, trace_mode ); DrawTmp->m_Start.x = Dimension->Barre_ox; DrawTmp->m_Start.y = Dimension->Barre_oy; DrawTmp->m_End.x = Dimension->Barre_fx; DrawTmp->m_End.y = Dimension->Barre_fy; - PlotDrawSegment( plotter, DrawTmp, masque_layer, trace_mode ); + PlotDrawSegment( plotter, DrawTmp, aLayerMask, trace_mode ); DrawTmp->m_Start.x = Dimension->TraitG_ox; DrawTmp->m_Start.y = Dimension->TraitG_oy; DrawTmp->m_End.x = Dimension->TraitG_fx; DrawTmp->m_End.y = Dimension->TraitG_fy; - PlotDrawSegment( plotter, DrawTmp, masque_layer, trace_mode ); + PlotDrawSegment( plotter, DrawTmp, aLayerMask, trace_mode ); DrawTmp->m_Start.x = Dimension->TraitD_ox; DrawTmp->m_Start.y = Dimension->TraitD_oy; DrawTmp->m_End.x = Dimension->TraitD_fx; DrawTmp->m_End.y = Dimension->TraitD_fy; - PlotDrawSegment( plotter, DrawTmp, masque_layer, trace_mode ); + PlotDrawSegment( plotter, DrawTmp, aLayerMask, trace_mode ); DrawTmp->m_Start.x = Dimension->FlecheD1_ox; DrawTmp->m_Start.y = Dimension->FlecheD1_oy; DrawTmp->m_End.x = Dimension->FlecheD1_fx; DrawTmp->m_End.y = Dimension->FlecheD1_fy; - PlotDrawSegment( plotter, DrawTmp, masque_layer, trace_mode ); + PlotDrawSegment( plotter, DrawTmp, aLayerMask, trace_mode ); DrawTmp->m_Start.x = Dimension->FlecheD2_ox; DrawTmp->m_Start.y = Dimension->FlecheD2_oy; DrawTmp->m_End.x = Dimension->FlecheD2_fx; DrawTmp->m_End.y = Dimension->FlecheD2_fy; - PlotDrawSegment( plotter, DrawTmp, masque_layer, trace_mode ); + PlotDrawSegment( plotter, DrawTmp, aLayerMask, trace_mode ); DrawTmp->m_Start.x = Dimension->FlecheG1_ox; DrawTmp->m_Start.y = Dimension->FlecheG1_oy; DrawTmp->m_End.x = Dimension->FlecheG1_fx; DrawTmp->m_End.y = Dimension->FlecheG1_fy; - PlotDrawSegment( plotter, DrawTmp, masque_layer, trace_mode ); + PlotDrawSegment( plotter, DrawTmp, aLayerMask, trace_mode ); DrawTmp->m_Start.x = Dimension->FlecheG2_ox; DrawTmp->m_Start.y = Dimension->FlecheG2_oy; DrawTmp->m_End.x = Dimension->FlecheG2_fx; DrawTmp->m_End.y = Dimension->FlecheG2_fy; - PlotDrawSegment( plotter, DrawTmp, masque_layer, trace_mode ); + PlotDrawSegment( plotter, DrawTmp, aLayerMask, trace_mode ); delete DrawTmp; } -void PlotMirePcb( PLOTTER* plotter, MIREPCB* Mire, int masque_layer, - GRTraceMode trace_mode ) +void PlotPcbTarget( PLOTTER* plotter, PCB_TARGET* Mire, int aLayerMask, GRTraceMode trace_mode ) { DRAWSEGMENT* DrawTmp; int dx1, dx2, dy1, dy2, radius; - if( (g_TabOneLayerMask[Mire->GetLayer()] & masque_layer) == 0 ) + if( (g_TabOneLayerMask[Mire->GetLayer()] & aLayerMask) == 0 ) return; DrawTmp = new DRAWSEGMENT( NULL ); @@ -329,7 +333,7 @@ void PlotMirePcb( PLOTTER* plotter, MIREPCB* Mire, int masque_layer, DrawTmp->m_End.x = DrawTmp->m_Start.x + ( Mire->m_Size / 4 ); DrawTmp->m_End.y = DrawTmp->m_Start.y; DrawTmp->m_Shape = S_CIRCLE; - PlotDrawSegment( plotter, DrawTmp, masque_layer, trace_mode ); + PlotDrawSegment( plotter, DrawTmp, aLayerMask, trace_mode ); DrawTmp->m_Shape = S_SEGMENT; @@ -350,20 +354,20 @@ void PlotMirePcb( PLOTTER* plotter, MIREPCB* Mire, int masque_layer, DrawTmp->m_Start.y = Mire->m_Pos.y - dy1; DrawTmp->m_End.x = Mire->m_Pos.x + dx1; DrawTmp->m_End.y = Mire->m_Pos.y + dy1; - PlotDrawSegment( plotter, DrawTmp, masque_layer, trace_mode ); + PlotDrawSegment( plotter, DrawTmp, aLayerMask, trace_mode ); DrawTmp->m_Start.x = Mire->m_Pos.x - dx2; DrawTmp->m_Start.y = Mire->m_Pos.y - dy2; DrawTmp->m_End.x = Mire->m_Pos.x + dx2; DrawTmp->m_End.y = Mire->m_Pos.y + dy2; - PlotDrawSegment( plotter, DrawTmp, masque_layer, trace_mode ); + PlotDrawSegment( plotter, DrawTmp, aLayerMask, trace_mode ); delete DrawTmp; } /* Plot footprints graphic items (outlines) */ -void Plot_Edges_Modules( PLOTTER* plotter, BOARD* pcb, int masque_layer, +void Plot_Edges_Modules( PLOTTER* plotter, BOARD* pcb, int aLayerMask, GRTraceMode trace_mode ) { for( MODULE* module = pcb->m_Modules; module; module = module->Next() ) @@ -375,7 +379,7 @@ void Plot_Edges_Modules( PLOTTER* plotter, BOARD* pcb, int masque_layer, if( edge->Type() != TYPE_EDGE_MODULE ) continue; - if( ( g_TabOneLayerMask[edge->GetLayer()] & masque_layer ) == 0 ) + if( ( g_TabOneLayerMask[edge->GetLayer()] & aLayerMask ) == 0 ) continue; Plot_1_EdgeModule( plotter, edge, trace_mode ); @@ -431,6 +435,7 @@ void Plot_1_EdgeModule( PLOTTER* plotter, EDGE_MODULE* PtEdge, case S_POLYGON: { std::vector polyPoints = PtEdge->GetPolyPoints(); + if( polyPoints.size() <= 1 ) // Malformed polygon break; @@ -462,7 +467,7 @@ void Plot_1_EdgeModule( PLOTTER* plotter, EDGE_MODULE* PtEdge, /* Plot a PCB Text, i;e. a text found on a copper or technical layer */ -void PlotTextePcb( PLOTTER* plotter, TEXTE_PCB* pt_texte, int masque_layer, +void PlotTextePcb( PLOTTER* plotter, TEXTE_PCB* pt_texte, int aLayerMask, GRTraceMode trace_mode ) { int orient, thickness; @@ -471,7 +476,8 @@ void PlotTextePcb( PLOTTER* plotter, TEXTE_PCB* pt_texte, int masque_layer, if( pt_texte->m_Text.IsEmpty() ) return; - if( ( g_TabOneLayerMask[pt_texte->GetLayer()] & masque_layer ) == 0 ) + + if( ( g_TabOneLayerMask[pt_texte->GetLayer()] & aLayerMask ) == 0 ) return; size = pt_texte->m_Size; @@ -496,6 +502,7 @@ void PlotTextePcb( PLOTTER* plotter, TEXTE_PCB* pt_texte, int masque_layer, offset.y = pt_texte->GetInterline(); RotatePoint( &offset, orient ); + for( unsigned i = 0; i < list->Count(); i++ ) { wxString txt = list->Item( i ); @@ -510,20 +517,22 @@ void PlotTextePcb( PLOTTER* plotter, TEXTE_PCB* pt_texte, int masque_layer, delete (list); } else + { plotter->text( pos, BLACK, pt_texte->m_Text, orient, size, pt_texte->m_HJustify, pt_texte->m_VJustify, thickness, pt_texte->m_Italic, allow_bold ); + } } /* Plot areas (given by .m_FilledPolysList member) in a zone */ -void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone, - GRTraceMode trace_mode ) +void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone, GRTraceMode trace_mode ) { unsigned imax = aZone->m_FilledPolysList.size(); + if( imax == 0 ) // Nothing to draw return; @@ -541,6 +550,7 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone, { CPolyPt* corner = &aZone->m_FilledPolysList[ic]; cornerList.push_back( wxPoint( corner->x, corner->y) ); + if( corner->end_contour ) // Plot the current filled area outline { // First, close the outline @@ -554,14 +564,12 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone, { // Plot the current filled area polygon if( aZone->m_FillMode == 0 ) // We are using solid polygons - // (if != 0: using segments ) + { // (if != 0: using segments ) plotter->PlotPoly( cornerList, FILLED_SHAPE ); + } else // We are using areas filled by - // segments: plot them ) - { - for( unsigned iseg = 0; - iseg < aZone->m_FillSegmList.size(); - iseg++ ) + { // segments: plot them ) + for( unsigned iseg = 0; iseg < aZone->m_FillSegmList.size(); iseg++ ) { wxPoint start = aZone->m_FillSegmList[iseg].m_Start; wxPoint end = aZone->m_FillSegmList[iseg].m_End; @@ -581,28 +589,30 @@ void PlotFilledAreas( PLOTTER* plotter, ZONE_CONTAINER* aZone, if( aZone->m_ZoneMinThickness > 0 ) { for( unsigned jj = 1; jjthick_segment(cornerList[jj -1], cornerList[jj], - ( trace_mode == FILAIRE ) ? -1 : aZone->m_ZoneMinThickness, - trace_mode ); + plotter->thick_segment( cornerList[jj -1], cornerList[jj], + ( trace_mode == FILAIRE ) ? -1 : aZone->m_ZoneMinThickness, + trace_mode ); } + plotter->set_current_line_width( -1 ); } + cornerList.clear(); } } } -/* Plot items type DRAWSEGMENT on layers allowed by masque_layer +/* Plot items type DRAWSEGMENT on layers allowed by aLayerMask */ -void PlotDrawSegment( PLOTTER* plotter, DRAWSEGMENT* pt_segm, int masque_layer, +void PlotDrawSegment( PLOTTER* plotter, DRAWSEGMENT* pt_segm, int aLayerMask, GRTraceMode trace_mode ) { wxPoint start, end; int thickness; int radius = 0, StAngle = 0, EndAngle = 0; - if( (g_TabOneLayerMask[pt_segm->GetLayer()] & masque_layer) == 0 ) + if( (g_TabOneLayerMask[pt_segm->GetLayer()] & aLayerMask) == 0 ) return; if( trace_mode == FILAIRE ) @@ -614,27 +624,21 @@ void PlotDrawSegment( PLOTTER* plotter, DRAWSEGMENT* pt_segm, int masque_layer, end = pt_segm->m_End; plotter->set_current_line_width( thickness ); + switch( pt_segm->m_Shape ) { case S_CIRCLE: - radius = - (int) hypot( (double) ( end.x - start.x ), - (double) ( end.y - start.y ) ); + radius = (int) hypot( (double) ( end.x - start.x ), + (double) ( end.y - start.y ) ); plotter->thick_circle( start, radius * 2, thickness, trace_mode ); break; case S_ARC: - radius = - (int) hypot( (double) ( end.x - start.x ), - (double) ( end.y - start.y ) ); + radius = (int) hypot( (double) ( end.x - start.x ), + (double) ( end.y - start.y ) ); StAngle = ArcTangente( end.y - start.y, end.x - start.x ); EndAngle = StAngle + pt_segm->m_Angle; - plotter->thick_arc( start, - -EndAngle, - -StAngle, - radius, - thickness, - trace_mode ); + plotter->thick_arc( start, -EndAngle, -StAngle, radius, thickness, trace_mode ); break; case S_CURVE: @@ -684,8 +688,7 @@ void PCB_BASE_FRAME::Plot_Layer( PLOTTER* plotter, int Layer, GRTraceMode trace_ Plot_Standard_Layer( plotter, layer_mask, true, trace_mode, g_PcbPlotOptions.m_SkipNPTH_Pads ); - // Adding drill marks, if required and if the plotter is able to plot - // them: + // Adding drill marks, if required and if the plotter is able to plot them: if( g_PcbPlotOptions.m_DrillShapeOpt != PCB_PLOT_PARAMS::NO_DRILL_SHAPE ) { if( plotter->GetPlotterType() == PLOT_FORMAT_POST ) @@ -693,6 +696,7 @@ void PCB_BASE_FRAME::Plot_Layer( PLOTTER* plotter, int Layer, GRTraceMode trace_ g_PcbPlotOptions.m_DrillShapeOpt == PCB_PLOT_PARAMS::SMALL_DRILL_SHAPE ); } + break; case SOLDERMASK_N_BACK: @@ -728,6 +732,7 @@ void PCB_BASE_FRAME::Plot_Layer( PLOTTER* plotter, int Layer, GRTraceMode trace_ g_PcbPlotOptions.m_PlotViaOnMaskLayer, trace_mode ); } + break; } } @@ -752,10 +757,7 @@ void PCB_BASE_FRAME::Plot_Standard_Layer( PLOTTER* aPlotter, switch( item->Type() ) { case TYPE_DRAWSEGMENT: - PlotDrawSegment( aPlotter, - (DRAWSEGMENT*) item, - aLayerMask, - aPlotMode ); + PlotDrawSegment( aPlotter, (DRAWSEGMENT*) item, aLayerMask, aPlotMode ); break; case TYPE_TEXTE: @@ -766,8 +768,8 @@ void PCB_BASE_FRAME::Plot_Standard_Layer( PLOTTER* aPlotter, PlotDimension( aPlotter, (DIMENSION*) item, aLayerMask, aPlotMode ); break; - case TYPE_MIRE: - PlotMirePcb( aPlotter, (MIREPCB*) item, aLayerMask, aPlotMode ); + case PCB_TARGET_T: + PlotPcbTarget( aPlotter, (PCB_TARGET*) item, aLayerMask, aPlotMode ); break; case TYPE_MARKER_PCB: @@ -788,9 +790,8 @@ void PCB_BASE_FRAME::Plot_Standard_Layer( PLOTTER* aPlotter, { case TYPE_EDGE_MODULE: if( aLayerMask & g_TabOneLayerMask[ item->GetLayer() ] ) - Plot_1_EdgeModule( aPlotter, - (EDGE_MODULE*) item, - aPlotMode ); + Plot_1_EdgeModule( aPlotter, (EDGE_MODULE*) item, aPlotMode ); + break; default: @@ -805,12 +806,14 @@ void PCB_BASE_FRAME::Plot_Standard_Layer( PLOTTER* aPlotter, for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() ) { wxPoint shape_pos; - if( (pad->m_Masque_Layer & aLayerMask) == 0 ) + + if( (pad->m_layerMask & aLayerMask) == 0 ) continue; shape_pos = pad->ReturnShapePos(); pos = shape_pos; wxSize margin; + switch( aLayerMask & ( SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT | SOLDERPASTE_LAYER_BACK | SOLDERPASTE_LAYER_FRONT ) ) @@ -843,6 +846,7 @@ void PCB_BASE_FRAME::Plot_Standard_Layer( PLOTTER* aPlotter, (pad->m_Size == pad->m_Drill) && (pad->m_Attribut == PAD_HOLE_NOT_PLATED) ) break; + aPlotter->flash_pad_circle( pos, size.x, aPlotMode ); break; @@ -851,6 +855,7 @@ void PCB_BASE_FRAME::Plot_Standard_Layer( PLOTTER* aPlotter, (pad->m_Size == pad->m_Drill) && (pad->m_Attribut == PAD_HOLE_NOT_PLATED) ) break; + aPlotter->flash_pad_oval( pos, size, pad->m_Orient, aPlotMode ); break; @@ -884,10 +889,13 @@ void PCB_BASE_FRAME::Plot_Standard_Layer( PLOTTER* aPlotter, // is SOLDERMASK_LAYER_BACK or SOLDERMASK_LAYER_FRONT,vias are drawn, // if they are on an external copper layer int via_mask_layer = Via->ReturnMaskLayer(); + if( via_mask_layer & LAYER_BACK ) via_mask_layer |= SOLDERMASK_LAYER_BACK; + if( via_mask_layer & LAYER_FRONT ) via_mask_layer |= SOLDERMASK_LAYER_FRONT; + if( ( via_mask_layer & aLayerMask ) == 0 ) continue; @@ -897,6 +905,7 @@ void PCB_BASE_FRAME::Plot_Standard_Layer( PLOTTER* aPlotter, // clearance for vias if( ( aLayerMask & ( SOLDERMASK_LAYER_BACK | SOLDERMASK_LAYER_FRONT ) ) ) via_margin = GetBoard()->GetBoardDesignSettings()->m_SolderMaskMargin; + pos = Via->m_Start; size.x = size.y = Via->m_Width + 2 * via_margin; @@ -945,8 +954,10 @@ void PCB_BASE_FRAME::Plot_Standard_Layer( PLOTTER* aPlotter, for( int ii = 0; ii < m_Pcb->GetAreaCount(); ii++ ) { ZONE_CONTAINER* edge_zone = m_Pcb->GetArea( ii ); + if( ( ( 1 << edge_zone->GetLayer() ) & aLayerMask ) == 0 ) continue; + PlotFilledAreas( aPlotter, edge_zone, aPlotMode ); } } @@ -982,7 +993,9 @@ void PCB_BASE_FRAME::PlotDrillMark( PLOTTER* aPlotter, { if( pts->Type() != TYPE_VIA ) continue; + pos = pts->m_Start; + if( g_PcbPlotOptions.m_DrillShapeOpt == PCB_PLOT_PARAMS::SMALL_DRILL_SHAPE ) diam.x = diam.y = SMALL_DRILL; else @@ -991,26 +1004,20 @@ void PCB_BASE_FRAME::PlotDrillMark( PLOTTER* aPlotter, aPlotter->flash_pad_circle( pos, diam.x, aTraceMode ); } - for( Module = m_Pcb->m_Modules; - Module != NULL; - Module = Module->Next() ) + for( Module = m_Pcb->m_Modules; Module != NULL; Module = Module->Next() ) { - for( PtPad = Module->m_Pads; - PtPad != NULL; - PtPad = PtPad->Next() ) + for( PtPad = Module->m_Pads; PtPad != NULL; PtPad = PtPad->Next() ) { if( PtPad->m_Drill.x == 0 ) continue; // Output hole shapes: pos = PtPad->m_Pos; + if( PtPad->m_DrillShape == PAD_OVAL ) { diam = PtPad->m_Drill; - aPlotter->flash_pad_oval( pos, - diam, - PtPad->m_Orient, - aTraceMode ); + aPlotter->flash_pad_oval( pos, diam, PtPad->m_Orient, aTraceMode ); } else { diff --git a/pcbnew/plothpgl.cpp b/pcbnew/plothpgl.cpp index eaa7f3d899..73851b32ed 100644 --- a/pcbnew/plothpgl.cpp +++ b/pcbnew/plothpgl.cpp @@ -18,29 +18,34 @@ bool PCB_BASE_FRAME::Genere_HPGL( const wxString& FullFileName, int Layer, GRTra wxSize SheetSize; wxSize BoardSize; wxPoint BoardCenter; - bool Center = FALSE; + bool Center = false; Ki_PageDescr* currentsheet = GetScreen()->m_CurrentSheetDesc; double scale; wxPoint offset; FILE* output_file = wxFopen( FullFileName, wxT( "wt" ) ); + if( output_file == NULL ) { return false; } + // Compute pen_dim (from g_m_HPGLPenDiam in mils) in pcb units, // with plot scale (if Scale is 2, pen diameter is always g_m_HPGLPenDiam // so apparent pen diam is real pen diam / Scale - int pen_diam = wxRound( (g_PcbPlotOptions.m_HPGLPenDiam * U_PCB) / g_PcbPlotOptions.m_PlotScale ); + int pen_diam = wxRound( (g_PcbPlotOptions.m_HPGLPenDiam * U_PCB) / + g_PcbPlotOptions.m_PlotScale ); // compute pen_overlay (from g_m_HPGLPenOvr in mils) // with plot scale if( g_PcbPlotOptions.m_HPGLPenOvr < 0 ) g_PcbPlotOptions.m_HPGLPenOvr = 0; + if( g_PcbPlotOptions.m_HPGLPenOvr >= g_PcbPlotOptions.m_HPGLPenDiam ) g_PcbPlotOptions.m_HPGLPenOvr = g_PcbPlotOptions.m_HPGLPenDiam - 1; - int pen_overlay = wxRound( - g_PcbPlotOptions.m_HPGLPenOvr * 10.0 / g_PcbPlotOptions.m_PlotScale ); + + int pen_overlay = wxRound( g_PcbPlotOptions.m_HPGLPenOvr * 10.0 / + g_PcbPlotOptions.m_PlotScale ); SetLocaleTo_C_standard(); @@ -68,7 +73,9 @@ bool PCB_BASE_FRAME::Genere_HPGL( const wxString& FullFileName, int Layer, GRTra scale = MIN( Xscale, Yscale ); } else + { scale = g_PcbPlotOptions.m_PlotScale; + } // Calculate the page size offset. if( Center ) diff --git a/pcbnew/plotps.cpp b/pcbnew/plotps.cpp index 5068eb45b6..c35d0e4db1 100644 --- a/pcbnew/plotps.cpp +++ b/pcbnew/plotps.cpp @@ -23,13 +23,14 @@ bool PCB_BASE_FRAME::Genere_PS( const wxString& FullFileName, int Layer, wxSize PaperSize; wxSize BoardSize; wxPoint BoardCenter; - bool Center = FALSE; + bool Center = false; Ki_PageDescr* currentsheet = GetScreen()->m_CurrentSheetDesc; double scale, paperscale; Ki_PageDescr* SheetPS; wxPoint offset; FILE* output_file = wxFopen( FullFileName, wxT( "wt" ) ); + if( output_file == NULL ) { return false; @@ -80,10 +81,8 @@ bool PCB_BASE_FRAME::Genere_PS( const wxString& FullFileName, int Layer, if( Center ) { - offset.x = wxRound( (double) BoardCenter.x - - ( (double) PaperSize.x / 2.0 ) / scale ); - offset.y = wxRound( (double) BoardCenter.y - - ( (double) PaperSize.y / 2.0 ) / scale ); + offset.x = wxRound( (double) BoardCenter.x - ( (double) PaperSize.x / 2.0 ) / scale ); + offset.y = wxRound( (double) BoardCenter.y - ( (double) PaperSize.y / 2.0 ) / scale ); } else { diff --git a/pcbnew/print_board_functions.cpp b/pcbnew/print_board_functions.cpp index 6aa10bdbf5..2a49d83f29 100644 --- a/pcbnew/print_board_functions.cpp +++ b/pcbnew/print_board_functions.cpp @@ -113,17 +113,19 @@ void PCB_EDIT_FRAME::PrintPage( wxDC* aDC, { MODULE* Module; int drawmode = GR_COPY; - DISPLAY_OPTIONS save_opt; - TRACK* pt_piste; - BOARD* Pcb = GetBoard(); - int defaultPenSize = 50; - bool onePagePerLayer = false; + DISPLAY_OPTIONS save_opt; + TRACK* pt_trace; + BOARD* Pcb = GetBoard(); + int defaultPenSize = 50; + bool onePagePerLayer = false; PRINT_PARAMETERS * printParameters = (PRINT_PARAMETERS*) aData; // can be null + if( printParameters && printParameters->m_OptionPrintPage == 0 ) onePagePerLayer = true; PRINT_PARAMETERS::DrillShapeOptT drillShapeOpt = PRINT_PARAMETERS::FULL_DRILL_SHAPE; + if( printParameters ) { drillShapeOpt = printParameters->m_DrillShapeOpt; @@ -140,14 +142,15 @@ void PCB_EDIT_FRAME::PrintPage( wxDC* aDC, if( (aPrintMaskLayer & ALL_CU_LAYERS) == 0 ) { if( onePagePerLayer ) - { // We can print mask layers (solder mask and solder paste) with the actual pad sizes - // To do that, we must set ContrastModeDisplay to true and set the GetScreen()->m_Active_Layer - // to the current printed layer + { // We can print mask layers (solder mask and solder paste) with the actual + // pad sizes. To do that, we must set ContrastModeDisplay to true and set + //the GetScreen()->m_Active_Layer to the current printed layer DisplayOpt.ContrastModeDisplay = true; DisplayOpt.DisplayPadFill = true; // Calculate the active layer number to print from its mask layer: GetScreen()->m_Active_Layer = 0; + for(int kk = 0; kk < 32; kk ++ ) { if( ((1 << kk) & aPrintMaskLayer) != 0 ) @@ -203,7 +206,7 @@ void PCB_EDIT_FRAME::PrintPage( wxDC* aDC, case TYPE_DRAWSEGMENT: case TYPE_DIMENSION: case TYPE_TEXTE: - case TYPE_MIRE: + case PCB_TARGET_T: if( ( ( 1 << item->GetLayer() ) & aPrintMaskLayer ) == 0 ) break; @@ -217,38 +220,38 @@ void PCB_EDIT_FRAME::PrintPage( wxDC* aDC, } /* Print tracks */ - pt_piste = Pcb->m_Track; + pt_trace = Pcb->m_Track; - for( ; pt_piste != NULL; pt_piste = pt_piste->Next() ) + for( ; pt_trace != NULL; pt_trace = pt_trace->Next() ) { - if( ( aPrintMaskLayer & pt_piste->ReturnMaskLayer() ) == 0 ) + if( ( aPrintMaskLayer & pt_trace->ReturnMaskLayer() ) == 0 ) continue; - if( pt_piste->Type() == TYPE_VIA ) /* VIA encountered. */ + if( pt_trace->Type() == TYPE_VIA ) /* VIA encountered. */ { - int rayon = pt_piste->m_Width >> 1; - int color = g_ColorsSettings.GetItemColor(VIAS_VISIBLE+pt_piste->m_Shape); + int radius = pt_trace->m_Width >> 1; + int color = g_ColorsSettings.GetItemColor( VIAS_VISIBLE + pt_trace->m_Shape ); GRSetDrawMode( aDC, drawmode ); GRFilledCircle( &DrawPanel->m_ClipBox, aDC, - pt_piste->m_Start.x, - pt_piste->m_Start.y, - rayon, + pt_trace->m_Start.x, + pt_trace->m_Start.y, + radius, 0, color, color ); } else { - pt_piste->Draw( DrawPanel, aDC, drawmode ); + pt_trace->Draw( DrawPanel, aDC, drawmode ); } } - pt_piste = Pcb->m_Zone; + pt_trace = Pcb->m_Zone; - for( ; pt_piste != NULL; pt_piste = pt_piste->Next() ) + for( ; pt_trace != NULL; pt_trace = pt_trace->Next() ) { - if( ( aPrintMaskLayer & pt_piste->ReturnMaskLayer() ) == 0 ) + if( ( aPrintMaskLayer & pt_trace->ReturnMaskLayer() ) == 0 ) continue; - pt_piste->Draw( DrawPanel, aDC, drawmode ); + pt_trace->Draw( DrawPanel, aDC, drawmode ); } /* Draw filled areas (i.e. zones) */ @@ -279,28 +282,28 @@ void PCB_EDIT_FRAME::PrintPage( wxDC* aDC, * vias */ if( drillShapeOpt != PRINT_PARAMETERS::NO_DRILL_SHAPE ) { - pt_piste = Pcb->m_Track; + pt_trace = Pcb->m_Track; int color = g_DrawBgColor; bool blackpenstate = GetGRForceBlackPenState(); GRForceBlackPen( false ); GRSetDrawMode( aDC, GR_COPY ); - for( ; pt_piste != NULL; pt_piste = pt_piste->Next() ) + for( ; pt_trace != NULL; pt_trace = pt_trace->Next() ) { - if( ( aPrintMaskLayer & pt_piste->ReturnMaskLayer() ) == 0 ) + if( ( aPrintMaskLayer & pt_trace->ReturnMaskLayer() ) == 0 ) continue; - if( pt_piste->Type() == TYPE_VIA ) /* VIA encountered. */ + if( pt_trace->Type() == TYPE_VIA ) /* VIA encountered. */ { int diameter; if( drillShapeOpt == PRINT_PARAMETERS::SMALL_DRILL_SHAPE ) - diameter = min( SMALL_DRILL, pt_piste->GetDrillValue() ); + diameter = min( SMALL_DRILL, pt_trace->GetDrillValue() ); else - diameter = pt_piste->GetDrillValue(); + diameter = pt_trace->GetDrillValue(); GRFilledCircle( &DrawPanel->m_ClipBox, aDC, - pt_piste->m_Start.x, pt_piste->m_Start.y, + pt_trace->m_Start.x, pt_trace->m_Start.y, diameter/2, 0, color, color ); } @@ -337,7 +340,7 @@ static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule, for( ; pt_pad != NULL; pt_pad = pt_pad->Next() ) { - if( (pt_pad->m_Masque_Layer & aMasklayer ) == 0 ) + if( (pt_pad->m_layerMask & aMasklayer ) == 0 ) continue; // Manage hole according to the print drill option @@ -394,8 +397,10 @@ static void Print_Module( EDA_DRAW_PANEL* aPanel, wxDC* aDC, MODULE* aModule, case TYPE_EDGE_MODULE: { EDGE_MODULE* edge = (EDGE_MODULE*) PtStruct; + if( ( g_TabOneLayerMask[edge->GetLayer()] & aMasklayer ) == 0 ) break; + edge->Draw( aPanel, aDC, aDraw_mode ); break; } diff --git a/pcbnew/protos.h b/pcbnew/protos.h index 25cd00f64b..6e50cefda1 100644 --- a/pcbnew/protos.h +++ b/pcbnew/protos.h @@ -55,11 +55,11 @@ void CreateSortedPadListByXCoord( BOARD* aBoard, std::vector* aVector ); * The starting point of a track following MUST exist: may be * Then put a 0 before calling a routine if the track is the last draw */ -void Trace_Une_Piste( EDA_DRAW_PANEL* panel, - wxDC* DC, - TRACK* pt_start_piste, - int nbsegment, - int mode_color ); +void DrawTraces( EDA_DRAW_PANEL* panel, + wxDC* DC, + TRACK* aStartTrace, + int nbsegment, + int mode_color ); /****************/ @@ -67,7 +67,7 @@ void Trace_Une_Piste( EDA_DRAW_PANEL* panel, /****************/ /* Find a pad by it's name om the module. */ -TRACK* Locate_Via( BOARD* Pcb, const wxPoint& pos, int layer = -1 ); +TRACK* Locate_Via( BOARD* Pcb, const wxPoint& pos, int layer = -1 ); /** * Function Locate_Via_Area @@ -89,8 +89,7 @@ TRACK* Fast_Locate_Via( TRACK* start_adr, TRACK* end_adr, const wxPoint& pos, in * by masquelayer. * Search is done to address start_adr has end_adr (not included) */ -TRACK* Fast_Locate_Piste( TRACK* start_adr, TRACK* end_adr, - const wxPoint& ref_pos, int masquelayer ); +TRACK* GetTrace( TRACK* start_adr, TRACK* end_adr, const wxPoint& ref_pos, int masquelayer ); /* Search for segment connected to the segment edge by * Ptr_piste: @@ -99,7 +98,7 @@ TRACK* Fast_Locate_Piste( TRACK* start_adr, TRACK* end_adr, * The search is done only on the ends of segments * The search is limited to the area [... pt_base] pt_lim. */ -TRACK* Locate_Piste_Connectee( TRACK* ptr_piste, TRACK* pt_base, TRACK* pt_lim, int extr ); +TRACK* GetConnectedTrace( TRACK* aTrace, TRACK* pt_base, TRACK* pt_lim, int extr ); /* * 1 - Locate segment of track leading from the mouse. @@ -110,7 +109,7 @@ TRACK* Locate_Piste_Connectee( TRACK* ptr_piste, TRACK* pt_base, TRACK* pt_lim, * * The search begins to address start_adresse */ -TRACK* Locate_Pistes( BOARD* aPcb, TRACK* start_adresse, const wxPoint& ref_pos, int layer ); +TRACK* GetTrace( BOARD* aPcb, TRACK* start_adresse, const wxPoint& ref_pos, int layer ); /* Locate pad connected to the beginning or end of a segment * Input: pointer to the segment, and flag = START or END @@ -158,7 +157,7 @@ D_PAD* Locate_Pads( MODULE* Module, int typeloc ); /* Locate a trace segment at the current cursor position. * The search begins to address start_adresse. */ -TRACK* Locate_Pistes( TRACK* start_adresse, int typeloc ); +TRACK* GetTrace( TRACK* start_adresse, int typeloc ); DRAWSEGMENT* Locate_Segment_Pcb( BOARD* Pcb, int LayerSearch, int typeloc ); @@ -187,8 +186,7 @@ TRACK* Locate_Zone( TRACK* start_adresse, const wxPoint& ref_pos, int layer ); /*************/ int ChangeSideNumLayer( int oldlayer ); void DrawModuleOutlines( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* module ); -void Montre_Position_Empreinte( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, - bool aErase ); +void MoveFootprint( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ); /****************/ @@ -203,7 +201,7 @@ void ShowNewTrackWhenMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPo /* Determine coordinate for a segment direction of 0, 90 or 45 degrees, * depending on it's position from the origin (ox, oy) and \a aPosiition.. */ -void Calcule_Coord_Extremite_45( const wxPoint& aPosition, int ox, int oy, int* fx, int* fy ); +void CalculateSegmentEndPoint( const wxPoint& aPosition, int ox, int oy, int* fx, int* fy ); /*****************/ @@ -211,7 +209,7 @@ void Calcule_Coord_Extremite_45( const wxPoint& aPosition, int ox, int oy, int* /*****************/ /** - * Function Marque_Une_Piste + * Function MarkTrace * marks a chain of track segments, connected to aTrackList. * Each segment is marked by setting the BUSY bit into m_Flags. Electrical * continuity is detected by walking each segment, and finally the segments @@ -234,12 +232,12 @@ void Calcule_Coord_Extremite_45( const wxPoint& aPosition, int ox, int oy, int* * track length in this case, flags are reset * @return TRACK* the first in the chain of interesting segments. */ -TRACK* Marque_Une_Piste( BOARD* aPcb, - TRACK* aStartSegm, - int* aSegmCount, - int* aTrackLen, - int* aLengthDie, - bool aReorder ); +TRACK* MarkTrace( BOARD* aPcb, + TRACK* aStartSegm, + int* aSegmCount, + int* aTrackLen, + int* aLengthDie, + bool aReorder ); /* Calculate end coordinate of a trace. * Returns 1 if OK, 0 if trace looped back on itself. @@ -247,7 +245,7 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, * And EndTrack-> fx, fy if OK * The segments are drawn consecutively. */ -int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, TRACK** StartTrack, TRACK** EndTrack ); +int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, TRACK** StartTrack, TRACK** EndTrack ); /***************/ @@ -279,10 +277,10 @@ BOARD_ITEM* LocateLockPoint( BOARD* aPcb, wxPoint aPos, int aLayerMask ); * Returns the exact value of aRefPoint and a pointer to the via, * But does not create extra point */ -TRACK* CreateLockPoint( BOARD* aPcb, - wxPoint& aRefPoint, - TRACK* aSegm, - PICKED_ITEMS_LIST* aItemsListPicker ); +TRACK* CreateLockPoint( BOARD* aPcb, + wxPoint& aRefPoint, + TRACK* aSegm, + PICKED_ITEMS_LIST* aItemsListPicker ); /****************/ diff --git a/pcbnew/ratsnest.cpp b/pcbnew/ratsnest.cpp index d616f72bdc..3fc111f053 100644 --- a/pcbnew/ratsnest.cpp +++ b/pcbnew/ratsnest.cpp @@ -116,7 +116,7 @@ void PCB_BASE_FRAME::Compile_Ratsnest( wxDC* aDC, bool aDisplayStatus ) { wxString msg; - DisplayRastnestInProgress = TRUE; + DisplayRastnestInProgress = true; GetBoard()->m_Status_Pcb = 0; /* we want a full ratsnest computation, * from the scratch */ @@ -203,7 +203,8 @@ static int sort_by_length( const void* o1, const void* o2 ) * @param aPadIdxMax = ending index (within the pad list) for search * @return blocks not connected count */ -static int gen_rats_block_to_block( +static int gen_rats_block_to_block +( std::vector& aRatsnestBuffer, std::vector& aPadBuffer, unsigned aPadIdxStart, @@ -271,8 +272,10 @@ static int gen_rats_block_to_block( } if( padBlock1Idx < 0 ) + { DisplayError( NULL, wxT( "gen_rats_block_to_block() internal error" ) ); + } else { /* Create the new ratsnest */ @@ -285,6 +288,7 @@ static int gen_rats_block_to_block( aRatsnestBuffer.push_back( net ); } } + return current_num_block; } @@ -355,11 +359,9 @@ static int gen_rats_pad_to_pad( vector& aRatsnestBuffer, /* Update the block number * if the 2 pads are not already created : a new block is created */ - if( (pad->GetSubRatsnest() == 0) - && (ref_pad->GetSubRatsnest() == 0) ) + if( (pad->GetSubRatsnest() == 0) && (ref_pad->GetSubRatsnest() == 0) ) { - current_num_block++; // Creates a new block number (or - // subratsnest) + current_num_block++; // Creates a new block number (or subratsnest) pad->SetSubRatsnest( current_num_block ); ref_pad->SetSubRatsnest( current_num_block ); } @@ -437,7 +439,7 @@ void PCB_BASE_FRAME::Build_Board_Ratsnest( wxDC* DC ) return; /* No useful connections. */ /* Ratsnest computation */ - DisplayRastnestInProgress = TRUE; + DisplayRastnestInProgress = true; unsigned current_net_code = 1; // First net code is analyzed. // (net_code = 0 -> no connect) @@ -446,19 +448,23 @@ void PCB_BASE_FRAME::Build_Board_Ratsnest( wxDC* DC ) for( ; current_net_code < m_Pcb->m_NetInfo->GetCount(); current_net_code++ ) { NETINFO_ITEM* net = m_Pcb->FindNet( current_net_code ); + if( net == NULL ) //Should not occur { DisplayError( this, wxT( "Build_Board_Ratsnest() error: net not found" ) ); return; } + net->m_RatsnestStartIdx = m_Pcb->GetRatsnestsCount(); // Search for the last subratsnest already in use int num_block = 0; + for( unsigned ii = 0; ii < net->m_ListPad.size(); ii++ ) { pad = net->m_ListPad[ii]; + if( num_block < pad->GetSubRatsnest() ) num_block = pad->GetSubRatsnest(); } @@ -486,6 +492,7 @@ void PCB_BASE_FRAME::Build_Board_Ratsnest( wxDC* DC ) /* sort by length */ net = m_Pcb->FindNet( current_net_code ); + if( ( net->m_RatsnestEndIdx - net->m_RatsnestStartIdx ) > 1 ) { RATSNEST_ITEM* rats = &m_Pcb->m_FullRatsnest[0]; @@ -522,14 +529,19 @@ void PCB_BASE_FRAME::DrawGeneralRatsnest( wxDC* aDC, int aNetcode ) { if( ( m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK ) == 0 ) return; + if( ( m_Pcb->m_Status_Pcb & DO_NOT_SHOW_GENERAL_RASTNEST ) ) return; + if( aDC == NULL ) return; + int state = CH_VISIBLE | CH_ACTIF; + for( unsigned ii = 0; ii < m_Pcb->GetRatsnestsCount(); ii++ ) { RATSNEST_ITEM& item = m_Pcb->m_FullRatsnest[ii]; + if( ( item.m_Status & state ) != state ) continue; @@ -565,13 +577,12 @@ static int tst_rats_block_to_block( NETINFO_ITEM* net, /* Search a link from a block to an other block */ min_rats = NULL; - for( unsigned ii = net->m_RatsnestStartIdx; - ii < net->m_RatsnestEndIdx; - ii++ ) + + for( unsigned ii = net->m_RatsnestStartIdx; ii < net->m_RatsnestEndIdx; ii++ ) { rats = &aRatsnestBuffer[ii]; - if( rats->m_PadStart->GetSubRatsnest() == - rats->m_PadEnd->GetSubRatsnest() ) // Same block + + if( rats->m_PadStart->GetSubRatsnest() == rats->m_PadEnd->GetSubRatsnest() ) // Same block continue; if( min_rats == NULL ) @@ -631,35 +642,33 @@ static int tst_rats_pad_to_pad( int current_num_block, RATSNEST_ITEM* end_rat_list ) { D_PAD* pad_start, * pad_end; - RATSNEST_ITEM* chevelu; + RATSNEST_ITEM* item; - for( chevelu = start_rat_list; chevelu < end_rat_list; chevelu++ ) + for( item = start_rat_list; item < end_rat_list; item++ ) { - pad_start = chevelu->m_PadStart; - pad_end = chevelu->m_PadEnd; + pad_start = item->m_PadStart; + pad_end = item->m_PadEnd; - /* Update the block if the 2 pads are not connected : a new block is - * created + /* Update the block if the 2 pads are not connected : a new block is created */ - if( (pad_start->GetSubRatsnest() == 0) - && (pad_end->GetSubRatsnest() == 0) ) + if( (pad_start->GetSubRatsnest() == 0) && (pad_end->GetSubRatsnest() == 0) ) { current_num_block++; pad_start->SetSubRatsnest( current_num_block ); pad_end->SetSubRatsnest( current_num_block ); - chevelu->m_Status |= CH_ACTIF; + item->m_Status |= CH_ACTIF; } - /* If a pad is already connected : the other is merged in the current - * block */ + + /* If a pad is already connected : the other is merged in the current block */ else if( pad_start->GetSubRatsnest() == 0 ) { pad_start->SetSubRatsnest( pad_end->GetSubRatsnest() ); - chevelu->m_Status |= CH_ACTIF; + item->m_Status |= CH_ACTIF; } else if( pad_end->GetSubRatsnest() == 0 ) { pad_end->SetSubRatsnest( pad_start->GetSubRatsnest() ); - chevelu->m_Status |= CH_ACTIF; + item->m_Status |= CH_ACTIF; } } @@ -680,14 +689,14 @@ void PCB_BASE_FRAME::Tst_Ratsnest( wxDC* DC, int ref_netcode ) if( m_Pcb->GetPadsCount() == 0 ) return; + if( (m_Pcb->m_Status_Pcb & LISTE_RATSNEST_ITEM_OK) == 0 ) Build_Board_Ratsnest( DC ); - for( int net_code = 1; - net_code < (int) m_Pcb->m_NetInfo->GetCount(); - net_code++ ) + for( int net_code = 1; net_code < (int) m_Pcb->m_NetInfo->GetCount(); net_code++ ) { net = m_Pcb->FindNet( net_code ); + if( net == NULL ) //Should not occur { DisplayError( this, wxT( "Tst_Ratsnest() error: net not found" ) ); @@ -698,6 +707,7 @@ void PCB_BASE_FRAME::Tst_Ratsnest( wxDC* DC, int ref_netcode ) continue; int num_block = 0; + for( unsigned ip = 0; ip < net->m_ListPad.size(); ip++ ) { pad = net->m_ListPad[ip]; @@ -706,9 +716,7 @@ void PCB_BASE_FRAME::Tst_Ratsnest( wxDC* DC, int ref_netcode ) num_block = MAX( num_block, subnet ); } - for( unsigned ii = net->m_RatsnestStartIdx; - ii < net->m_RatsnestEndIdx; - ii++ ) + for( unsigned ii = net->m_RatsnestStartIdx; ii < net->m_RatsnestEndIdx; ii++ ) { m_Pcb->m_FullRatsnest[ii].m_Status &= ~CH_ACTIF; } @@ -727,6 +735,7 @@ void PCB_BASE_FRAME::Tst_Ratsnest( wxDC* DC, int ref_netcode ) } m_Pcb->m_NbNoconnect = 0; + for( unsigned ii = 0; ii < m_Pcb->GetRatsnestsCount(); ii++ ) { if( m_Pcb->m_FullRatsnest[ii].m_Status & CH_ACTIF ) @@ -743,7 +752,7 @@ void PCB_BASE_FRAME::Tst_Ratsnest( wxDC* DC, int ref_netcode ) */ int PCB_BASE_FRAME::Test_1_Net_Ratsnest( wxDC* aDC, int aNetcode ) { - DisplayRastnestInProgress = FALSE; + DisplayRastnestInProgress = false; DrawGeneralRatsnest( aDC, aNetcode ); Tst_Ratsnest( aDC, aNetcode ); DrawGeneralRatsnest( aDC, aNetcode ); @@ -811,27 +820,27 @@ void PCB_BASE_FRAME::build_ratsnest_module( MODULE* aModule ) } pads_module_count = s_localPadBuffer.size(); + if( pads_module_count == 0 ) return; /* no connection! */ - qsort( &s_localPadBuffer[0], - pads_module_count, - sizeof(D_PAD*), - sortByNetcode ); + qsort( &s_localPadBuffer[0], pads_module_count, sizeof( D_PAD* ), sortByNetcode ); /* Build the list of pads linked to the current footprint pads */ - DisplayRastnestInProgress = FALSE; + DisplayRastnestInProgress = false; current_net_code = 0; + for( unsigned ii = 0; ii < pads_module_count; ii++ ) { pad_ref = s_localPadBuffer[ii]; + if( pad_ref->GetNet() == current_net_code ) continue; - // A new net was found, load all pads of others modules members of this - // net: + // A new net was found, load all pads of others modules members of this net: NETINFO_ITEM* net = m_Pcb->FindNet( pad_ref->GetNet() ); + if( net == NULL ) //Should not occur { DisplayError( this, @@ -842,6 +851,7 @@ void PCB_BASE_FRAME::build_ratsnest_module( MODULE* aModule ) for( unsigned jj = 0; jj < net->m_ListPad.size(); jj++ ) { pad_externe = net->m_ListPad[jj]; + if( pad_externe->GetParent() == aModule ) continue; @@ -854,8 +864,8 @@ void PCB_BASE_FRAME::build_ratsnest_module( MODULE* aModule ) /* Sort the pad list by net_code */ baseListePad = &s_localPadBuffer[0]; - qsort( baseListePad + pads_module_count, - s_localPadBuffer.size() - pads_module_count, + + qsort( baseListePad + pads_module_count, s_localPadBuffer.size() - pads_module_count, sizeof(D_PAD*), sortByNetcode ); /* Compute the internal rats nest: @@ -869,6 +879,7 @@ void PCB_BASE_FRAME::build_ratsnest_module( MODULE* aModule ) { /* Search the end of pad list relative to the current net */ unsigned jj = ii + 1; + for( ; jj <= pads_module_count; jj++ ) { if( jj >= pads_module_count ) @@ -880,20 +891,17 @@ void PCB_BASE_FRAME::build_ratsnest_module( MODULE* aModule ) /* End of list found: */ /* a - first step of lee algorithm : build the pad to pad link list */ - int icnt = gen_rats_pad_to_pad( m_Pcb->m_LocalRatsnest, - s_localPadBuffer, - ii, jj, 0 ); + int icnt = gen_rats_pad_to_pad( m_Pcb->m_LocalRatsnest, s_localPadBuffer, ii, jj, 0 ); /* b - second step of lee algorithm : build the block to block link *list (Iteration) */ while( icnt > 1 ) { - icnt = gen_rats_block_to_block( m_Pcb->m_LocalRatsnest, - s_localPadBuffer, - ii, jj ); + icnt = gen_rats_block_to_block( m_Pcb->m_LocalRatsnest, s_localPadBuffer, ii, jj ); } ii = jj; + if( ii < s_localPadBuffer.size() ) current_net_code = s_localPadBuffer[ii]->GetNet(); } @@ -926,14 +934,15 @@ CalculateExternalRatsnest: local_rats.m_Status = 0; bool addRats = false; if( internalRatsCount < m_Pcb->m_LocalRatsnest.size() ) - m_Pcb->m_LocalRatsnest.erase( - m_Pcb->m_LocalRatsnest.begin() + internalRatsCount, - m_Pcb->m_LocalRatsnest.end() ); + m_Pcb->m_LocalRatsnest.erase( m_Pcb->m_LocalRatsnest.begin() + internalRatsCount, + m_Pcb->m_LocalRatsnest.end() ); current_net_code = s_localPadBuffer[0]->GetNet(); + for( unsigned ii = 0; ii < pads_module_count; ii++ ) { pad_ref = s_localPadBuffer[ii]; + if( pad_ref->GetNet() != current_net_code ) { /* if needed, creates a new ratsnest for the old net */ @@ -941,6 +950,7 @@ CalculateExternalRatsnest: { m_Pcb->m_LocalRatsnest.push_back( local_rats ); } + addRats = false; current_net_code = pad_ref->GetNet(); local_rats.m_Lenght = 0x7FFFFFFF; @@ -949,9 +959,7 @@ CalculateExternalRatsnest: pad_pos = pad_ref->m_Pos - g_Offset_Module; // Search the nearest external pad of this current pad - for( unsigned jj = pads_module_count; - jj < s_localPadBuffer.size(); - jj++ ) + for( unsigned jj = pads_module_count; jj < s_localPadBuffer.size(); jj++ ) { pad_externe = s_localPadBuffer[jj]; @@ -959,9 +967,7 @@ CalculateExternalRatsnest: if( pad_externe->GetNet() < pad_ref->GetNet() ) continue; - if( pad_externe->GetNet() > pad_ref->GetNet() ) // remember pads - // are sorted by - // net code + if( pad_externe->GetNet() > pad_ref->GetNet() ) // pads are sorted by net code break; distance = abs( pad_externe->m_Pos.x - pad_pos.x ) + @@ -993,13 +999,16 @@ void PCB_BASE_FRAME::trace_ratsnest_module( wxDC* DC ) { if( DC == NULL ) return; + if( ( m_Pcb->m_Status_Pcb & RATSNEST_ITEM_LOCAL_OK ) == 0 ) return; int tmpcolor = g_ColorsSettings.GetItemColor(RATSNEST_VISIBLE); + for( unsigned ii = 0; ii < m_Pcb->m_LocalRatsnest.size(); ii++ ) { RATSNEST_ITEM* rats = &m_Pcb->m_LocalRatsnest[ii]; + if( rats->m_Status & LOCAL_RATSNEST_ITEM ) { g_ColorsSettings.SetItemColor(RATSNEST_VISIBLE, YELLOW); @@ -1073,9 +1082,11 @@ void PCB_BASE_FRAME::build_ratsnest_pad( BOARD_ITEM* ref, const wxPoint& refpos, } s_CursorPos = refpos; + if( init ) { s_RatsnestMouseToPads.clear(); + if( ref == NULL ) return; @@ -1107,8 +1118,7 @@ void PCB_BASE_FRAME::build_ratsnest_pad( BOARD_ITEM* ref, const wxPoint& refpos, if( net == NULL ) // Should not occur { - DisplayError( this, - wxT( "build_ratsnest_pad() error: net not found" ) ); + DisplayError( this, wxT( "build_ratsnest_pad() error: net not found" ) ); return; } @@ -1117,6 +1127,7 @@ void PCB_BASE_FRAME::build_ratsnest_pad( BOARD_ITEM* ref, const wxPoint& refpos, for( unsigned ii = 0; ii < net->m_ListPad.size(); ii++ ) { D_PAD* pad = net->m_ListPad[ii]; + if( pad == pad_ref ) continue; @@ -1126,8 +1137,7 @@ void PCB_BASE_FRAME::build_ratsnest_pad( BOARD_ITEM* ref, const wxPoint& refpos, } /* end if Init */ if( s_RatsnestMouseToPads.size() > 1 ) - sort( s_RatsnestMouseToPads.begin(), - s_RatsnestMouseToPads.end(), sort_by_localnetlength ); + sort( s_RatsnestMouseToPads.begin(), s_RatsnestMouseToPads.end(), sort_by_localnetlength ); } @@ -1144,12 +1154,12 @@ void PCB_BASE_FRAME::trace_ratsnest_pad( wxDC* DC ) GRSetDrawMode( DC, GR_XOR ); + for( int ii = 0; ii < (int) s_RatsnestMouseToPads.size(); ii++ ) { if( ii >= g_MaxLinksShowed ) break; - GRLine( &DrawPanel->m_ClipBox, DC, s_CursorPos, - s_RatsnestMouseToPads[ii], 0, YELLOW ); + GRLine( &DrawPanel->m_ClipBox, DC, s_CursorPos, s_RatsnestMouseToPads[ii], 0, YELLOW ); } } diff --git a/pcbnew/solve.cpp b/pcbnew/solve.cpp index f5e3800a63..86a20a2eec 100644 --- a/pcbnew/solve.cpp +++ b/pcbnew/solve.cpp @@ -23,6 +23,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, int row_target, int col_target, RATSNEST_ITEM* pt_chevelu ); + static int Retrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC, int, @@ -31,13 +32,15 @@ static int Retrace( PCB_EDIT_FRAME* pcbframe, int, int, int net_code ); + static void OrCell_Trace( BOARD* pcb, int col, int row, int side, int orient, int current_net_code ); -static void Place_Piste_en_Buffer( PCB_EDIT_FRAME* pcbframe, wxDC* DC ); + +static void AddNewTrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC ); static int segm_oX, segm_oY; @@ -260,7 +263,9 @@ int PCB_EDIT_FRAME::Solve( wxDC* DC, int two_sides ) break; } else + { DrawPanel->m_AbortRequest = 0; + } } EraseMsgBox(); @@ -375,15 +380,12 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, int newdist, olddir, _self; int current_net_code; int marge; - int pad_masque_layer_s; /* Mask layers belonging to the - *starting pad. */ - int pad_masque_layer_e; /* Mask layers belonging to the ending - *pad. */ - int masque_layer_TOP = g_TabOneLayerMask[Route_Layer_TOP]; - int masque_layer_BOTTOM = g_TabOneLayerMask[Route_Layer_BOTTOM]; - int masque_layers; /* Mask two layers for routing. */ - int tab_mask[2]; /* Enables the calculation of the mask - * layer being + int padLayerMaskStart; /* Mask layers belonging to the starting pad. */ + int padLayerMaskEnd; /* Mask layers belonging to the ending pad. */ + int topLayerMask = g_TabOneLayerMask[Route_Layer_TOP]; + int bottomLayerMask = g_TabOneLayerMask[Route_Layer_BOTTOM]; + int routeLayerMask; /* Mask two layers for routing. */ + int tab_mask[2]; /* Enables the calculation of the mask layer being * tested. (side = TOP or BOTTOM) */ int start_mask_layer = 0; wxString msg; @@ -393,8 +395,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, result = NOSUCCESS; - marge = s_Clearance + - ( pcbframe->GetBoard()->GetCurrentTrackWidth() / 2 ); + marge = s_Clearance + ( pcbframe->GetBoard()->GetCurrentTrackWidth() / 2 ); /* clear direction flags */ i = Nrows * Ncols * sizeof(DIR_CELL); @@ -404,23 +405,24 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, lastopen = lastclos = lastmove = 0; /* Set tab_masque[side] for final test of routing. */ - tab_mask[TOP] = masque_layer_TOP; - tab_mask[BOTTOM] = masque_layer_BOTTOM; + tab_mask[TOP] = topLayerMask; + tab_mask[BOTTOM] = bottomLayerMask; /* Set active layers mask. */ - masque_layers = masque_layer_TOP | masque_layer_BOTTOM; + routeLayerMask = topLayerMask | bottomLayerMask; pt_cur_ch = pt_chevelu; current_net_code = pt_chevelu->GetNet(); - pad_masque_layer_s = pt_cur_ch->m_PadStart->m_Masque_Layer; - pad_masque_layer_e = pt_cur_ch->m_PadEnd->m_Masque_Layer; + padLayerMaskStart = pt_cur_ch->m_PadStart->m_layerMask; + padLayerMaskEnd = pt_cur_ch->m_PadEnd->m_layerMask; /* First Test if routing possible ie if the pads are accessible * on the routing layers. */ - if( ( masque_layers & pad_masque_layer_s ) == 0 ) + if( ( routeLayerMask & padLayerMaskStart ) == 0 ) goto end_of_route; - if( ( masque_layers & pad_masque_layer_e ) == 0 ) + + if( ( routeLayerMask & padLayerMaskEnd ) == 0 ) goto end_of_route; /* Then test if routing possible ie if the pads are accessible @@ -438,6 +440,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, if( ( ( pt_cur_ch->m_PadStart->m_Orient / 900 ) & 1 ) != 0 ) EXCHG( dx, dy ); + if( ( abs( cX - px ) > dx ) || ( abs( cY - py ) > dy ) ) goto end_of_route; @@ -449,6 +452,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, dy = pt_cur_ch->m_PadEnd->m_Size.y / 2; px = pt_cur_ch->m_PadEnd->GetPosition().x; py = pt_cur_ch->m_PadEnd->GetPosition().y; + if( ( (pt_cur_ch->m_PadEnd->m_Orient / 900) & 1 ) != 0 ) EXCHG( dx, dy ); @@ -458,7 +462,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, /* Test the trivial case: direct connection overlay pads. */ if( ( row_source == row_target ) && ( col_source == col_target ) - && ( pad_masque_layer_e & pad_masque_layer_s & + && ( padLayerMaskEnd & padLayerMaskStart & g_TabAllCopperLayerMask[pcbframe->GetBoard()->GetCopperLayerCount() - 1] ) ) { result = TRIVIAL_SUCCESS; @@ -477,13 +481,15 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, * bits precedent) */ i = pcbframe->GetBoard()->GetPadsCount(); + for( unsigned ii = 0; ii < pcbframe->GetBoard()->GetPadsCount(); ii++ ) { + D_PAD* ptr = pcbframe->GetBoard()->m_NetInfo->GetPad( ii ); + if( ( pt_cur_ch->m_PadStart != ptr ) && ( pt_cur_ch->m_PadEnd != ptr ) ) { - Place_1_Pad_Board( pcbframe->GetBoard(), ptr, ~CURRENT_PAD, - marge, WRITE_AND_CELL ); + Place_1_Pad_Board( pcbframe->GetBoard(), ptr, ~CURRENT_PAD, marge, WRITE_AND_CELL ); } } @@ -495,16 +501,18 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, { if( abs( row_target - row_source ) > abs( col_target - col_source ) ) { - if( pad_masque_layer_s & masque_layer_TOP ) + if( padLayerMaskStart & topLayerMask ) { start_mask_layer = 2; + if( SetQueue( row_source, col_source, TOP, 0, apx_dist, row_target, col_target ) == 0 ) { return ERR_MEMORY; } } - if( pad_masque_layer_s & masque_layer_BOTTOM ) + + if( padLayerMaskStart & bottomLayerMask ) { start_mask_layer |= 1; @@ -517,16 +525,18 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, } else { - if( pad_masque_layer_s & masque_layer_BOTTOM ) + if( padLayerMaskStart & bottomLayerMask ) { start_mask_layer = 1; + if( SetQueue( row_source, col_source, BOTTOM, 0, apx_dist, row_target, col_target ) == 0 ) { return ERR_MEMORY; } } - if( pad_masque_layer_s & masque_layer_TOP ) + + if( padLayerMaskStart & topLayerMask ) { start_mask_layer |= 2; @@ -538,12 +548,11 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, } } } - else if( pad_masque_layer_s & masque_layer_BOTTOM ) + else if( padLayerMaskStart & bottomLayerMask ) { start_mask_layer = 1; - if( SetQueue( row_source, col_source, BOTTOM, 0, apx_dist, - row_target, col_target ) == 0 ) + if( SetQueue( row_source, col_source, BOTTOM, 0, apx_dist, row_target, col_target ) == 0 ) { return ERR_MEMORY; } @@ -551,13 +560,16 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, /* search until success or we exhaust all possibilities */ GetQueue( &r, &c, &side, &d, &apx_dist ); + for( ; r != ILLEGAL; GetQueue( &r, &c, &side, &d, &apx_dist ) ) { curcell = GetCell( r, c, side ); + if( curcell & CURRENT_PAD ) curcell &= ~HOLE; + if( (r == row_target) && (c == col_target) /* success if layer OK */ - && ( tab_mask[side] & pad_masque_layer_e) ) + && ( tab_mask[side] & padLayerMaskEnd) ) { /* Remove link. */ GRSetDrawMode( DC, GR_XOR ); @@ -576,6 +588,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, { result = SUCCESS; /* Success : Route OK */ } + break; /* Routing complete. */ } @@ -600,9 +613,11 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, } _self = 0; + if( curcell & HOLE ) { _self = 5; + /* set 'present' bits */ for( i = 0; i < 8; i++ ) { @@ -622,7 +637,9 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, if( _self == 5 && selfok2[i].present ) continue; + newcell = GetCell( nr, nc, side ); + if( newcell & CURRENT_PAD ) newcell &= ~HOLE; @@ -634,23 +651,29 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, } /* check for traces */ else if( newcell & HOLE & ~(newmask[i]) ) + { continue; + } /* check blocking on corner neighbors */ if( delta[i][0] && delta[i][1] ) { /* check first buddy */ buddy = GetCell( r + blocking[i].r1, c + blocking[i].c1, side ); + if( buddy & CURRENT_PAD ) buddy &= ~HOLE; + if( buddy & HOLE ) continue; // if (buddy & (blocking[i].b1)) continue; /* check second buddy */ buddy = GetCell( r + blocking[i].r2, c + blocking[i].c2, side ); + if( buddy & CURRENT_PAD ) buddy &= ~HOLE; + if( buddy & HOLE ) continue; @@ -668,6 +691,7 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, { SetDir( nr, nc, side, ndir[i] ); SetDist( nr, nc, side, newdist ); + if( SetQueue( nr, nc, side, newdist, GetApxDist( nr, nc, row_target, col_target ), row_target, col_target ) == 0 ) @@ -689,13 +713,17 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, if( two_sides ) { olddir = GetDir( r, c, side ); + if( olddir == FROM_OTHERSIDE ) continue; /* useless move, so don't bother */ + if( curcell ) /* can't drill via if anything here */ continue; + /* check for holes or traces on other side */ if( ( newcell = GetCell( r, c, 1 - side ) ) != 0 ) continue; + /* check for nearby holes or traces on both sides */ for( skip = 0, i = 0; i < 8; i++ ) { @@ -729,8 +757,8 @@ static int Autoroute_One_Track( PCB_EDIT_FRAME* pcbframe, { SetDir( r, c, 1 - side, FROM_OTHERSIDE ); SetDist( r, c, 1 - side, newdist ); - if( SetQueue( r, c, 1 - side, newdist, apx_dist, row_target, - col_target ) == 0 ) + + if( SetQueue( r, c, 1 - side, newdist, apx_dist, row_target, col_target ) == 0 ) { return ERR_MEMORY; } @@ -899,7 +927,8 @@ static int Retrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC, wxASSERT( g_CurrentTrackList.GetCount() == 0 ); - do { + do + { /* find where we came from to get here */ r2 = r1; c2 = c1; s2 = s1; x = GetDir( r1, c1, s1 ); @@ -947,8 +976,7 @@ static int Retrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC, break; default: - DisplayError( pcbframe, - wxT( "Retrace: internal error: no way back" ) ); + DisplayError( pcbframe, wxT( "Retrace: internal error: no way back" ) ); return 0; } @@ -1001,8 +1029,7 @@ static int Retrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC, return 0; } - OrCell_Trace( - pcbframe->GetBoard(), r1, c1, s1, p_dir, current_net_code ); + OrCell_Trace( pcbframe->GetBoard(), r1, c1, s1, p_dir, current_net_code ); } else { @@ -1017,11 +1044,10 @@ static int Retrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC, || x == FROM_OTHERSIDE ) && ( ( b = bit[y - 1][x - 1] ) != 0 ) ) { - OrCell_Trace( pcbframe->GetBoard(), r1, c1, s1, b, - current_net_code ); + OrCell_Trace( pcbframe->GetBoard(), r1, c1, s1, b, current_net_code ); + if( b & HOLE ) - OrCell_Trace( pcbframe->GetBoard(), r2, c2, s2, HOLE, - current_net_code ); + OrCell_Trace( pcbframe->GetBoard(), r2, c2, s2, HOLE, current_net_code ); } else { @@ -1074,9 +1100,9 @@ static int Retrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC, return 0; } - OrCell_Trace( pcbframe->GetBoard(), r2, c2, s2, p_dir, - current_net_code ); + OrCell_Trace( pcbframe->GetBoard(), r2, c2, s2, p_dir, current_net_code ); } + /* move to next cell */ r0 = r1; c0 = c1; @@ -1086,7 +1112,7 @@ static int Retrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC, s1 = s2; } while( !( ( r2 == row_source ) && ( c2 == col_source ) ) ); - Place_Piste_en_Buffer( pcbframe, DC ); + AddNewTrace( pcbframe, DC ); return 1; } @@ -1129,6 +1155,7 @@ static void OrCell_Trace( BOARD* pcb, int col, int row, g_CurrentTrackList.PushBack( newTrack ); g_CurrentTrackSegment->SetLayer( Route_Layer_BOTTOM ); + if( side == TOP ) g_CurrentTrackSegment->SetLayer( Route_Layer_TOP ); @@ -1145,26 +1172,20 @@ static void OrCell_Trace( BOARD* pcb, int col, int row, g_CurrentTrackSegment->m_Start.y = segm_fY; /* Placement on the center of the pad if outside grid. */ - dx1 = g_CurrentTrackSegment->m_End.x - - g_CurrentTrackSegment->m_Start.x; - dy1 = g_CurrentTrackSegment->m_End.y - - g_CurrentTrackSegment->m_Start.y; + dx1 = g_CurrentTrackSegment->m_End.x - g_CurrentTrackSegment->m_Start.x; + dy1 = g_CurrentTrackSegment->m_End.y - g_CurrentTrackSegment->m_Start.y; - dx0 = pt_cur_ch->m_PadEnd->GetPosition().x - - g_CurrentTrackSegment->m_Start.x; - dy0 = pt_cur_ch->m_PadEnd->GetPosition().y - - g_CurrentTrackSegment->m_Start.y; + dx0 = pt_cur_ch->m_PadEnd->GetPosition().x - g_CurrentTrackSegment->m_Start.x; + dy0 = pt_cur_ch->m_PadEnd->GetPosition().y - g_CurrentTrackSegment->m_Start.y; /* If aligned, change the origin point. */ if( abs( dx0 * dy1 ) == abs( dx1 * dy0 ) ) { - g_CurrentTrackSegment->m_Start = - pt_cur_ch->m_PadEnd->GetPosition(); + g_CurrentTrackSegment->m_Start = pt_cur_ch->m_PadEnd->GetPosition(); } else // Creation of a supplemental segment { - g_CurrentTrackSegment->m_Start = - pt_cur_ch->m_PadEnd->GetPosition(); + g_CurrentTrackSegment->m_Start = pt_cur_ch->m_PadEnd->GetPosition(); newTrack = g_CurrentTrackSegment->Copy(); newTrack->m_Start = g_CurrentTrackSegment->m_End; @@ -1176,22 +1197,21 @@ static void OrCell_Trace( BOARD* pcb, int col, int row, { if( g_CurrentTrackSegment->Back() ) { - g_CurrentTrackSegment->m_Start = - g_CurrentTrackSegment->Back()->m_End; + g_CurrentTrackSegment->m_Start = g_CurrentTrackSegment->Back()->m_End; } } + g_CurrentTrackSegment->m_Width = pcb->GetCurrentTrackWidth(); if( g_CurrentTrackSegment->m_Start != g_CurrentTrackSegment->m_End ) { /* Reduce aligned segments by one. */ TRACK* oldTrack = g_CurrentTrackSegment->Back(); + if( oldTrack && oldTrack->Type() != TYPE_VIA ) { - dx1 = g_CurrentTrackSegment->m_End.x - - g_CurrentTrackSegment->m_Start.x; - dy1 = g_CurrentTrackSegment->m_End.y - - g_CurrentTrackSegment->m_Start.y; + dx1 = g_CurrentTrackSegment->m_End.x - g_CurrentTrackSegment->m_Start.x; + dy1 = g_CurrentTrackSegment->m_End.y - g_CurrentTrackSegment->m_Start.y; dx0 = oldTrack->m_End.x - oldTrack->m_Start.x; dy0 = oldTrack->m_End.y - oldTrack->m_Start.y; @@ -1213,7 +1233,7 @@ static void OrCell_Trace( BOARD* pcb, int col, int row, * connected * Center on pads even if they are off grid. */ -static void Place_Piste_en_Buffer( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) +static void AddNewTrace( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) { if( g_FirstTrackSegment == NULL ) return; @@ -1282,7 +1302,7 @@ static void Place_Piste_en_Buffer( PCB_EDIT_FRAME* pcbframe, wxDC* DC ) pcbframe->GetBoard()->m_Track.Insert( track, insertBeforeMe ); } - Trace_Une_Piste( panel, DC, firstTrack, newCount, GR_OR ); + DrawTraces( panel, DC, firstTrack, newCount, GR_OR ); pcbframe->test_1_net_connexion( DC, netcode ); diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index 2eb0c4856c..54f2a0a80f 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -81,7 +81,7 @@ void PCB_EDIT_FRAME::ExportToSpecctra( wxCommandEvent& event ) mask, this, wxFD_SAVE, - FALSE + false ); if( fullFileName == wxEmptyString ) return; @@ -245,7 +245,7 @@ static bool isRoundKeepout( D_PAD* aPad ) if( aPad->m_Drill.x >= aPad->m_Size.x ) return true; - if( (aPad->m_Masque_Layer & ALL_CU_LAYERS) == 0 ) + if( (aPad->m_layerMask & ALL_CU_LAYERS) == 0 ) return true; } @@ -283,7 +283,7 @@ PADSTACK* SPECCTRA_DB::makePADSTACK( BOARD* aBoard, D_PAD* aPad ) uniqifier = '['; - bool onAllCopperLayers = ( (aPad->m_Masque_Layer & ALL_CU_LAYERS) == ALL_CU_LAYERS ); + bool onAllCopperLayers = ( (aPad->m_layerMask & ALL_CU_LAYERS) == ALL_CU_LAYERS ); if( onAllCopperLayers ) uniqifier += 'A'; // A for all layers diff --git a/pcbnew/specctra_import.cpp b/pcbnew/specctra_import.cpp index c7ae2acea8..ebe7380d51 100644 --- a/pcbnew/specctra_import.cpp +++ b/pcbnew/specctra_import.cpp @@ -80,7 +80,7 @@ void PCB_EDIT_FRAME::ImportSpecctraSession( wxCommandEvent& event ) mask, this, wxFD_OPEN, - FALSE + false ); if( fullFileName == wxEmptyString ) diff --git a/pcbnew/swap_layers.cpp b/pcbnew/swap_layers.cpp index 324278490a..36b8643ff4 100644 --- a/pcbnew/swap_layers.cpp +++ b/pcbnew/swap_layers.cpp @@ -209,17 +209,21 @@ WinEDA_SwapLayerFrame::WinEDA_SwapLayerFrame( PCB_BASE_FRAME* parent ) : for( int jj = 1; jj < NB_LAYERS; jj++ ) { text->SetLabel( board->GetLayerName( jj ) ); + if( goodSize.x < text->GetSize().x ) goodSize.x = text->GetSize().x; } text->SetLabel( _( "No Change" ) ); + if( goodSize.x < text->GetSize().x ) goodSize.x = text->GetSize().x; } else + { text = new wxStaticText( this, item_ID, _( "No Change" ), wxDefaultPosition, wxDefaultSize, 0 ); + } text->SetMinSize( goodSize ); FlexColumnBoxSizer->Add( text, 1, @@ -241,8 +245,7 @@ WinEDA_SwapLayerFrame::WinEDA_SwapLayerFrame( PCB_BASE_FRAME* parent ) : // Provide a line to separate the controls which have been provided so far // from the OK and Cancel buttons (which will be provided after this line) - Line = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, - wxLI_HORIZONTAL ); + Line = new wxStaticLine( this, -1, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL ); OuterBoxSizer->Add( Line, 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 ); // Provide a StdDialogButtonSizer to accommodate the OK and Cancel buttons; @@ -251,8 +254,7 @@ WinEDA_SwapLayerFrame::WinEDA_SwapLayerFrame( PCB_BASE_FRAME* parent ) : StdDialogButtonSizer = new wxStdDialogButtonSizer; OuterBoxSizer->Add( StdDialogButtonSizer, 0, wxGROW | wxALL, 10 ); - Button = new wxButton( this, wxID_OK, _( "&OK" ), wxDefaultPosition, - wxDefaultSize, 0 ); + Button = new wxButton( this, wxID_OK, _( "&OK" ), wxDefaultPosition, wxDefaultSize, 0 ); Button->SetDefault(); StdDialogButtonSizer->AddButton( Button ); @@ -281,8 +283,10 @@ void WinEDA_SwapLayerFrame::Sel_Layer( wxCommandEvent& event ) ii = event.GetId() - ID_BUTTON_0; jj = New_Layer[ii]; + if( (jj < 0) || (jj > NB_LAYERS) ) jj = LAYER_NO_CHANGE; // (Defaults to "No Change".) + jj = m_Parent->SelectLayer( jj, -1, -1, true ); if( (jj < 0) || (jj > NB_LAYERS) ) @@ -303,6 +307,7 @@ void WinEDA_SwapLayerFrame::Sel_Layer( wxCommandEvent& event ) if( jj != New_Layer[ii] ) { New_Layer[ii] = jj; + if( jj >= LAYER_NO_CHANGE ) { layer_list[ii]->SetLabel( _( "No Change" ) ); @@ -356,27 +361,34 @@ void PCB_EDIT_FRAME::Swap_Layers( wxCommandEvent& event ) /* Change traces. */ pt_segm = GetBoard()->m_Track; + for( ; pt_segm != NULL; pt_segm = pt_segm->Next() ) { OnModify(); + if( pt_segm->Type() == TYPE_VIA ) { SEGVIA* Via = (SEGVIA*) pt_segm; + if( Via->Shape() == VIA_THROUGH ) continue; + int top_layer, bottom_layer; + Via->ReturnLayerPair( &top_layer, &bottom_layer ); - if( New_Layer[bottom_layer] >= 0 && New_Layer[bottom_layer] < - LAYER_NO_CHANGE ) + + if( New_Layer[bottom_layer] >= 0 && New_Layer[bottom_layer] < LAYER_NO_CHANGE ) bottom_layer = New_Layer[bottom_layer]; - if( New_Layer[top_layer] >= 0 - && New_Layer[top_layer] < LAYER_NO_CHANGE ) + + if( New_Layer[top_layer] >= 0 && New_Layer[top_layer] < LAYER_NO_CHANGE ) top_layer = New_Layer[top_layer]; + Via->SetLayerPair( top_layer, bottom_layer ); } else { jj = pt_segm->GetLayer(); + if( New_Layer[jj] >= 0 && New_Layer[jj] < LAYER_NO_CHANGE ) pt_segm->SetLayer( New_Layer[jj] ); } @@ -387,12 +399,14 @@ void PCB_EDIT_FRAME::Swap_Layers( wxCommandEvent& event ) { OnModify(); jj = pt_segm->GetLayer(); + if( New_Layer[jj] >= 0 && New_Layer[jj] < LAYER_NO_CHANGE ) pt_segm->SetLayer( New_Layer[jj] ); } /* Change other segments. */ PtStruct = GetBoard()->m_Drawings; + for( ; PtStruct != NULL; PtStruct = PtStruct->Next() ) { if( PtStruct->Type() == TYPE_DRAWSEGMENT ) @@ -400,10 +414,11 @@ void PCB_EDIT_FRAME::Swap_Layers( wxCommandEvent& event ) OnModify(); pt_drawsegm = (DRAWSEGMENT*) PtStruct; jj = pt_drawsegm->GetLayer(); + if( New_Layer[jj] >= 0 && New_Layer[jj] < LAYER_NO_CHANGE ) pt_drawsegm->SetLayer( New_Layer[jj] ); } } - DrawPanel->Refresh( TRUE ); + DrawPanel->Refresh( true ); } diff --git a/pcbnew/tr_modif.cpp b/pcbnew/tr_modif.cpp index 62227c5aba..a2e06772b8 100644 --- a/pcbnew/tr_modif.cpp +++ b/pcbnew/tr_modif.cpp @@ -11,7 +11,7 @@ static void ListSetState( EDA_ITEM* Start, int NbItem, int State, int onoff ); extern int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, - TRACK** StartTrack, TRACK** EndTrack ); + TRACK** StartTrack, TRACK** EndTrack ); /** @@ -54,8 +54,7 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, if( aNewTrack->Type() == TYPE_VIA && ( aNewTrackSegmentsCount > 1 ) ) aNewTrack = aNewTrack->Next(); - aNewTrack = Marque_Une_Piste( GetBoard(), aNewTrack, - &aNewTrackSegmentsCount, NULL, NULL, true ); + aNewTrack = MarkTrace( GetBoard(), aNewTrack, &aNewTrackSegmentsCount, NULL, NULL, true ); wxASSERT( aNewTrack ); #if 0 && defined(DEBUG) @@ -63,11 +62,11 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, * the track */ EndNewTrack = aNewTrack; + for( ii = 1; ii < aNewTrackSegmentsCount; ii++ ) { wxASSERT( EndNewTrack->GetState( -1 ) != 0 ); - D( printf( "track %p is newly part of net %d\n", EndNewTrack, - netcode ); ) + D( printf( "track %p is newly part of net %d\n", EndNewTrack, netcode ); ) EndNewTrack = EndNewTrack->Next(); } @@ -79,8 +78,8 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, #endif - TRACK* bufStart = m_Pcb->m_Track->GetStartNetCode( netcode ); // Beginning of tracks of the net - TRACK* bufEnd = bufStart->GetEndNetCode( netcode ); // Enf of tracks of the net + TRACK* bufStart = m_Pcb->m_Track->GetStartNetCode( netcode ); // Beginning of tracks of the net + TRACK* bufEnd = bufStart->GetEndNetCode( netcode ); // Enf of tracks of the net /* Flags for cleaning the net. */ for( pt_del = bufStart; pt_del; pt_del = pt_del->Next() ) @@ -88,12 +87,12 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, //D( printf( "track %p turning off BUSY | IN_EDIT | IS_LINKED\n", pt_del ); ) D( std::cout<<"track "<SetState( BUSY | IN_EDIT | IS_LINKED, OFF ); + if( pt_del == bufEnd ) // Last segment reached break; } - if( ReturnEndsTrack( aNewTrack, aNewTrackSegmentsCount, - &StartTrack, &EndTrack ) == 0 ) + if( ReturnEndsTrack( aNewTrack, aNewTrackSegmentsCount, &StartTrack, &EndTrack ) == 0 ) return 0; if( ( StartTrack == NULL ) || ( EndTrack == NULL ) ) @@ -112,6 +111,7 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, /* There may be a via or a pad on the end points. */ pt_segm = Fast_Locate_Via( m_Pcb->m_Track, NULL, start, startmasklayer ); + if( pt_segm ) startmasklayer |= pt_segm->ReturnMaskLayer(); @@ -119,17 +119,18 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, { /* Start on pad. */ D_PAD* pt_pad = (D_PAD*)(StartTrack->start); - startmasklayer |= pt_pad->m_Masque_Layer; + startmasklayer |= pt_pad->m_layerMask; } pt_segm = Fast_Locate_Via( m_Pcb->m_Track, NULL, end, endmasklayer ); + if( pt_segm ) endmasklayer |= pt_segm->ReturnMaskLayer(); if( EndTrack->end && ( EndTrack->end->Type() == TYPE_PAD ) ) { D_PAD* pt_pad = (D_PAD*)(EndTrack->end); - endmasklayer |= pt_pad->m_Masque_Layer; + endmasklayer |= pt_pad->m_layerMask; } /* Mark as deleted a new track (which is not involved in the search for @@ -140,7 +141,7 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, /* A segment must be connected to the starting point, otherwise * it is unnecessary to analyze the other point */ - pt_segm = Fast_Locate_Piste( bufStart, bufEnd, start, startmasklayer ); + pt_segm = GetTrace( bufStart, bufEnd, start, startmasklayer ); if( pt_segm == NULL ) /* Not connected to the track starting point. */ { @@ -155,7 +156,8 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, */ for( pt_del = bufStart, nbconnect = 0; ; ) { - pt_segm = Fast_Locate_Piste( pt_del, bufEnd, end, endmasklayer ); + pt_segm = GetTrace( pt_del, bufEnd, end, endmasklayer ); + if( pt_segm == NULL ) break; @@ -167,6 +169,7 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, nbconnect++; } } + if( pt_del == bufEnd ) break; @@ -179,6 +182,7 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, for( pt_del = bufStart; pt_del; pt_del = pt_del->Next() ) { pt_del->SetState( BUSY | IS_DELETED | IN_EDIT | IS_LINKED, OFF ); + if( pt_del == bufEnd ) // Last segment reached break; } @@ -199,6 +203,7 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, { if( pt_del->GetState( IS_LINKED ) ) break; + if( pt_del == bufEnd ) // Last segment reached break; } @@ -206,13 +211,14 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, nbconnect--; pt_del->SetState( IS_LINKED, OFF ); - pt_del = Marque_Une_Piste( GetBoard(), pt_del, &nb_segm, NULL, NULL, true ); + pt_del = MarkTrace( GetBoard(), pt_del, &nb_segm, NULL, NULL, true ); /* Test if the marked track is redundant, i.e. if one of marked segments * is connected to the starting point of the new track. */ ii = 0; pt_segm = pt_del; + for( ; pt_segm && (ii < nb_segm); pt_segm = pt_segm->Next(), ii++ ) { if( pt_segm->GetState( BUSY ) == 0 ) @@ -222,12 +228,13 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, { /* Marked track can be erased. */ TRACK* NextS; - Trace_Une_Piste( DrawPanel, aDC, pt_del, nb_segm, - GR_XOR | GR_SURBRILL ); + + DrawTraces( DrawPanel, aDC, pt_del, nb_segm, GR_XOR | GR_SURBRILL ); for( jj = 0; jj < nb_segm; jj++, pt_del = NextS ) { NextS = pt_del->Next(); + if( aItemsListPicker ) { pt_del->UnLink(); @@ -237,19 +244,22 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, aItemsListPicker->PushItem( picker ); } else + { pt_del->DeleteStructure(); + } } /* Clean up flags. */ - for( pt_del = m_Pcb->m_Track; pt_del != NULL; - pt_del = pt_del->Next() ) + for( pt_del = m_Pcb->m_Track; pt_del != NULL; pt_del = pt_del->Next() ) { if( pt_del->GetState( IN_EDIT ) ) { pt_del->SetState( IN_EDIT, OFF ); + if( aDC ) pt_del->Draw( DrawPanel, aDC, GR_OR ); } + pt_del->SetState( IN_EDIT | IS_LINKED, OFF ); } @@ -266,6 +276,7 @@ int PCB_EDIT_FRAME::EraseRedundantTrack( wxDC* aDC, for( pt_del = m_Pcb->m_Track; pt_del; pt_del = pt_del->Next() ) { pt_del->SetState( BUSY | IS_DELETED | IN_EDIT | IS_LINKED, OFF ); + if( pt_del == bufEnd ) // Last segment reached break; } diff --git a/pcbnew/tracepcb.cpp b/pcbnew/tracepcb.cpp index 2abb3d1fdf..a505ee6692 100644 --- a/pcbnew/tracepcb.cpp +++ b/pcbnew/tracepcb.cpp @@ -26,10 +26,10 @@ extern int g_DrawDefaultLineThickness; // Default line thickness, used to draw F /* Trace the pads of a module in sketch mode. * Used to display pads when when the module visibility is set to not visible * and we want to see pad through. - * The pads must appear on the layers selected in MasqueLayer + * The pads must appear on the layers selected in LayerMask */ static void Trace_Pads_Only( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module, - int ox, int oy, int MasqueLayer, int draw_mode ); + int ox, int oy, int LayerMask, int draw_mode ); void FOOTPRINT_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) @@ -141,7 +141,7 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* DC, int aDrawMode, const wxPoint { case TYPE_DIMENSION: case TYPE_TEXTE: - case TYPE_MIRE: + case PCB_TARGET_T: case TYPE_DRAWSEGMENT: item->Draw( aPanel, DC, aDrawMode ); break; @@ -177,6 +177,7 @@ void BOARD::Draw( EDA_DRAW_PANEL* aPanel, wxDC* DC, int aDrawMode, const wxPoint { if( module->GetLayer() == LAYER_N_FRONT ) display = false; + layerMask &= ~LAYER_FRONT; } @@ -250,10 +251,10 @@ void BOARD::DrawHighLight( EDA_DRAW_PANEL* aDrawPanel, wxDC* DC, int aNetCode ) /* Trace the pads of a module in sketch mode. * Used to display pads when when the module visibility is set to not visible * and we want to see pad through. - * The pads must appear on the layers selected in MasqueLayer + * The pads must appear on the layers selected in LayerMask */ void Trace_Pads_Only( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module, - int ox, int oy, int MasqueLayer, int draw_mode ) + int ox, int oy, int LayerMask, int draw_mode ) { int tmp; PCB_BASE_FRAME* frame; @@ -266,7 +267,7 @@ void Trace_Pads_Only( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module, /* Draw pads. */ for( D_PAD* pad = Module->m_Pads; pad; pad = pad->Next() ) { - if( (pad->m_Masque_Layer & MasqueLayer) == 0 ) + if( (pad->m_layerMask & LayerMask) == 0 ) continue; pad->Draw( panel, DC, draw_mode, wxPoint( ox, oy ) ); diff --git a/pcbnew/track.cpp b/pcbnew/track.cpp index 2e210ee8ff..b6e3f51d95 100644 --- a/pcbnew/track.cpp +++ b/pcbnew/track.cpp @@ -22,18 +22,18 @@ typedef std::vector TRACK_PTRS; // buffer of item candidates when /* Local functions */ -static void Marque_Chaine_segments( BOARD* Pcb, - wxPoint ref_pos, - int masklayer, - TRACK_PTRS* aList ); +static void ChainMarkedSegments( BOARD* Pcb, + wxPoint ref_pos, + int masklayer, + TRACK_PTRS* aList ); -TRACK* Marque_Une_Piste( BOARD* aPcb, - TRACK* aStartSegm, - int* aSegmCount, - int* aTrackLen, - int* aLengthDie, - bool aReorder ) +TRACK* MarkTrace( BOARD* aPcb, + TRACK* aStartSegm, + int* aSegmCount, + int* aTrackLen, + int* aLengthDie, + bool aReorder ) { int NbSegmBusy; @@ -55,7 +55,7 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, /* Set flags of the initial track segment */ aStartSegm->SetState( BUSY, ON ); - int masque_layer = aStartSegm->ReturnMaskLayer(); + int layerMask = aStartSegm->ReturnMaskLayer(); trackList.push_back( aStartSegm ); @@ -69,50 +69,42 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, if( aStartSegm->Type() == TYPE_VIA ) { TRACK* Segm1, * Segm2 = NULL, * Segm3 = NULL; - Segm1 = Fast_Locate_Piste( aPcb->m_Track, NULL, - aStartSegm->m_Start, masque_layer ); + Segm1 = GetTrace( aPcb->m_Track, NULL, aStartSegm->m_Start, layerMask ); + if( Segm1 ) { - Segm2 = Fast_Locate_Piste( Segm1->Next(), NULL, - aStartSegm->m_Start, masque_layer ); + Segm2 = GetTrace( Segm1->Next(), NULL, aStartSegm->m_Start, layerMask ); } + if( Segm2 ) { - Segm3 = Fast_Locate_Piste( Segm2->Next(), NULL, - aStartSegm->m_Start, masque_layer ); + Segm3 = GetTrace( Segm2->Next(), NULL, aStartSegm->m_Start, layerMask ); } - if( Segm3 ) // More than 2 segments are connected to this via. the - // "track" is only this via + + if( Segm3 ) // More than 2 segments are connected to this via. the track" is only this via { if( aSegmCount ) *aSegmCount = 1; + return aStartSegm; } - if( Segm1 ) // search for others segments connected to the initial - // segment start point + + if( Segm1 ) // search for others segments connected to the initial segment start point { - masque_layer = Segm1->ReturnMaskLayer(); - Marque_Chaine_segments( aPcb, aStartSegm->m_Start, masque_layer, - &trackList ); + layerMask = Segm1->ReturnMaskLayer(); + ChainMarkedSegments( aPcb, aStartSegm->m_Start, layerMask, &trackList ); } - if( Segm2 ) // search for others segments connected to the initial - // segment end point + + if( Segm2 ) // search for others segments connected to the initial segment end point { - masque_layer = Segm2->ReturnMaskLayer(); - Marque_Chaine_segments( aPcb, aStartSegm->m_Start, masque_layer, - &trackList ); + layerMask = Segm2->ReturnMaskLayer(); + ChainMarkedSegments( aPcb, aStartSegm->m_Start, layerMask, &trackList ); } } else // mark the chain using both ends of the initial segment { - Marque_Chaine_segments( aPcb, - aStartSegm->m_Start, - masque_layer, - &trackList ); - Marque_Chaine_segments( aPcb, - aStartSegm->m_End, - masque_layer, - &trackList ); + ChainMarkedSegments( aPcb, aStartSegm->m_Start, layerMask, &trackList ); + ChainMarkedSegments( aPcb, aStartSegm->m_End, layerMask, &trackList ); } // Now examine selected vias and flag them if they are on the track @@ -131,17 +123,13 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, if( via == aStartSegm ) continue; - via->SetState( BUSY, ON ); // Try to flag it. the flag will be cleared - // later if needed + via->SetState( BUSY, ON ); // Try to flag it. the flag will be cleared later if needed - masque_layer = via->ReturnMaskLayer(); + layerMask = via->ReturnMaskLayer(); - TRACK* track = Fast_Locate_Piste( aPcb->m_Track, - NULL, - via->m_Start, - masque_layer ); + TRACK* track = GetTrace( aPcb->m_Track, NULL, via->m_Start, layerMask ); - // Fast_Locate_Piste does not consider tracks flagged BUSY. + // GetTrace does not consider tracks flagged BUSY. // So if no connected track found, this via is on the current track // only: keep it if( track == NULL ) @@ -161,9 +149,7 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, */ int layer = track->GetLayer(); - while( ( track = Fast_Locate_Piste( track->Next(), NULL, - via->m_Start, - masque_layer ) ) != NULL ) + while( ( track = GetTrace( track->Next(), NULL, via->m_Start, layerMask ) ) != NULL ) { if( layer != track->GetLayer() ) { @@ -183,9 +169,8 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, */ NbSegmBusy = 0; TRACK* firstTrack; - for( firstTrack = aPcb->m_Track; - firstTrack; - firstTrack = firstTrack->Next() ) + + for( firstTrack = aPcb->m_Track; firstTrack; firstTrack = firstTrack->Next() ) { // Search for the first flagged BUSY segments if( firstTrack->GetState( BUSY ) ) @@ -200,6 +185,7 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, double full_len = 0; double lenDie = 0; + if( aReorder ) { DLIST* list = (DLIST*)firstTrack->GetList(); @@ -210,16 +196,20 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, * of the flagged list */ TRACK* next; + for( TRACK* track = firstTrack->Next(); track; track = next ) { next = track->Next(); + if( track->GetState( BUSY ) ) // move it! { NbSegmBusy++; track->UnLink(); list->Insert( track, firstTrack->Next() ); + if( aTrackLen ) full_len += track->GetLength(); + if( aLengthDie ) // Add now length die. { // In fact only 2 pads (maximum) will be taken in account: @@ -229,6 +219,7 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, D_PAD * pad = (D_PAD *) track->start; lenDie += (double) pad->m_LengthDie; } + if( track->GetState( END_ONPAD ) ) { D_PAD * pad = (D_PAD *) track->end; @@ -241,6 +232,7 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, else if( aTrackLen ) { NbSegmBusy = 0; + for( TRACK* track = firstTrack; track; track = track->Next() ) { if( track->GetState( BUSY ) ) @@ -248,6 +240,7 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, NbSegmBusy++; track->SetState( BUSY, OFF ); full_len += track->GetLength(); + // Add now length die. // In fact only 2 pads (maximum) will be taken in account: // that are on each end of the track, if any @@ -256,6 +249,7 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, D_PAD * pad = (D_PAD *) track->start; lenDie += (double) pad->m_LengthDie; } + if( track->GetState( END_ONPAD ) ) { D_PAD * pad = (D_PAD *) track->end; @@ -267,8 +261,10 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, if( aTrackLen ) *aTrackLen = wxRound( full_len ); + if( aLengthDie ) *aLengthDie = wxRound( lenDie ); + if( aSegmCount ) *aSegmCount = NbSegmBusy; @@ -277,7 +273,7 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, /** - * Function used by Marque_Une_Piste + * Function used by MarkTrace * - Set the BUSY flag of connected segments, the first search point is * ref_pos on layers allowed in masque_layer * - Put segments fount in aList @@ -289,10 +285,10 @@ TRACK* Marque_Une_Piste( BOARD* aPcb, * starting point is on a via) * @param aList = the track list to fill with points of segments flagged */ -static void Marque_Chaine_segments( BOARD* aPcb, - wxPoint aRef_pos, - int aLayerMask, - TRACK_PTRS* aList ) +static void ChainMarkedSegments( BOARD* aPcb, + wxPoint aRef_pos, + int aLayerMask, + TRACK_PTRS* aList ) { TRACK* pt_segm, // The current segment being analyzed. * pt_via, // The via identified, eventually destroy @@ -332,6 +328,7 @@ static void Marque_Chaine_segments( BOARD* aPcb, * and we do not know if this via is on the track or finish the track */ pt_via = Fast_Locate_Via( aPcb->m_Track, NULL, aRef_pos, aLayerMask ); + if( pt_via ) { aLayerMask = pt_via->ReturnMaskLayer(); @@ -346,11 +343,10 @@ static void Marque_Chaine_segments( BOARD* aPcb, */ pt_segm = aPcb->m_Track; SegmentCandidate = NULL; NbSegm = 0; - while( ( pt_segm = Fast_Locate_Piste( pt_segm, NULL, - aRef_pos, aLayerMask ) ) != NULL ) + + while( ( pt_segm = GetTrace( pt_segm, NULL, aRef_pos, aLayerMask ) ) != NULL ) { - if( pt_segm->GetState( BUSY ) ) // already found and selected: skip - // it + if( pt_segm->GetState( BUSY ) ) // already found and selected: skip it { pt_segm = pt_segm->Next(); continue; @@ -363,21 +359,19 @@ static void Marque_Chaine_segments( BOARD* aPcb, } NbSegm++; - if( NbSegm == 1 ) /* First time we found a connected item: pt_segm - * is candidate */ + + if( NbSegm == 1 ) /* First time we found a connected item: pt_segm is candidate */ { SegmentCandidate = pt_segm; pt_segm = pt_segm->Next(); } - else /* More than 1 segment connected -> this location is an end of - * the track */ + else /* More than 1 segment connected -> this location is an end of the track */ { return; } } - if( SegmentCandidate ) // A candidate is found: flag it an push it - // in list + if( SegmentCandidate ) // A candidate is found: flag it an push it in list { /* Initialize parameters to search items connected to this * candidate: @@ -401,7 +395,9 @@ static void Marque_Chaine_segments( BOARD* aPcb, SegmentCandidate->SetState( BUSY, ON ); } else + { return; + } } } @@ -416,11 +412,10 @@ static void Marque_Chaine_segments( BOARD* aPcb, * (*EndTrack)->m_End coordinate is the end of the track * Segments connected must be consecutive in list */ -int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, - TRACK** StartTrack, TRACK** EndTrack ) +int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, TRACK** StartTrack, TRACK** EndTrack ) { TRACK* Track, * via, * segm, * TrackListEnd; - int NbEnds, masque_layer, ii, ok = 0; + int NbEnds, layerMask, ii, ok = 0; if( NbSegm <= 1 ) { @@ -431,6 +426,7 @@ int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, /* Calculation of the limit analysis. */ *StartTrack = *EndTrack = NULL; TrackListEnd = Track = RefTrack; ii = 0; + for( ; ( Track != NULL ) && ( ii < NbSegm ); ii++, Track = Track->Next() ) { TrackListEnd = Track; @@ -439,24 +435,25 @@ int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, /* Calculate the extremes. */ NbEnds = 0; Track = RefTrack; ii = 0; + for( ; ( Track != NULL ) && ( ii < NbSegm ); ii++, Track = Track->Next() ) { if( Track->Type() == TYPE_VIA ) continue; - masque_layer = Track->ReturnMaskLayer(); - via = Fast_Locate_Via( RefTrack, TrackListEnd, - Track->m_Start, masque_layer ); + layerMask = Track->ReturnMaskLayer(); + via = Fast_Locate_Via( RefTrack, TrackListEnd, Track->m_Start, layerMask ); + if( via ) { - masque_layer |= via->ReturnMaskLayer(); + layerMask |= via->ReturnMaskLayer(); via->SetState( BUSY, ON ); } Track->SetState( BUSY, ON ); - segm = Fast_Locate_Piste( RefTrack, TrackListEnd, - Track->m_Start, masque_layer ); + segm = GetTrace( RefTrack, TrackListEnd, Track->m_Start, layerMask ); Track->SetState( BUSY, OFF ); + if( via ) via->SetState( BUSY, OFF ); @@ -480,6 +477,7 @@ int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, if( BeginPad ) Track->SetState( END_ONPAD, ON ); + if( EndPad ) Track->SetState( BEGIN_ONPAD, ON ); @@ -490,21 +488,22 @@ int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, } } - masque_layer = Track->ReturnMaskLayer(); - via = Fast_Locate_Via( RefTrack, TrackListEnd, - Track->m_End, masque_layer ); + layerMask = Track->ReturnMaskLayer(); + via = Fast_Locate_Via( RefTrack, TrackListEnd, Track->m_End, layerMask ); + if( via ) { - masque_layer |= via->ReturnMaskLayer(); + layerMask |= via->ReturnMaskLayer(); via->SetState( BUSY, ON ); } Track->SetState( BUSY, ON ); - segm = Fast_Locate_Piste( RefTrack, TrackListEnd, - Track->m_End, masque_layer ); + segm = GetTrace( RefTrack, TrackListEnd, Track->m_End, layerMask ); Track->SetState( BUSY, OFF ); + if( via ) via->SetState( BUSY, OFF ); + if( segm == NULL ) { switch( NbEnds ) @@ -522,6 +521,7 @@ int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, if( BeginPad ) Track->SetState( END_ONPAD, ON ); + if( EndPad ) Track->SetState( BEGIN_ONPAD, ON ); @@ -539,4 +539,3 @@ int ReturnEndsTrack( TRACK* RefTrack, int NbSegm, return ok; } - diff --git a/pcbnew/trpiste.cpp b/pcbnew/trpiste.cpp index d616641b82..fcb2b4c2e1 100644 --- a/pcbnew/trpiste.cpp +++ b/pcbnew/trpiste.cpp @@ -12,22 +12,21 @@ #include "protos.h" -/* Trace consecutive segments in memory. +/** + * Draw a list of trace segmants. * * Parameters: - * Pt_start_piste = first segment in the list + * Pt_start_trace = first segment in the list * Nbsegment = number of segments traced * Draw_mode = mode (GR_XOR, GR_OR ..) * CAUTION: * The starting point of a track following MUST exist: may be * then put a 0 before calling a routine if the track is the last drawn. */ -void Trace_Une_Piste( EDA_DRAW_PANEL* panel, wxDC* DC, TRACK* aTrackList, - int nbsegment, int draw_mode ) +void DrawTraces( EDA_DRAW_PANEL* panel, wxDC* DC, TRACK* aTrackList, int nbsegment, int draw_mode ) { // preserve the start of the list for debugging. - for( TRACK* track = aTrackList; nbsegment > 0 && track; - nbsegment--, track = track->Next() ) + for( TRACK* track = aTrackList; nbsegment > 0 && track; nbsegment--, track = track->Next() ) { track->Draw( panel, DC, draw_mode ); } diff --git a/pcbnew/zones_by_polygon.cpp b/pcbnew/zones_by_polygon.cpp index 17bef9087b..36cd92e7a7 100644 --- a/pcbnew/zones_by_polygon.cpp +++ b/pcbnew/zones_by_polygon.cpp @@ -40,9 +40,6 @@ static PICKED_ITEMS_LIST _AuxiliaryList; // a picked list to store z #include "dialog_copper_zones.h" -/**********************************************************************************/ -void PCB_EDIT_FRAME::Add_Similar_Zone( wxDC* DC, ZONE_CONTAINER* zone_container ) -/**********************************************************************************/ /** * Function Add_Similar_Zone @@ -51,6 +48,7 @@ void PCB_EDIT_FRAME::Add_Similar_Zone( wxDC* DC, ZONE_CONTAINER* zone_container * @param DC = current Device Context * @param zone_container = parent zone outline */ +void PCB_EDIT_FRAME::Add_Similar_Zone( wxDC* DC, ZONE_CONTAINER* zone_container ) { if ( zone_container == NULL ) return; @@ -67,19 +65,17 @@ void PCB_EDIT_FRAME::Add_Similar_Zone( wxDC* DC, ZONE_CONTAINER* zone_container } -/**********************************************************************************/ -void PCB_EDIT_FRAME::Add_Zone_Cutout( wxDC* DC, ZONE_CONTAINER* zone_container ) -/**********************************************************************************/ - /** * Function Add_Zone_Cutout * Add a cutout zone to a given zone outline * @param DC = current Device Context * @param zone_container = parent zone outline */ +void PCB_EDIT_FRAME::Add_Zone_Cutout( wxDC* DC, ZONE_CONTAINER* zone_container ) { if ( zone_container == NULL ) return; + s_AddCutoutToCurrentZone = true; s_CurrentZone = zone_container; @@ -93,15 +89,12 @@ void PCB_EDIT_FRAME::Add_Zone_Cutout( wxDC* DC, ZONE_CONTAINER* zone_container ) } -/*******************************************************/ -int PCB_EDIT_FRAME::Delete_LastCreatedCorner( wxDC* DC ) -/*******************************************************/ - /** Used **only** while creating a new zone outline * Remove and delete the current outline segment in progress * @return 0 if no corner in list, or corner number * if no corner in list, close the outline creation */ +int PCB_EDIT_FRAME::Delete_LastCreatedCorner( wxDC* DC ) { ZONE_CONTAINER* zone = GetBoard()->m_CurrentZoneContour; @@ -127,18 +120,16 @@ int PCB_EDIT_FRAME::Delete_LastCreatedCorner( wxDC* DC ) zone->RemoveAllContours(); zone->m_Flags = 0; } + return zone->GetNumCorners(); } -/*************************************************************************/ -static void Abort_Zone_Create_Outline( EDA_DRAW_PANEL* Panel, wxDC* DC ) -/*************************************************************************/ - /** * Function Abort_Zone_Create_Outline * cancels the Begin_Zone command if at least one EDGE_ZONE was created. */ +static void Abort_Zone_Create_Outline( EDA_DRAW_PANEL* Panel, wxDC* DC ) { PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent(); ZONE_CONTAINER* zone = pcbframe->GetBoard()->m_CurrentZoneContour; @@ -157,16 +148,13 @@ static void Abort_Zone_Create_Outline( EDA_DRAW_PANEL* Panel, wxDC* DC ) } -/*******************************************************************************************************/ -void PCB_EDIT_FRAME::Start_Move_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_container, - int corner_id, bool IsNewCorner ) -/*******************************************************************************************************/ - /** * Function Start_Move_Zone_Corner * Initialise parametres to move an existing corner of a zone. * if IsNewCorner is true, the Abort_Zone_Move_Corner_Or_Outlines will remove this corner, if called */ +void PCB_EDIT_FRAME::Start_Move_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_container, + int corner_id, bool IsNewCorner ) { if( zone_container->IsOnCopperLayer() ) /* Show the Net */ { @@ -177,6 +165,7 @@ void PCB_EDIT_FRAME::Start_Move_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_cont g_Zone_Default_Setting.m_NetcodeSelection = zone_container->GetNet(); GetBoard()->SetHightLightNet( zone_container->GetNet() ); + if( DC ) High_Light( DC ); } @@ -193,7 +182,9 @@ void PCB_EDIT_FRAME::Start_Move_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_cont _AuxiliaryList.ClearListAndDeleteItems(); s_PickedList.ClearListAndDeleteItems(); - SaveCopyOfZones(s_PickedList, GetBoard(), zone_container->GetNet(), zone_container->GetLayer() ); + SaveCopyOfZones( s_PickedList, GetBoard(), zone_container->GetNet(), + zone_container->GetLayer() ); + if ( IsNewCorner ) zone_container->m_Poly->InsertCorner(corner_id-1, cx, cy ); @@ -207,40 +198,34 @@ void PCB_EDIT_FRAME::Start_Move_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_cont } -/**************************************************************************************/ -void PCB_EDIT_FRAME::Start_Move_Zone_Drag_Outline_Edge( wxDC* DC, - ZONE_CONTAINER* zone_container, - int corner_id ) -/**************************************************************************************/ - /** * Function Start_Move_Zone_Drag_Outline_Edge * Prepares a drag edge for an existing zone outline, */ +void PCB_EDIT_FRAME::Start_Move_Zone_Drag_Outline_Edge( wxDC* DC, + ZONE_CONTAINER* zone_container, + int corner_id ) { zone_container->m_Flags = IS_DRAGGED; zone_container->m_CornerSelection = corner_id; DrawPanel->SetMouseCapture( Show_Zone_Corner_Or_Outline_While_Move_Mouse, - Abort_Zone_Move_Corner_Or_Outlines ); + Abort_Zone_Move_Corner_Or_Outlines ); s_CursorLastPosition = s_CornerInitialPosition = GetScreen()->GetCrossHairPosition(); s_AddCutoutToCurrentZone = false; s_CurrentZone = NULL; s_PickedList.ClearListAndDeleteItems(); _AuxiliaryList.ClearListAndDeleteItems(); - SaveCopyOfZones(s_PickedList, GetBoard(), zone_container->GetNet(), - zone_container->GetLayer() ); + SaveCopyOfZones( s_PickedList, GetBoard(), zone_container->GetNet(), + zone_container->GetLayer() ); } -/*******************************************************************************************************/ -void PCB_EDIT_FRAME::Start_Move_Zone_Outlines( wxDC* DC, ZONE_CONTAINER* zone_container ) -/*******************************************************************************************************/ - /** * Function Start_Move_Zone_Outlines * Initialise parametres to move an existing zone outlines. */ +void PCB_EDIT_FRAME::Start_Move_Zone_Outlines( wxDC* DC, ZONE_CONTAINER* zone_container ) { /* Show the Net */ if( zone_container->IsOnCopperLayer() ) /* Show the Net */ @@ -257,11 +242,12 @@ void PCB_EDIT_FRAME::Start_Move_Zone_Outlines( wxDC* DC, ZONE_CONTAINER* zone_co s_PickedList.ClearListAndDeleteItems(); _AuxiliaryList.ClearListAndDeleteItems(); - SaveCopyOfZones(s_PickedList, GetBoard(), zone_container->GetNet(), zone_container->GetLayer() ); + SaveCopyOfZones( s_PickedList, GetBoard(), zone_container->GetNet(), + zone_container->GetLayer() ); zone_container->m_Flags = IS_MOVED; DrawPanel->SetMouseCapture( Show_Zone_Corner_Or_Outline_While_Move_Mouse, - Abort_Zone_Move_Corner_Or_Outlines ); + Abort_Zone_Move_Corner_Or_Outlines ); s_CursorLastPosition = s_CornerInitialPosition = GetScreen()->GetCrossHairPosition(); s_CornerIsNew = false; s_AddCutoutToCurrentZone = false; @@ -269,16 +255,13 @@ void PCB_EDIT_FRAME::Start_Move_Zone_Outlines( wxDC* DC, ZONE_CONTAINER* zone_co } -/*************************************************************************************************/ -void PCB_EDIT_FRAME::End_Move_Zone_Corner_Or_Outlines( wxDC* DC, ZONE_CONTAINER* zone_container ) -/*************************************************************************************************/ - /** * Function End_Move_Zone_Corner_Or_Outlines * Terminates a move corner in a zone outline, or a move zone outlines * @param DC = current Device Context (can be NULL) * @param zone_container: the given zone */ +void PCB_EDIT_FRAME::End_Move_Zone_Corner_Or_Outlines( wxDC* DC, ZONE_CONTAINER* zone_container ) { zone_container->m_Flags = 0; DrawPanel->SetMouseCapture( NULL, NULL ); @@ -299,6 +282,7 @@ void PCB_EDIT_FRAME::End_Move_Zone_Corner_Or_Outlines( wxDC* DC, ZONE_CONTAINER* int ii = GetBoard()->GetAreaIndex( zone_container ); // test if zone_container exists + if( ii < 0 ) zone_container = NULL; // was removed by combining zones @@ -307,6 +291,7 @@ void PCB_EDIT_FRAME::End_Move_Zone_Corner_Or_Outlines( wxDC* DC, ZONE_CONTAINER* s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items int error_count = GetBoard()->Test_Drc_Areas_Outlines_To_Areas_Outlines( zone_container, true ); + if( error_count ) { DisplayError( this, _( "Area: DRC outline error" ) ); @@ -314,10 +299,6 @@ void PCB_EDIT_FRAME::End_Move_Zone_Corner_Or_Outlines( wxDC* DC, ZONE_CONTAINER* } -/*************************************************************************************/ -void PCB_EDIT_FRAME::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_container ) -/*************************************************************************************/ - /** * Function Remove_Zone_Corner * Remove the currently selected corner in a zone outline @@ -326,17 +307,20 @@ void PCB_EDIT_FRAME::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_containe * @param zone_container = the zone that contains the selected corner * the member .m_CornerSelection is used as selected corner */ +void PCB_EDIT_FRAME::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_container ) { OnModify(); if( zone_container->m_Poly->GetNumCorners() <= 3 ) { DrawPanel->RefreshDrawingRect( zone_container->GetBoundingBox() ); + if( DC ) { // Remove the full zone because this is no more an area zone_container->UnFill(); zone_container->DrawFilledArea( DrawPanel, DC, GR_XOR ); } + GetBoard()->Delete( zone_container ); return; } @@ -351,11 +335,13 @@ void PCB_EDIT_FRAME::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_containe _AuxiliaryList.ClearListAndDeleteItems(); s_PickedList. ClearListAndDeleteItems(); - SaveCopyOfZones(s_PickedList, GetBoard(), zone_container->GetNet(), zone_container->GetLayer() ); + SaveCopyOfZones( s_PickedList, GetBoard(), zone_container->GetNet(), + zone_container->GetLayer() ); zone_container->m_Poly->DeleteCorner( zone_container->m_CornerSelection ); // modify zones outlines according to the new zone_container shape GetBoard()->AreaPolygonModified( &_AuxiliaryList, zone_container, true, s_Verbose ); + if( DC ) { GetBoard()->RedrawAreasOutlines( DrawPanel, DC, GR_OR, layer ); @@ -367,9 +353,12 @@ void PCB_EDIT_FRAME::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_containe s_PickedList.ClearItemsList(); // s_ItemsListPicker is no more owner of picked items int ii = GetBoard()->GetAreaIndex( zone_container ); // test if zone_container exists + if( ii < 0 ) - zone_container = NULL; // zone_container does not exist anymaore, after combining zones + zone_container = NULL; // zone_container does not exist anymaore, after combining zones + int error_count = GetBoard()->Test_Drc_Areas_Outlines_To_Areas_Outlines( zone_container, true ); + if( error_count ) { DisplayError( this, _( "Area: DRC outline error" ) ); @@ -377,14 +366,11 @@ void PCB_EDIT_FRAME::Remove_Zone_Corner( wxDC* DC, ZONE_CONTAINER* zone_containe } -/**************************************************************************/ -void Abort_Zone_Move_Corner_Or_Outlines( EDA_DRAW_PANEL* Panel, wxDC* DC ) -/**************************************************************************/ - /** * Function Abort_Zone_Move_Corner_Or_Outlines * cancels the Begin_Zone state if at least one EDGE_ZONE has been created. */ +void Abort_Zone_Move_Corner_Or_Outlines( EDA_DRAW_PANEL* Panel, wxDC* DC ) { PCB_EDIT_FRAME* pcbframe = (PCB_EDIT_FRAME*) Panel->GetParent(); ZONE_CONTAINER* zone_container = (ZONE_CONTAINER*) pcbframe->GetCurItem(); @@ -456,16 +442,14 @@ void Show_Zone_Corner_Or_Outline_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* s_CursorLastPosition = pos; } else + { zone->m_Poly->MoveCorner( zone->m_CornerSelection, pos.x, pos.y ); + } zone->Draw( aPanel, aDC, GR_XOR ); } -/*************************************************/ -int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) -/*************************************************/ - /** * Function Begin_Zone * either initializes the first segment of a new zone, or adds an @@ -475,9 +459,11 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) * created from a similar zone (s_CurrentZone is used): parameters are copied from s_CurrentZone * created as a cutout (an hole) inside s_CurrentZone */ +int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) { // verify if s_CurrentZone exists (could be deleted since last selection) : int ii; + for( ii = 0; ii < GetBoard()->GetAreaCount(); ii++ ) { if( s_CurrentZone == GetBoard()->GetArea( ii ) ) @@ -495,7 +481,8 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) GetBoard()->m_CurrentZoneContour = new ZONE_CONTAINER( GetBoard() ); ZONE_CONTAINER* zone = GetBoard()->m_CurrentZoneContour; - if( zone->GetNumCorners() == 0 ) /* Start a new contour: init zone params (net, layer ...) */ + + if( zone->GetNumCorners() == 0 ) // Start a new contour: init zone params (net, layer ...) { if( s_CurrentZone == NULL ) // A new outline is created, from scratch { @@ -504,7 +491,8 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) zone->SetLayer( getActiveLayer() ); // Prompt user for parameters: - DrawPanel->m_IgnoreMouseEvents = TRUE; + DrawPanel->m_IgnoreMouseEvents = true; + if( zone->IsOnCopperLayer() ) { // Put a zone on a copper layer if ( GetBoard()->GetHightLightNetCode() > 0 ) @@ -516,9 +504,9 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) } wxGetApp().m_EDA_Config->Read( ZONE_THERMAL_RELIEF_GAP_STRING_KEY, - &g_Zone_Default_Setting.m_ThermalReliefGapValue ); + &g_Zone_Default_Setting.m_ThermalReliefGapValue ); wxGetApp().m_EDA_Config->Read( ZONE_THERMAL_RELIEF_COPPER_WIDTH_STRING_KEY, - &g_Zone_Default_Setting.m_ThermalReliefCopperBridgeValue ); + &g_Zone_Default_Setting.m_ThermalReliefCopperBridgeValue ); g_Zone_Default_Setting.m_CurrentZone_Layer = zone->GetLayer(); DIALOG_COPPER_ZONE* frame = new DIALOG_COPPER_ZONE( this, &g_Zone_Default_Setting ); @@ -530,8 +518,9 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) diag = InstallDialogNonCopperZonesEditor( zone ); g_Zone_Default_Setting.m_NetcodeSelection = 0; // No net for non copper zones } + DrawPanel->MoveCursorToCrossHair(); - DrawPanel->m_IgnoreMouseEvents = FALSE; + DrawPanel->m_IgnoreMouseEvents = false; if( diag == ZONE_ABORT ) return 0; @@ -539,8 +528,8 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) // Switch active layer to the selectec zonz layer setActiveLayer( g_Zone_Default_Setting.m_CurrentZone_Layer ); } - else // Start a new contour: init zone params (net and layer) from an existing zone (add cutout or similar zone) - { + else // Start a new contour: init zone params (net and layer) from an existing + { // zone (add cutout or similar zone) g_Zone_Default_Setting.m_CurrentZone_Layer = s_CurrentZone->GetLayer(); setActiveLayer( s_CurrentZone->GetLayer() ); g_Zone_Default_Setting.ImportSetting( * s_CurrentZone); @@ -551,6 +540,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) { if( s_CurrentZone ) g_Zone_Default_Setting.m_NetcodeSelection = s_CurrentZone->GetNet(); + if( GetBoard()->IsHightLightNetON() ) { High_Light( DC ); // Remove old hightlight selection @@ -559,6 +549,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) GetBoard()->SetHightLightNet( g_Zone_Default_Setting.m_NetcodeSelection ); High_Light( DC ); } + if( !s_AddCutoutToCurrentZone ) s_CurrentZone = NULL; // the zone is used only once ("add similar zone" command) } @@ -574,6 +565,7 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) GetScreen()->GetCrossHairPosition().y, zone->GetHatchStyle() ); zone->AppendCorner( GetScreen()->GetCrossHairPosition() ); + if( Drc_On && (m_drc->Drc( zone, 0 ) == BAD_DRC) && zone->IsOnCopperLayer() ) { zone->m_Flags = 0; @@ -584,25 +576,21 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) // PCB_EDIT_FRAME::SetCurItem() calls DisplayInfo(). GetScreen()->SetCurItem( NULL ); DisplayError( this, - _( "DRC error: this start point is inside or too close an other area" ) ); + _( "DRC error: this start point is inside or too close an other area" ) ); return 0; } SetCurItem( zone ); - DrawPanel->SetMouseCapture( Show_New_Edge_While_Move_Mouse, - Abort_Zone_Create_Outline ); + DrawPanel->SetMouseCapture( Show_New_Edge_While_Move_Mouse, Abort_Zone_Create_Outline ); } - // edge in progress: - else + else // edge in progress: { ii = zone->GetNumCorners() - 1; /* edge in progress : the current corner coordinate was set by Show_New_Edge_While_Move_Mouse */ if( zone->GetCornerPosition( ii - 1 ) != zone->GetCornerPosition( ii ) ) { - if( !Drc_On || !zone->IsOnCopperLayer() - || ( m_drc->Drc( zone, ii - 1 ) == OK_DRC ) - ) + if( !Drc_On || !zone->IsOnCopperLayer() || ( m_drc->Drc( zone, ii - 1 ) == OK_DRC ) ) { // Ok, we can add a new corner zone->AppendCorner( GetScreen()->GetCrossHairPosition() ); SetCurItem( zone ); // calls DisplayInfo(). @@ -614,10 +602,6 @@ int PCB_EDIT_FRAME::Begin_Zone( wxDC* DC ) } -/*********************************************/ -bool PCB_EDIT_FRAME::End_Zone( wxDC* DC ) -/*********************************************/ - /** * Function End_Zone * Terminates a zone outline creation @@ -626,6 +610,7 @@ bool PCB_EDIT_FRAME::End_Zone( wxDC* DC ) * @return true if Ok, false if DRC error * if ok, put it in the main list GetBoard()->m_ZoneDescriptorList (a vector) */ +bool PCB_EDIT_FRAME::End_Zone( wxDC* DC ) { ZONE_CONTAINER* zone = GetBoard()->m_CurrentZoneContour; @@ -645,10 +630,11 @@ bool PCB_EDIT_FRAME::End_Zone( wxDC* DC ) { if( Drc_On && m_drc->Drc( zone, icorner - 1 ) == BAD_DRC ) // we can't validate last edge return false; + if( Drc_On && m_drc->Drc( zone, icorner ) == BAD_DRC ) // we can't validate the closing edge { DisplayError( this, - _( "DRC error: closing this area creates a drc error with an other area" ) ); + _( "DRC error: closing this area creates a drc error with an other area" ) ); DrawPanel->MoveCursorToCrossHair(); return false; } @@ -705,10 +691,12 @@ bool PCB_EDIT_FRAME::End_Zone( wxDC* DC ) GetBoard()->RedrawFilledAreas( DrawPanel, DC, GR_OR, layer ); int ii = GetBoard()->GetAreaIndex( zone ); // test if zone_container exists + if( ii < 0 ) zone = NULL; // was removed by combining zones int error_count = GetBoard()->Test_Drc_Areas_Outlines_To_Areas_Outlines( zone, true ); + if( error_count ) { DisplayError( this, _( "Area: DRC outline error" ) ); @@ -750,7 +738,7 @@ static void Show_New_Edge_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC, { // calculate the new position as allowed wxPoint StartPoint = zone->GetCornerPosition( icorner - 1 ); - Calcule_Coord_Extremite_45( c_pos, StartPoint.x, StartPoint.y, &c_pos.x, &c_pos.y ); + CalculateSegmentEndPoint( c_pos, StartPoint.x, StartPoint.y, &c_pos.x, &c_pos.y ); } zone->SetCornerPosition( icorner, c_pos ); @@ -759,17 +747,14 @@ static void Show_New_Edge_While_Move_Mouse( EDA_DRAW_PANEL* aPanel, wxDC* aDC, } -/***********************************************************************************/ -void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* zone_container ) -/***********************************************************************************/ - /** * Function Edit_Zone_Params * Edit params (layer, clearance, ...) for a zone outline */ +void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* zone_container ) { int diag; - DrawPanel->m_IgnoreMouseEvents = TRUE; + DrawPanel->m_IgnoreMouseEvents = true; /* Save initial zones configuration, for undo/redo, before adding new zone * note the net name and the layer can be changed, so we must save all zones @@ -786,10 +771,12 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* zone_container frame->Destroy(); } else // edit a zone on a non copper layer (technical layer) + { diag = InstallDialogNonCopperZonesEditor( zone_container ); + } DrawPanel->MoveCursorToCrossHair(); - DrawPanel->m_IgnoreMouseEvents = FALSE; + DrawPanel->m_IgnoreMouseEvents = false; if( diag == ZONE_ABORT ) { @@ -797,6 +784,7 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* zone_container s_PickedList.ClearListAndDeleteItems(); return; } + if( diag == ZONE_EXPORT_VALUES ) { UpdateCopyOfZonesList( s_PickedList, _AuxiliaryList, GetBoard() ); @@ -814,6 +802,7 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* zone_container g_Zone_Default_Setting.ExportSetting( *zone_container); NETINFO_ITEM* net = GetBoard()->FindNet( g_Zone_Default_Setting.m_NetcodeSelection ); + if( net ) // net == NULL should not occur zone_container->m_Netname = net->GetNetname(); @@ -831,10 +820,6 @@ void PCB_EDIT_FRAME::Edit_Zone_Params( wxDC* DC, ZONE_CONTAINER* zone_container } -/************************************************************************************/ -void PCB_EDIT_FRAME::Delete_Zone_Contour( wxDC* DC, ZONE_CONTAINER* zone_container ) -/************************************************************************************/ - /** * Function Delete_Zone_Contour * Remove the zone which include the segment aZone, or the zone which have the given time stamp. @@ -845,6 +830,7 @@ void PCB_EDIT_FRAME::Delete_Zone_Contour( wxDC* DC, ZONE_CONTAINER* zone_contain * if the outline is the main outline, all the zone_container is removed (deleted) * otherwise, the hole is deleted */ +void PCB_EDIT_FRAME::Delete_Zone_Contour( wxDC* DC, ZONE_CONTAINER* zone_container ) { int ncont = zone_container->m_Poly->GetContour( zone_container->m_CornerSelection ); @@ -871,4 +857,3 @@ void PCB_EDIT_FRAME::Delete_Zone_Contour( wxDC* DC, ZONE_CONTAINER* zone_contain OnModify(); } - diff --git a/pcbnew/zones_by_polygon_fill_functions.cpp b/pcbnew/zones_by_polygon_fill_functions.cpp index 8e42e28bbb..64c0116d5c 100644 --- a/pcbnew/zones_by_polygon_fill_functions.cpp +++ b/pcbnew/zones_by_polygon_fill_functions.cpp @@ -37,7 +37,8 @@ /** * Function Delete_OldZone_Fill (obsolete) * Used for compatibility with old boards - * Remove the zone filling which include the segment aZone, or the zone which have the given time stamp. + * Remove the zone filling which include the segment aZone, or the zone which have the + * given time stamp. * A zone is a group of segments which have the same TimeStamp * @param aZone = zone segment within the zone to delete. Can be NULL * @param aTimestamp = Timestamp for the zone to delete, used if aZone == NULL @@ -53,12 +54,14 @@ void PCB_EDIT_FRAME::Delete_OldZone_Fill( SEGZONE* aZone, long aTimestamp ) TimeStamp = aZone->m_TimeStamp; // Save reference time stamp (aZone will be deleted) SEGZONE* next; + for( SEGZONE* zone = GetBoard()->m_Zone; zone != NULL; zone = next ) { next = zone->Next(); + if( zone->m_TimeStamp == TimeStamp ) { - modify = TRUE; + modify = true; /* remove item from linked list and free memory */ zone->DeleteStructure(); } @@ -116,7 +119,6 @@ int PCB_EDIT_FRAME::Fill_Zone( ZONE_CONTAINER* zone_container, bool verbose ) } -int PCB_EDIT_FRAME::Fill_All_Zones( bool verbose ) /** * Function Fill_All_Zones * Fill all zones on the board @@ -124,6 +126,7 @@ int PCB_EDIT_FRAME::Fill_All_Zones( bool verbose ) * @param verbose = true to show error messages * @return error level (0 = no error) */ +int PCB_EDIT_FRAME::Fill_All_Zones( bool verbose ) { int errorLevel = 0; int areaCount = GetBoard()->GetAreaCount(); @@ -133,8 +136,7 @@ int PCB_EDIT_FRAME::Fill_All_Zones( bool verbose ) // Create a message with a long net name, and build a wxProgressDialog // with a correct size to show this long net name - msg.Printf( FORMAT_STRING, - 000, areaCount, wxT("XXXXXXXXXXXXXXXXX" ) ); + msg.Printf( FORMAT_STRING, 000, areaCount, wxT("XXXXXXXXXXXXXXXXX" ) ); wxProgressDialog progressDialog( _( "Fill All Zones" ), msg, areaCount+2, this, wxPD_AUTO_HIDE | wxPD_APP_MODAL | wxPD_CAN_ABORT ); @@ -145,11 +147,11 @@ int PCB_EDIT_FRAME::Fill_All_Zones( bool verbose ) GetBoard()->m_Zone.DeleteAll(); int ii; + for( ii = 0; ii < areaCount; ii++ ) { ZONE_CONTAINER* zoneContainer = GetBoard()->GetArea( ii ); - msg.Printf( FORMAT_STRING, - ii+1, areaCount, GetChars( zoneContainer->GetNetName() ) ); + msg.Printf( FORMAT_STRING, ii+1, areaCount, GetChars( zoneContainer->GetNetName() ) ); if( !progressDialog.Update( ii+1, msg ) ) break; @@ -159,6 +161,7 @@ int PCB_EDIT_FRAME::Fill_All_Zones( bool verbose ) if( errorLevel && !verbose ) break; } + progressDialog.Update( ii+2, _( "Updating ratsnest..." ) ); test_connexions( NULL ); @@ -168,5 +171,3 @@ int PCB_EDIT_FRAME::Fill_All_Zones( bool verbose ) return errorLevel; } - - diff --git a/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp b/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp index 8fbbdc3bf8..f639aeda3f 100644 --- a/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp +++ b/pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp @@ -9,9 +9,11 @@ * calculated from these items shapes and the clearance area * * Important note: - * Because filled areas must have a minimum thickness to match with Design rule, they are draw in 2 step: + * Because filled areas must have a minimum thickness to match with Design rule, they are + * draw in 2 step: * 1 - filled polygons are drawn - * 2 - polygon outlines are drawn with a "minimum thickness width" ( or with a minimum thickness pen ) + * 2 - polygon outlines are drawn with a "minimum thickness width" ( or with a minimum + * thickness pen ) * So outlines of filled polygons are calculated with the constraint they match with clearance, * taking in account outlines have thickness * This ensures: @@ -38,8 +40,10 @@ extern void BuildUnconnectedThermalStubsPolygonList( std::vector& aCorn BOARD* aPcb, ZONE_CONTAINER* aZone, double aArcCorrection, int aRoundPadThermalRotation); + extern void Test_For_Copper_Island_And_Remove( BOARD* aPcb, ZONE_CONTAINER* aZone_container ); + extern void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, D_PAD& aPad, int aThermalGap, @@ -55,6 +59,7 @@ static void AddPolygonCornersToKPolygonList( std::vector & aCornersBuff static int CopyPolygonsFromKPolygonListToFilledPolysList( ZONE_CONTAINER* aZone, KPolygonSet& aKPolyList ); + static int CopyPolygonsFromFilledPolysListTotKPolygonList( ZONE_CONTAINER* aZone, KPolygonSet& aKPolyList ); @@ -86,9 +91,10 @@ double s_Correction; /* mult coeff used to enlarge rounded and oval pads (an * 1 - Creates the main outline (zone outline) using a correction to shrink the resulting area * with m_ZoneMinThickness/2 value. * The result is areas with a margin of m_ZoneMinThickness/2 - * When drawing outline with segments having a thickness of m_ZoneMinThickness, the outlines will - * match exactly the initial outlines - * 3 - Add all non filled areas (pads, tracks) in group B with a clearance of m_Clearance + m_ZoneMinThickness/2 + * When drawing outline with segments having a thickness of m_ZoneMinThickness, the + * outlines will match exactly the initial outlines + * 3 - Add all non filled areas (pads, tracks) in group B with a clearance of m_Clearance + + * m_ZoneMinThickness/2 * in a buffer * - If Thermal shapes are wanted, add non filled area, in order to create these thermal shapes * 4 - calculates the polygon A - B @@ -96,9 +102,9 @@ double s_Correction; /* mult coeff used to enlarge rounded and oval pads (an * This zone contains pads with the same net. * 6 - Remove insulated copper islands * 7 - If Thermal shapes are wanted, remove unconnected stubs in thermal shapes: - * creates a buffer of polygons corresponding to stubs to remove - * sub them to the filled areas. - * Remove new insulated copper islands + * creates a buffer of polygons corresponding to stubs to remove + * sub them to the filled areas. + * Remove new insulated copper islands */ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) { @@ -134,8 +140,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) * the main polygon is stored in polyset_zone_solid_areas */ - CopyPolygonsFromFilledPolysListTotKPolygonList( this, - polyset_zone_solid_areas ); + CopyPolygonsFromFilledPolysListTotKPolygonList( this, polyset_zone_solid_areas ); polyset_zone_solid_areas -= margin; if( polyset_zone_solid_areas.size() == 0 ) @@ -189,17 +194,21 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) { for( D_PAD* pad = module->m_Pads; pad != NULL; pad = nextpad ) { - nextpad = pad->Next(); // pad pointer can be modified by next code, so calculate the next pad here + nextpad = pad->Next(); // pad pointer can be modified by next code, so + // calculate the next pad here + if( !pad->IsOnLayer( GetLayer() ) ) { /* Test for pads that are on top or bottom only and have a hole. - * There are curious pads but they can be used for some components that are inside the - * board (in fact inside the hole. Some photo diodes and Leds are like this) + * There are curious pads but they can be used for some components that are + * inside the board (in fact inside the hole. Some photo diodes and Leds are + * like this) */ if( (pad->m_Drill.x == 0) && (pad->m_Drill.y == 0) ) continue; - // Use a dummy pad to calculate a hole shape that have the same dimension as the pad hole + // Use a dummy pad to calculate a hole shape that have the same dimension as + // the pad hole dummypad.m_Size = pad->m_Drill; dummypad.m_Orient = pad->m_Orient; dummypad.m_PadShape = pad->m_DrillShape; @@ -211,6 +220,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) { item_clearance = pad->GetClearance() + margin; item_boundingbox = pad->GetBoundingBox(); + if( item_boundingbox.Intersects( zone_boundingbox ) ) { int clearance = MAX( zone_clearance, item_clearance ); @@ -219,10 +229,12 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) s_CircleToSegmentsCount, s_Correction ); } + continue; } int gap = zone_clearance; + if( (m_PadOption == PAD_NOT_IN_ZONE) || (GetNet() == 0) || pad->m_PadShape == PAD_TRAPEZOID ) @@ -230,6 +242,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) // and i think it is good that shapes are not changed by thermal pads or others { item_boundingbox = pad->GetBoundingBox(); + if( item_boundingbox.Intersects( zone_boundingbox ) ) { pad->TransformShapeWithClearanceToPolygon( cornerBufferPolysToSubstract, @@ -248,11 +261,13 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) { if( !track->IsOnLayer( GetLayer() ) ) continue; + if( track->GetNet() == GetNet() && (GetNet() != 0) ) continue; item_clearance = track->GetClearance() + margin; item_boundingbox = track->GetBoundingBox(); + if( item_boundingbox.Intersects( zone_boundingbox ) ) { int clearance = MAX( zone_clearance, item_clearance ); @@ -273,9 +288,12 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) { if( !item->IsOnLayer( GetLayer() ) ) continue; + if( item->Type() != TYPE_EDGE_MODULE ) continue; + item_boundingbox = item->GetBoundingBox(); + if( item_boundingbox.Intersects( zone_boundingbox ) ) { ( (EDGE_MODULE*) item )->TransformShapeWithClearanceToPolygon( @@ -301,7 +319,6 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) s_Correction ); break; - case TYPE_TEXTE: ( (TEXTE_PCB*) item )->TransformShapeWithClearanceToPolygon( cornerBufferPolysToSubstract, @@ -329,6 +346,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) continue; item_boundingbox = pad->GetBoundingBox(); item_boundingbox.Inflate( m_ThermalReliefGapValue, m_ThermalReliefGapValue ); + if( item_boundingbox.Intersects( zone_boundingbox ) ) { CreateThermalReliefPadPolygon( cornerBufferPolysToSubstract, @@ -348,8 +366,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) if( cornerBufferPolysToSubstract.size() > 0 ) { KPolygonSet polyset_holes; - AddPolygonCornersToKPolygonList( cornerBufferPolysToSubstract, - polyset_holes ); + AddPolygonCornersToKPolygonList( cornerBufferPolysToSubstract, polyset_holes ); // Remove holes from initial area.: polyset_zone_solid_areas -= polyset_holes; } @@ -362,12 +379,13 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) if( GetNet() > 0 ) Test_For_Copper_Island_And_Remove_Insulated_Islands( aPcb ); -// Now we remove all unused thermal stubs. + // Now we remove all unused thermal stubs. if( m_PadOption == THERMAL_PAD ) { cornerBufferPolysToSubstract.clear(); // Test thermal stubs connections and add polygons to remove unconnected stubs. - BuildUnconnectedThermalStubsPolygonList( cornerBufferPolysToSubstract, aPcb, this, s_Correction, s_thermalRot ); + BuildUnconnectedThermalStubsPolygonList( cornerBufferPolysToSubstract, aPcb, this, + s_Correction, s_thermalRot ); /* remove copper areas */ if( cornerBufferPolysToSubstract.size() ) @@ -379,6 +397,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) /* put these areas in m_FilledPolysList */ m_FilledPolysList.clear(); CopyPolygonsFromKPolygonListToFilledPolysList( this, polyset_zone_solid_areas ); + if( GetNet() > 0 ) Test_For_Copper_Island_And_Remove_Insulated_Islands( aPcb ); } @@ -387,15 +406,15 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) cornerBufferPolysToSubstract.clear(); } -void AddPolygonCornersToKPolygonList( std::vector & - aCornersBuffer, - KPolygonSet& aKPolyList ) +void AddPolygonCornersToKPolygonList( std::vector & aCornersBuffer, + KPolygonSet& aKPolyList ) { unsigned ii; std::vector cornerslist; int polycount = 0; + for( unsigned ii = 0; ii < aCornersBuffer.size(); ii++ ) { if( aCornersBuffer[ii].end_contour ) @@ -408,10 +427,11 @@ void AddPolygonCornersToKPolygonList( std::vector & { KPolygon poly; cornerslist.clear(); + for( ii = icnt; ii < aCornersBuffer.size(); ii++ ) { - cornerslist.push_back( KPolyPoint( aCornersBuffer[ii].x, - aCornersBuffer[ii].y ) ); + cornerslist.push_back( KPolyPoint( aCornersBuffer[ii].x, aCornersBuffer[ii].y ) ); + if( aCornersBuffer[ii].end_contour ) break; } @@ -423,9 +443,8 @@ void AddPolygonCornersToKPolygonList( std::vector & } -int CopyPolygonsFromKPolygonListToFilledPolysList( ZONE_CONTAINER* - aZone, KPolygonSet& - aKPolyList ) +int CopyPolygonsFromKPolygonListToFilledPolysList( ZONE_CONTAINER* aZone, + KPolygonSet& aKPolyList ) { int count = 0; @@ -433,6 +452,7 @@ int CopyPolygonsFromKPolygonListToFilledPolysList( ZONE_CONTAINER* { KPolygon& poly = aKPolyList[ii]; CPolyPt corner( 0, 0, false ); + for( unsigned jj = 0; jj < poly.size(); jj++ ) { KPolyPoint point = *(poly.begin() + jj); @@ -456,9 +476,8 @@ int CopyPolygonsFromKPolygonListToFilledPolysList( ZONE_CONTAINER* } -int CopyPolygonsFromFilledPolysListTotKPolygonList( ZONE_CONTAINER* - aZone, KPolygonSet& - aKPolyList ) +int CopyPolygonsFromFilledPolysListTotKPolygonList( ZONE_CONTAINER* aZone, + KPolygonSet& aKPolyList ) { unsigned corners_count = aZone->m_FilledPolysList.size(); int count = 0; @@ -469,12 +488,14 @@ int CopyPolygonsFromFilledPolysListTotKPolygonList( ZONE_CONTAINER* for( unsigned ii = 0; ii < corners_count; ii++ ) { CPolyPt* corner = &aZone->m_FilledPolysList[ic]; + if( corner->end_contour ) polycount++; } aKPolyList.reserve( polycount ); std::vector cornerslist; + while( ic < corners_count ) { cornerslist.clear(); @@ -485,6 +506,7 @@ int CopyPolygonsFromFilledPolysListTotKPolygonList( ZONE_CONTAINER* CPolyPt* corner = &aZone->m_FilledPolysList[ic]; cornerslist.push_back( KPolyPoint( corner->x, corner->y ) ); count++; + if( corner->end_contour ) { ic++; diff --git a/pcbnew/zones_convert_brd_items_to_polygons_with_Kbool.cpp b/pcbnew/zones_convert_brd_items_to_polygons_with_Kbool.cpp index 33e4104a71..35bf1c98b5 100644 --- a/pcbnew/zones_convert_brd_items_to_polygons_with_Kbool.cpp +++ b/pcbnew/zones_convert_brd_items_to_polygons_with_Kbool.cpp @@ -9,9 +9,11 @@ * calculated from these items shapes and the clearance area * * Important note: - * Because filled areas must have a minimum thickness to match with Design rule, they are draw in 2 step: + * Because filled areas must have a minimum thickness to match with Design rule, they are + * draw in 2 step: * 1 - filled polygons are drawn - * 2 - polygon outlines are drawn with a "minimum thickness width" ( or with a minimum thickness pen ) + * 2 - polygon outlines are drawn with a "minimum thickness width" ( or with a minimum + * thickness pen ) * So outlines of filled polygons are calculated with the constraint they match with clearance, * taking in account outlines have thickness * This ensures: @@ -31,7 +33,8 @@ #include "PolyLine.h" -// Kbool 1.9 and before had sometimes problemes when calculating thermal shapes as polygons (this is the best solution) +// Kbool 1.9 and before had sometimes problemes when calculating thermal shapes as polygons +// (this is the best solution) // Kbool 2.0 has solved some problems, but not all // Kbool 2.1 has solved some others problems, but not all @@ -47,8 +50,10 @@ extern void BuildUnconnectedThermalStubsPolygonList( std::vector& aCorn BOARD* aPcb, ZONE_CONTAINER* aZone, double aArcCorrection, int aRoundPadThermalRotation); + extern void Test_For_Copper_Island_And_Remove( BOARD* aPcb, ZONE_CONTAINER* aZone_container ); + extern void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, D_PAD& aPad, int aThermalGap, @@ -90,23 +95,27 @@ double s_Correction; /* mult coeff used to enlarge rounded and oval pads (an * BuildFilledPolysListData() call this function just after creating the * filled copper area polygon (without clearence areas * to do that this function: - * 1 - creates a Bool_Engine,with option: holes are linked to outer contours by double overlapping segments - * this means the created polygons have no holes (hole are linked to outer outline by double overlapped segments - * and are therefore compatible with draw functions (DC draw polygons and Gerber or PS outputs) + * 1 - creates a Bool_Engine,with option: holes are linked to outer contours by double + * overlapping segments this means the created polygons have no holes (hole are linked + * to outer outline by double overlapped segments and are therefore compatible with + * draw functions (DC draw polygons and Gerber or PS outputs) * 2 - Add the main outline (zone outline) in group A * 3 - Creates a correction using BOOL_CORRECTION operation to shrink the resulting area * with m_ZoneMinThickness/2 value. * The result is areas with a margin of m_ZoneMinThickness/2 - * When drawing outline with segments having a thickness of m_ZoneMinThickness, the outlines will + * When drawing outline with segments having a thickness of m_ZoneMinThickness, the + * outlines will * match exactly the initial outlines * 4 - recreates the same Bool_Engine, with no correction * 5 - Add the main modified outline (zone outline) in group A - * 6 - Add all non filled areas (pads, tracks) in group B with a clearance of m_Clearance + m_ZoneMinThickness/2 + * 6 - Add all non filled areas (pads, tracks) in group B with a clearance of m_Clearance + + * m_ZoneMinThickness/2 * 7 - calculates the polygon A - B * 8 - put resulting list of polygons (filled areas) in m_FilledPolysList * This zone contains pads with the same net. * 9 - Remove insulated copper islands - * 10 - If Thermal shapes are wanted, remove copper around pads in zone, in order to create thes thermal shapes + * 10 - If Thermal shapes are wanted, remove copper around pads in zone, in order to create + * thes thermal shapes * a - Creates a bool engine and add the last copper areas in group A * b - Add thermal shapes (non copper ares in group B * c - Calculates the polygon A - B @@ -223,11 +232,13 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) MODULE dummymodule( aPcb ); // Creates a dummy parent D_PAD dummypad( &dummymodule ); D_PAD* nextpad; + for( MODULE* module = aPcb->m_Modules; module; module = module->Next() ) { for( D_PAD* pad = module->m_Pads; pad != NULL; pad = nextpad ) { nextpad = pad->Next(); // pad pointer can be modified by next code, so calculate the next pad here + if( !pad->IsOnLayer( GetLayer() ) ) { /* Test fo pads that are on top or bottom only and have a hole. @@ -249,6 +260,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) { item_clearance = pad->GetClearance() + margin; item_boundingbox = pad->GetBoundingBox(); + if( item_boundingbox.Intersects( zone_boundingbox ) ) { int clearance = MAX( zone_clearance, item_clearance ); @@ -261,13 +273,15 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) } int gap = zone_clearance; + if( (m_PadOption == PAD_NOT_IN_ZONE) - || (GetNet() == 0) || pad->m_PadShape == PAD_TRAPEZOID ) + || (GetNet() == 0) || pad->m_PadShape == PAD_TRAPEZOID ) // PAD_TRAPEZOID shapes are not in zones because they are used in microwave apps // and i think it is good that shapes are not changed by thermal pads or others { item_boundingbox = pad->GetBoundingBox(); + if( item_boundingbox.Intersects( zone_boundingbox ) ) { pad->TransformShapeWithClearanceToPolygon( cornerBufferPolysToSubstract, @@ -286,11 +300,13 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) { if( !track->IsOnLayer( GetLayer() ) ) continue; + if( track->GetNet() == GetNet() && (GetNet() != 0) ) continue; item_clearance = track->GetClearance() + margin; item_boundingbox = track->GetBoundingBox(); + if( item_boundingbox.Intersects( zone_boundingbox ) ) { int clearance = MAX( zone_clearance, item_clearance ); @@ -311,9 +327,12 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) { if( !item->IsOnLayer( GetLayer() ) ) continue; + if( item->Type() != TYPE_EDGE_MODULE ) continue; + item_boundingbox = item->GetBoundingBox(); + if( item_boundingbox.Intersects( zone_boundingbox ) ) { ( (EDGE_MODULE*) item )->TransformShapeWithClearanceToPolygon( @@ -355,17 +374,18 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) // cornerBufferPolysToSubstract contains polygons to substract, // prepare booleng to do that: - AddPolygonCornersToBoolengine( cornerBufferPolysToSubstract, - booleng, GROUP_B ); + AddPolygonCornersToBoolengine( cornerBufferPolysToSubstract, booleng, GROUP_B ); #ifdef CREATE_KBOOL_KEY_FILES_FIRST_PASS for( unsigned icnt = 0; icnt < cornerBuffer.size(); ) { StartKeyFilePolygon( 1 ); + for( ii = icnt; ii < cornerBuffer.size(); ii++ ) { AddKeyFilePointXY( cornerBufferPolysToSubstract[ii].x, cornerBufferPolysToSubstract[ii].y ); + if( cornerBufferPolysToSubstract[ii].end_contour ) break; } @@ -392,9 +412,10 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) m_FilledPolysList.clear(); CopyPolygonsFromBoolengineToFilledPolysList( booleng ); } + delete booleng; -// Remove insulated islands: + // Remove insulated islands: if( GetNet() > 0 ) Test_For_Copper_Island_And_Remove_Insulated_Islands( aPcb ); @@ -402,8 +423,9 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) if( m_PadOption != THERMAL_PAD || aPcb->m_Modules == NULL ) return; -// Remove thermal symbols + // Remove thermal symbols cornerBufferPolysToSubstract.clear(); + if( m_PadOption == THERMAL_PAD ) { booleng = new Bool_Engine(); @@ -424,8 +446,10 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) if( pad->GetNet() != GetNet() ) continue; + item_boundingbox = pad->GetBoundingBox(); item_boundingbox.Inflate( m_ThermalReliefGapValue ); + if( item_boundingbox.Intersects( zone_boundingbox ) ) { CreateThermalReliefPadPolygon( cornerBufferPolysToSubstract, @@ -447,8 +471,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) // cornerBufferPolysToSubstract contains polygons to substract, // prepare booleng to do that: - AddPolygonCornersToBoolengine( cornerBufferPolysToSubstract, - booleng, GROUP_B ); + AddPolygonCornersToBoolengine( cornerBufferPolysToSubstract, booleng, GROUP_B ); /* remove thermal areas (non copper areas) */ booleng->Do_Operation( BOOL_A_SUB_B ); @@ -456,19 +479,23 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) m_FilledPolysList.clear(); CopyPolygonsFromBoolengineToFilledPolysList( booleng ); } + delete booleng; // Remove insulated islands: if( GetNet() > 0 ) Test_For_Copper_Island_And_Remove_Insulated_Islands( aPcb ); + #ifdef CREATE_KBOOL_KEY_FILES for( unsigned icnt = 0; icnt < cornerBufferPolysToSubstract.size(); ) { StartKeyFilePolygon( 1 ); + for( ii = icnt; ii < cornerBufferPolysToSubstract.size(); ii++ ) { AddKeyFilePointXY( cornerBufferPolysToSubstract[ii].x, cornerBufferPolysToSubstract[ii].y ); + if( cornerBufferPolysToSubstract[ii].end_contour ) break; } @@ -477,6 +504,7 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) icnt = ii + 1; } } + CloseKeyFileEntity(); CloseKeyFile(); #endif @@ -490,7 +518,9 @@ void ZONE_CONTAINER::AddClearanceAreasPolygonsToPolysList( BOARD* aPcb ) booleng = new Bool_Engine(); ArmBoolEng( booleng, true ); cornerBufferPolysToSubstract.clear(); - BuildUnconnectedThermalStubsPolygonList( cornerBufferPolysToSubstract, aPcb, this, s_Correction, s_thermalRot ); + BuildUnconnectedThermalStubsPolygonList( cornerBufferPolysToSubstract, aPcb, this, + s_Correction, s_thermalRot ); + /* remove copper areas */ if( cornerBufferPolysToSubstract.size() ) { @@ -531,9 +561,11 @@ void AddPolygonCornersToBoolengine( std::vector & aCornersBuffer, for( unsigned icnt = 0; icnt < aCornersBuffer.size(); ) { aBoolengine->StartPolygonAdd( aGroup ); + for( ii = icnt; ii < aCornersBuffer.size(); ii++ ) { aBoolengine->AddPoint( aCornersBuffer[ii].x, aCornersBuffer[ii].y ); + if( aCornersBuffer[ii].end_contour ) break; } @@ -544,11 +576,6 @@ void AddPolygonCornersToBoolengine( std::vector & aCornersBuffer, } -/***********************************************************************************************************/ -int ZONE_CONTAINER::CopyPolygonsFromFilledPolysListToBoolengine( Bool_Engine* aBoolengine, - GroupType aGroup ) -/************************************************************************************************************/ - /** * Function CopyPolygonsFromFilledPolysListToBoolengine * Copy (Add) polygons found in m_FilledPolysList to kbool BoolEngine @@ -557,6 +584,8 @@ int ZONE_CONTAINER::CopyPolygonsFromFilledPolysListToBoolengine( Bool_Engine* aB * @param aGroup = group in kbool engine (GROUP_A or GROUP_B only) * @return the corner count */ +int ZONE_CONTAINER::CopyPolygonsFromFilledPolysListToBoolengine( Bool_Engine* aBoolengine, + GroupType aGroup ) { unsigned corners_count = m_FilledPolysList.size(); int count = 0; @@ -571,6 +600,7 @@ int ZONE_CONTAINER::CopyPolygonsFromFilledPolysListToBoolengine( Bool_Engine* aB CPolyPt* corner = &m_FilledPolysList[ic]; aBoolengine->AddPoint( corner->x, corner->y ); count++; + if( corner->end_contour ) { ic++; @@ -586,22 +616,20 @@ int ZONE_CONTAINER::CopyPolygonsFromFilledPolysListToBoolengine( Bool_Engine* aB } -/*****************************************************************************************/ -int ZONE_CONTAINER::CopyPolygonsFromBoolengineToFilledPolysList( Bool_Engine* aBoolengine ) -/*****************************************************************************************/ - /** * Function CopyPolygonsFromBoolengineToFilledPolysList * Copy (Add) polygons created by kbool (after Do_Operation) to m_FilledPolysList * @param aBoolengine = kbool engine * @return the corner count */ +int ZONE_CONTAINER::CopyPolygonsFromBoolengineToFilledPolysList( Bool_Engine* aBoolengine ) { int count = 0; while( aBoolengine->StartPolygonGet() ) { CPolyPt corner( 0, 0, false ); + while( aBoolengine->PolygonHasMorePoints() ) { corner.x = (int) aBoolengine->GetPolygonXPoint(); diff --git a/pcbnew/zones_non_copper_type_functions.cpp b/pcbnew/zones_non_copper_type_functions.cpp index 6c6470447c..b247cf29d8 100644 --- a/pcbnew/zones_non_copper_type_functions.cpp +++ b/pcbnew/zones_non_copper_type_functions.cpp @@ -38,12 +38,10 @@ public: }; -/*******************************************************************************************/ DialogNonCopperZonesEditor::DialogNonCopperZonesEditor( PCB_EDIT_FRAME* parent, ZONE_CONTAINER* zone_container, ZONE_SETTING* zone_setting ) : DialogNonCopperZonesPropertiesBase( parent ) -/*******************************************************************************************/ { m_Parent = parent; m_Zone_Container = zone_container; @@ -54,9 +52,7 @@ DialogNonCopperZonesEditor::DialogNonCopperZonesEditor( PCB_EDIT_FRAME* parent, } -/********************************************************/ DialogNonCopperZonesEditor::~DialogNonCopperZonesEditor() -/********************************************************/ { } @@ -70,9 +66,7 @@ bool PCB_EDIT_FRAME::InstallDialogNonCopperZonesEditor( ZONE_CONTAINER* aZone ) } -/********************************************************************/ void DialogNonCopperZonesEditor::Init() -/********************************************************************/ { SetFocus(); SetReturnCode( ZONE_ABORT ); // Will be changed on buttons click @@ -81,8 +75,8 @@ void DialogNonCopperZonesEditor::Init() AddUnitSymbol( *m_MinThicknessValueTitle, g_UserUnit ); wxString msg = ReturnStringFromValue( g_UserUnit, - m_Zone_Setting->m_ZoneMinThickness, - m_Parent->m_InternalUnits ); + m_Zone_Setting->m_ZoneMinThickness, + m_Parent->m_InternalUnits ); m_ZoneMinThicknessCtrl->SetValue( msg ); if( g_Zone_45_Only ) @@ -126,18 +120,16 @@ void DialogNonCopperZonesEditor::Init() } -/******************************************************************/ void DialogNonCopperZonesEditor::OnOkClick( wxCommandEvent& event ) -/******************************************************************/ { wxString txtvalue = m_ZoneMinThicknessCtrl->GetValue(); m_Zone_Setting->m_ZoneMinThickness = ReturnValueFromString( g_UserUnit, txtvalue, m_Parent->m_InternalUnits ); + if( m_Zone_Setting->m_ZoneMinThickness < 10 ) { DisplayError( this, - _( - "Error :\nyou must choose a copper min thickness value bigger than 0.001 inch (or 0.0254 mm)" ) ); + _( "Error :\nyou must choose a copper min thickness value bigger than 0.001 inch (or 0.0254 mm)" ) ); return; } @@ -165,25 +157,25 @@ void DialogNonCopperZonesEditor::OnOkClick( wxCommandEvent& event ) } if( m_OrientEdgesOpt->GetSelection() == 0 ) - g_Zone_45_Only = FALSE; + g_Zone_45_Only = false; else - g_Zone_45_Only = TRUE; + g_Zone_45_Only = true; /* Get the layer selection for this zone */ int ii = m_LayerSelectionCtrl->GetSelection(); + if( ii < 0 ) { DisplayError( this, _( "Error : you must choose a layer" ) ); return; } + g_Zone_Default_Setting.m_CurrentZone_Layer = ii + FIRST_NO_COPPER_LAYER; EndModal( ZONE_OK ); } -/**********************************************************************/ void DialogNonCopperZonesEditor::OnCancelClick( wxCommandEvent& event ) -/**********************************************************************/ { EndModal( ZONE_ABORT ); } diff --git a/pcbnew/zones_test_and_combine_areas.cpp b/pcbnew/zones_test_and_combine_areas.cpp index 235a4edb24..76fc9fff03 100644 --- a/pcbnew/zones_test_and_combine_areas.cpp +++ b/pcbnew/zones_test_and_combine_areas.cpp @@ -1019,7 +1019,7 @@ bool DRC::doEdgeZoneDrc( ZONE_CONTAINER* aArea, int aCornerIndex ) wxPoint end; // Search the end point of the edge starting at aCornerIndex - if( aArea->m_Poly->corner[aCornerIndex].end_contour == FALSE + if( aArea->m_Poly->corner[aCornerIndex].end_contour == false && aCornerIndex < (aArea->GetNumCorners() - 1) ) { end = aArea->GetCornerPosition( aCornerIndex + 1 );