diff --git a/include/convert_to_biu.h b/include/convert_to_biu.h new file mode 100644 index 0000000000..8fc2281fa9 --- /dev/null +++ b/include/convert_to_biu.h @@ -0,0 +1,38 @@ +#ifndef CONVERT_TO_BIU_H +#define CONVERT_TO_BIU_H + +#include // USE_PCBNEW_NANOMETRES is defined here + +/** + * @file convert_to_biu.h + */ + + +/** + * @brief inline convert functions to convert a value in decimils (or mils) + * to the internal unit used in pcbnew or cvpcb(nanometer or decimil) + * depending on compil option + */ + +/// Convert mils to PCBNEW internal units (iu). +inline int Mils2iu( int mils ) +{ +#if defined( USE_PCBNEW_NANOMETRES ) + return int( mils * 25.4e3 + 0.5 ); +#else + return mils * 10; +#endif +} + +/// Convert deci-mils to PCBNEW internal units (iu). +inline int DMils2iu( int dmils ) +{ +#if defined( USE_PCBNEW_NANOMETRES ) + return int( dmils * 25.4e2 + 0.5 ); +#else + return dmils; +#endif +} + +#endif // #define CONVERT_TO_BIU_H + diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 6be88e0307..1181c4ae12 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -71,13 +71,6 @@ BOARD::BOARD() : BOARD::~BOARD() { - /* @todo - NO! this has nothing to do with a BOARD - Do this in the UI, not in the storage container please. - if( m_PcbFrame && m_PcbFrame->GetScreen() ) - m_PcbFrame->GetScreen()->ClearUndoRedoList(); - */ - while( m_ZoneDescriptorList.size() ) { ZONE_CONTAINER* area_to_remove = m_ZoneDescriptorList[0]; diff --git a/pcbnew/class_board.h b/pcbnew/class_board.h index 0716ac51ea..3dae2934c3 100644 --- a/pcbnew/class_board.h +++ b/pcbnew/class_board.h @@ -272,6 +272,14 @@ public: */ static wxString GetDefaultLayerName( int aLayerNumber ); + /** + * Function ReturnFlippedLayerNumber + * @return the layer number after flipping an item + * some (not all) layers: external copper, Mask, Paste, and solder + * are swapped between front and back sides + */ + static int ReturnFlippedLayerNumber( int oldlayer ); + /** * Function Add * adds the given item to this BOARD and takes ownership of its memory. diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index 6582ad8ad0..d80584c91d 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include @@ -200,7 +199,7 @@ void DIMENSION::Rotate( const wxPoint& aRotCentre, double aAngle ) void DIMENSION::Flip( const wxPoint& aCentre ) { Mirror( aCentre ); - SetLayer( ChangeSideNumLayer( GetLayer() ) ); + SetLayer( BOARD::ReturnFlippedLayerNumber( GetLayer() ) ); } diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index a72e569b6a..7c710e179a 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -107,7 +107,7 @@ void DRAWSEGMENT::Flip( const wxPoint& aCentre ) NEGATE( m_Angle ); } - SetLayer( ChangeSideNumLayer( GetLayer() ) ); + SetLayer( BOARD::ReturnFlippedLayerNumber( GetLayer() ) ); } diff --git a/pcbnew/class_mire.cpp b/pcbnew/class_mire.cpp index e989ef1d27..5a18558e9a 100644 --- a/pcbnew/class_mire.cpp +++ b/pcbnew/class_mire.cpp @@ -189,7 +189,7 @@ void PCB_TARGET::Rotate(const wxPoint& aRotCentre, double aAngle) void PCB_TARGET::Flip(const wxPoint& aCentre ) { m_Pos.y = aCentre.y - ( m_Pos.y - aCentre.y ); - SetLayer( ChangeSideNumLayer( GetLayer() ) ); + SetLayer( BOARD::ReturnFlippedLayerNumber( GetLayer() ) ); } diff --git a/pcbnew/class_module_transform_functions.cpp b/pcbnew/class_module_transform_functions.cpp index 171afdfbe1..3bcc462b6c 100644 --- a/pcbnew/class_module_transform_functions.cpp +++ b/pcbnew/class_module_transform_functions.cpp @@ -11,15 +11,18 @@ #include #include +#include #include #include #include -/* Calculate the layer number for changing cu / cmp layers for Cu / CMP - * (Copper, Mask, Paste, solder) + +/* Returns the layer number after flipping an item + * some layers: external copper, Mask, Paste, and solder + * are swapped between front and back sides */ -int ChangeSideNumLayer( int oldlayer ) +int BOARD::ReturnFlippedLayerNumber( int oldlayer ) { int newlayer; @@ -155,7 +158,7 @@ void MODULE::Flip( const wxPoint& aCentre ) SetPosition( finalPos ); // Flip layer - SetLayer( ChangeSideNumLayer( GetLayer() ) ); + SetLayer( BOARD::ReturnFlippedLayerNumber( GetLayer() ) ); // Reverse mirror orientation. NEGATE( m_Orient ); @@ -174,7 +177,7 @@ void MODULE::Flip( const wxPoint& aCentre ) pt_texte->m_Mirror = false; NEGATE_AND_NORMALIZE_ANGLE_POS( pt_texte->m_Orient ); pt_texte->SetLayer( GetLayer() ); - pt_texte->SetLayer( ChangeSideNumLayer( pt_texte->GetLayer() ) ); + pt_texte->SetLayer( BOARD::ReturnFlippedLayerNumber( pt_texte->GetLayer() ) ); if( GetLayer() == LAYER_N_BACK ) pt_texte->SetLayer( SILKSCREEN_N_BACK ); @@ -195,7 +198,7 @@ void MODULE::Flip( const wxPoint& aCentre ) pt_texte->m_Mirror = false; NEGATE_AND_NORMALIZE_ANGLE_POS( pt_texte->m_Orient ); pt_texte->SetLayer( GetLayer() ); - pt_texte->SetLayer( ChangeSideNumLayer( pt_texte->GetLayer() ) ); + pt_texte->SetLayer( BOARD::ReturnFlippedLayerNumber( pt_texte->GetLayer() ) ); if( GetLayer() == LAYER_N_BACK ) pt_texte->SetLayer( SILKSCREEN_N_BACK ); @@ -236,7 +239,7 @@ void MODULE::Flip( const wxPoint& aCentre ) em->SetAngle( -em->GetAngle() ); } - em->SetLayer( ChangeSideNumLayer( em->GetLayer() ) ); + em->SetLayer( BOARD::ReturnFlippedLayerNumber( em->GetLayer() ) ); } break; @@ -251,7 +254,7 @@ void MODULE::Flip( const wxPoint& aCentre ) NEGATE_AND_NORMALIZE_ANGLE_POS( pt_texte->m_Orient ); pt_texte->SetLayer( GetLayer() ); - pt_texte->SetLayer( ChangeSideNumLayer( pt_texte->GetLayer() ) ); + pt_texte->SetLayer( BOARD::ReturnFlippedLayerNumber( pt_texte->GetLayer() ) ); if( GetLayer() == LAYER_N_BACK ) pt_texte->SetLayer( SILKSCREEN_N_BACK ); diff --git a/pcbnew/class_pcb_text.cpp b/pcbnew/class_pcb_text.cpp index ccda388b71..bc9d559fc3 100644 --- a/pcbnew/class_pcb_text.cpp +++ b/pcbnew/class_pcb_text.cpp @@ -165,7 +165,7 @@ void TEXTE_PCB::Flip(const wxPoint& aCentre ) { m_Mirror = not m_Mirror; /* inverse mirror */ } - SetLayer( ChangeSideNumLayer( GetLayer() ) ); + SetLayer( BOARD::ReturnFlippedLayerNumber( GetLayer() ) ); } diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 218f6ecd49..dbe2e80ee7 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -392,7 +392,7 @@ void TRACK::Flip( const wxPoint& aCentre ) } else { - SetLayer( ChangeSideNumLayer( GetLayer() ) ); + SetLayer( BOARD::ReturnFlippedLayerNumber( GetLayer() ) ); } } diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index f893b21bb5..4355257d88 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -824,7 +824,7 @@ void ZONE_CONTAINER::Rotate( const wxPoint& centre, double angle ) void ZONE_CONTAINER::Flip( const wxPoint& aCentre ) { Mirror( aCentre ); - SetLayer( ChangeSideNumLayer( GetLayer() ) ); + SetLayer( BOARD::ReturnFlippedLayerNumber( GetLayer() ) ); } @@ -876,7 +876,8 @@ void ZONE_CONTAINER::Copy( ZONE_CONTAINER* src ) m_PadConnection = src->m_PadConnection; m_ThermalReliefGap = src->m_ThermalReliefGap; m_ThermalReliefCopperBridge = src->m_ThermalReliefCopperBridge; - m_Poly->m_HatchStyle = src->m_Poly->GetHatchStyle(); + m_Poly->SetHatchStyle( src->m_Poly->GetHatchStyle() ); + m_Poly->SetHatchPitch( src->m_Poly->GetHatchPitch() ); m_Poly->m_HatchLines = src->m_Poly->m_HatchLines; // Copy vector m_FilledPolysList.clear(); m_FilledPolysList = src->m_FilledPolysList; diff --git a/pcbnew/class_zone_settings.cpp b/pcbnew/class_zone_settings.cpp index aadefdc5d6..845f8b4b50 100644 --- a/pcbnew/class_zone_settings.cpp +++ b/pcbnew/class_zone_settings.cpp @@ -73,7 +73,7 @@ void ZONE_SETTINGS::ExportSetting( ZONE_CONTAINER& aTarget, bool aFullExport ) c aTarget.m_FillMode = m_FillMode; aTarget.m_ZoneClearance = m_ZoneClearance; aTarget.m_ZoneMinThickness = m_ZoneMinThickness; - aTarget.m_Poly->SetHatch( m_Zone_HatchingStyle ); + aTarget.m_Poly->SetHatch( m_Zone_HatchingStyle, Mils2iu( 20 ) ); aTarget.m_ArcToSegmentsCount = m_ArcToSegmentsCount; aTarget.m_ThermalReliefGap = m_ThermalReliefGap; aTarget.m_ThermalReliefCopperBridge = m_ThermalReliefCopperBridge; diff --git a/pcbnew/item_io.cpp b/pcbnew/item_io.cpp index a3121514be..d145a2e213 100644 --- a/pcbnew/item_io.cpp +++ b/pcbnew/item_io.cpp @@ -1980,7 +1980,7 @@ int ZONE_CONTAINER::ReadDescr( LINE_READER* aReader ) } // Set hatch here, when outlines corners are read - m_Poly->SetHatch( outline_hatch ); + m_Poly->SetHatch( outline_hatch, Mils2iu( m_Poly->GetDefaultHatchPitchMils() ) ); return error ? 0 : 1; } diff --git a/pcbnew/legacy_plugin.cpp b/pcbnew/legacy_plugin.cpp index 896887a3b0..8f5626634c 100644 --- a/pcbnew/legacy_plugin.cpp +++ b/pcbnew/legacy_plugin.cpp @@ -3,7 +3,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2007-2011 SoftPLC Corporation, Dick Hollenbeck - * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com + * Copyright (C) 2004 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.fr * Copyright (C) 1992-2011 KiCad Developers, see change_log.txt for contributors. * @@ -82,7 +82,7 @@ #include <3d_struct.h> #include #include - +#include #include #include @@ -2286,7 +2286,8 @@ void LEGACY_PLUGIN::loadZONE_CONTAINER() } // Set hatch here, after outlines corners are read - zc->m_Poly->SetHatch( outline_hatch ); + zc->m_Poly->SetHatch( outline_hatch, + Mils2iu( zc->m_Poly->GetDefaultHatchPitchMils() ) ); m_board->Add( zc.release() ); } diff --git a/pcbnew/modules.cpp b/pcbnew/modules.cpp index b36315324a..379189e01a 100644 --- a/pcbnew/modules.cpp +++ b/pcbnew/modules.cpp @@ -44,6 +44,8 @@ #include +static void MoveFootprint( EDA_DRAW_PANEL* aPanel, wxDC* aDC, + const wxPoint& aPosition, bool aErase ); static void Abort_MoveOrCopyModule( EDA_DRAW_PANEL* Panel, wxDC* DC ); diff --git a/pcbnew/pcbnew.h b/pcbnew/pcbnew.h index e013189886..9759ee4b4c 100644 --- a/pcbnew/pcbnew.h +++ b/pcbnew/pcbnew.h @@ -8,7 +8,7 @@ #include // PCB_INTERNAL_UNIT and EESCHEMA_INTERNAL_UNIT definitions. #include // IS_DRAGGED and IN_EDIT definitions. - +#include // to define DMils2iu() conversion function #define U_PCB (PCB_INTERNAL_UNIT / EESCHEMA_INTERNAL_UNIT) @@ -34,19 +34,6 @@ #define DIM_ANCRE_TEXTE 2 /* Anchor size (Text center) */ -#if defined(PCBNEW) -/// Convert deci-mils to PCBNEW internal units (iu). -inline int DMils2iu( int dmils ) -{ -#if defined( USE_PCBNEW_NANOMETRES ) - return int( dmils * 25.4e2 + 0.5 ); -#else - return dmils; -#endif -} -#endif - - #define TEXTS_MIN_SIZE DMils2iu( 50 ) ///< Minimum text size in Pcbnew units value (50 * 0.0001 mils) #define TEXTS_MAX_SIZE DMils2iu( 10000 ) ///< Maximum text size in Pcbnew units value (1 inch) ) #define TEXTS_MAX_WIDTH DMils2iu( 5000 ) ///< Maximum text width in Pcbnew units value (0.5 inches) diff --git a/pcbnew/protos.h b/pcbnew/protos.h index 2e1a0948ac..611f26cdba 100644 --- a/pcbnew/protos.h +++ b/pcbnew/protos.h @@ -6,18 +6,13 @@ #define PROTO_H -#include - - class wxDC; class wxPoint; class EDA_DRAW_PANEL; class BOARD_ITEM; -class D_PAD; class TRACK; class MODULE; - /** * Function SwapData * Used in undo / redo command: @@ -63,15 +58,7 @@ void DrawTraces( EDA_DRAW_PANEL* panel, */ int ChangeSideMaskLayer( int aMask ); -/** - * Function ChangeSideNumLayer - * calculates the layer number for changing cu / cmp layers for Cu / CMP. - * (Copper, Mask, Paste, solder) - */ -int ChangeSideNumLayer( int oldlayer ); - void DrawModuleOutlines( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* module ); -void MoveFootprint( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ); /****************/ diff --git a/pcbnew/zone_filling_algorithm.cpp b/pcbnew/zone_filling_algorithm.cpp index 921974db12..38e626c46c 100644 --- a/pcbnew/zone_filling_algorithm.cpp +++ b/pcbnew/zone_filling_algorithm.cpp @@ -14,7 +14,6 @@ #include #include -#include /* Local functions */ diff --git a/polygon/PolyLine.cpp b/polygon/PolyLine.cpp index 2d5cbdaaf9..7efda63ff0 100644 --- a/polygon/PolyLine.cpp +++ b/polygon/PolyLine.cpp @@ -8,18 +8,11 @@ #include #include -#include // to define KICAD_NANOMETRE #include #include #include -#if defined(KICAD_NANOMETRE) -#define PCBU_PER_MIL (1000.0*25.4) -#else -#define PCBU_PER_MIL 10 -#endif - #define to_int( x ) wxRound( (x) ) @@ -34,7 +27,8 @@ CPolyLine::CPolyLine() { - m_HatchStyle = 0; + m_hatchStyle = NO_HATCH; + m_hatchPitch = 0; m_Width = 0; utility = 0; m_Kbool_Poly_Engine = NULL; @@ -794,7 +788,7 @@ int CPolyLine::RestoreArcs( std::vector * arc_array, std::vector pointbuffer; @@ -1514,7 +1508,7 @@ void CPolyLine::Hatch() // Push only one line for diagonal hatch, // or for small lines < twice the line len // else push 2 small lines - if( m_HatchStyle == DIAGONAL_FULL || fabs( dx ) < 2 * hatch_line_len ) + if( m_hatchStyle == DIAGONAL_FULL || fabs( dx ) < 2 * hatch_line_len ) { m_HatchLines.push_back( CSegment( pointbuffer[ip].x, pointbuffer[ip].y, @@ -1583,7 +1577,8 @@ bool CPolyLine::TestPointInside( int px, int py ) void CPolyLine::Copy( CPolyLine* src ) { UnHatch(); - m_HatchStyle = src->m_HatchStyle; + m_hatchStyle = src->m_hatchStyle; + m_hatchPitch = src->m_hatchPitch; // copy corners, using vector copy corner = src->corner; // copy side styles, using vector copy diff --git a/polygon/PolyLine.h b/polygon/PolyLine.h index 827ff0ae85..fc44f87755 100644 --- a/polygon/PolyLine.h +++ b/polygon/PolyLine.h @@ -108,8 +108,8 @@ public: class CPolyLine { public: - enum { STRAIGHT, ARC_CW, ARC_CCW }; // side styles - enum { NO_HATCH, DIAGONAL_FULL, DIAGONAL_EDGE }; // hatch styles + enum side_style { STRAIGHT, ARC_CW, ARC_CCW }; // side styles + enum hatch_style { NO_HATCH, DIAGONAL_FULL, DIAGONAL_EDGE }; // hatch styles // constructors/destructor CPolyLine(); @@ -180,13 +180,25 @@ public: int GetUtility( int ic ) { return corner[ic].utility; }; void SetUtility( int ic, int utility ) { corner[ic].utility = utility; }; int GetSideStyle( int is ); + int GetHatchPitch() { return m_hatchPitch; } + int GetDefaultHatchPitchMils() { return 20; } // default hatch pitch value in mils - int GetHatchStyle() { return m_HatchStyle; } - void SetHatch( int hatch ) { m_HatchStyle = hatch; Hatch(); }; + enum hatch_style GetHatchStyle() { return m_hatchStyle; } + void SetHatch( int hatch, int pitch ) + { + SetHatchPitch( pitch ); + m_hatchStyle = (enum hatch_style ) hatch; + Hatch(); + } void SetX( int ic, int x ); void SetY( int ic, int y ); void SetEndContour( int ic, bool end_contour ); void SetSideStyle( int is, int style ); + void SetHatchStyle( enum hatch_style style ) + { + m_hatchStyle = style; + } + void SetHatchPitch( int pitch ) { m_hatchPitch = pitch; } int RestoreArcs( std::vector * arc_array, std::vector * pa = NULL ); @@ -260,15 +272,18 @@ public: private: - int m_layer; // layer to draw on - int m_Width; // lines width when drawing. Provided but not really used + int m_layer; // layer to draw on + int m_Width; // lines width when drawing. Provided but not really used + enum hatch_style m_hatchStyle; // hatch style, see enum above + int m_hatchPitch; // for DIAGONAL_EDGE hatched outlines, basic distance between 2 hatch lines + // and the len of eacvh segment + // for DIAGONAL_FULL, the pitch is twice this value int utility; Bool_Engine* m_Kbool_Poly_Engine; // polygons set in kbool engine data public: std::vector corner; // array of points for corners std::vector side_style; // array of styles for sides - int m_HatchStyle; // hatch style, see enum above std::vector m_HatchLines; // hatch lines };