You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

992 lines
27 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
12 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
14 years ago
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
++PCBNew * Removed Pcb_Frame argument from BOARD() constructor, since it precludes having a BOARD being edited by more than one editor, it was a bad design. And this meant removing m_PcbFrame from BOARD. * removed BOARD::SetWindowFrame(), and BOARD::m_PcbFrame * Removed the global BOARD_DESIGN_SETTINGS which was in class_board.cpp * added BOARD_DESIGN_SETTINGS to the BOARD class, a full instance * a couple dialogs now only change BOARD_DESIGN_SETTINGS when OK is pressed, such as dialog_mask_clearance, dialog_drc, etc. * Removed common/pcbcommon.cpp's int g_CurrentVersionPCB = 1 and replaced it with build_version.h's #define BOARD_FILE_VERSION, although there may be a better place for this constant. * Made the public functions in PARAM_CFG_ARRAY be type const. void SaveParam(..) const and void ReadParam(..) const * PARAM_CFG_BASE now has virtual destructor since we have various way of destroying the derived class and boost::ptr_vector must be told about this. * Pass const PARAM_CFG_ARRAY& instead of PARAM_CFG_ARRAY so that we can use an automatic PARAM_CFG_ARRAY which is on the stack.\ * PCB_EDIT_FRAME::GetProjectFileParameters() may no longer cache the array, since it has to access the current BOARD and the BOARD can change. Remember BOARD_DESIGN_SETTINGS are now in the BOARD. * Made the m_BoundingBox member private, this was a brutally hard task, and indicative of the lack of commitment to accessors and object oriented design on the part of KiCad developers. We must do better. Added BOARD::GetBoundingBox, SetBoundingBox(), ComputeBoundingBox(). * Added PCB_BASE_FRAME::GetBoardBoundingBox() which calls BOARD::ComputeBoundingBox()
14 years ago
// Dick Hollenbeck's KiROUND R&D // This provides better project control over rounding to int from double // than wxRound() did. This scheme provides better logging in Debug builds // and it provides for compile time calculation of constants. #include <stdio.h> #include <assert.h> #include <limits.h> //-----<KiROUND KIT>------------------------------------------------------------ /** * KiROUND * rounds a floating point number to an int using * "round halfway cases away from zero". * In Debug build an assert fires if will not fit into an int. */ #if defined( DEBUG ) // DEBUG: a macro to capture line and file, then calls this inline static inline int KiRound( double v, int line, const char* filename ) { v = v < 0 ? v - 0.5 : v + 0.5; if( v > INT_MAX + 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' > 0 ' for int\n", __FUNCTION__, filename, line, v ); } else if( v < INT_MIN - 0.5 ) { printf( "%s: in file %s on line %d, val: %.16g too ' < 0 ' for int\n", __FUNCTION__, filename, line, v ); } return int( v ); } #define KiROUND( v ) KiRound( v, __LINE__, __FILE__ ) #else // RELEASE: a macro so compile can pre-compute constants. #define KiROUND( v ) int( (v) < 0 ? (v) - 0.5 : (v) + 0.5 ) #endif //-----</KiROUND KIT>----------------------------------------------------------- // Only a macro is compile time calculated, an inline function causes a static constructor // in a situation like this. // Therefore the Release build is best done with a MACRO not an inline function. int Computed = KiROUND( 14.3 * 8 ); int main( int argc, char** argv ) { for( double d = double(INT_MAX)-1; d < double(INT_MAX)+8; d += 2.0 ) { int i = KiROUND( d ); printf( "t: %d %.16g\n", i, d ); } return 0; }
14 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
14 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
14 years ago
18 years ago
18 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
Introduction of Graphics Abstraction Layer based rendering for pcbnew. New classes: - VIEW - represents view that is seen by user, takes care of layer ordering & visibility and how it is displayed (which location, how much zoomed, etc.) - VIEW_ITEM - Base class for every item that can be displayed on VIEW (the biggest change is that now it may be necessary to override ViewBBox & ViewGetLayers method for derived classes). - EDA_DRAW_PANEL_GAL - Inherits after EDA_DRAW_PANEL, displays VIEW output, right now it is not editable (in opposite to usual EDA_DRAW_PANEL). - GAL/OPENGL_GAL/CAIRO_GAL - Base Graphics Abstraction Layer class + two different flavours (Cairo is not fully supported yet), that offers methods to draw primitives using different libraries. - WX_VIEW_CONTROLS - Controller for VIEW, handles user events, allows zooming, panning, etc. - PAINTER/PCB_PAINTER - Classes that uses GAL interface to draw items (as you may have already guessed - PCB_PAINTER is a class for drawing PCB specific object, PAINTER is an abstract class). Its methods are invoked by VIEW, when an item has to be drawn. To display a new type of item - you need to implement draw(ITEM_TYPE*) method that draws it using GAL methods. - STROKE_FONT - Implements stroke font drawing using GAL methods. Most important changes to Kicad original code: * EDA_ITEM now inherits from VIEW_ITEM, which is a base class for all drawable objects. * EDA_DRAW_FRAME contains both usual EDA_DRAW_PANEL and new EDA_DRAW_PANEL_GAL, that can be switched anytime. * There are some new layers for displaying multilayer pads, vias & pads holes (these are not shown yet on the right sidebar in pcbnew) * Display order of layers is different than in previous versions (if you are curious - you may check m_galLayerOrder@pcbnew/basepcbframe.cpp). Preserving usual order would result in not very natural display, such as showing silkscreen texts on the bottom. * Introduced new hotkey (Alt+F12) and new menu option (View->Switch canvas) for switching canvas during runtime. * Some of classes (mostly derived from BOARD_ITEM) now includes ViewBBox & ViewGetLayers methods. * Removed tools/class_painter.h, as now it is extended and included in source code. Build changes: * GAL-based rendering option is turned on by a new compilation CMake option KICAD_GAL. * When compiling with CMake option KICAD_GAL=ON, GLEW and Cairo libraries are required. * GAL-related code is compiled into a static library (common/libgal). * Build with KICAD_GAL=OFF should not need any new libraries and should come out as a standard version of Kicad Currently most of items in pcbnew can be displayed using OpenGL (to be done are DIMENSIONS and MARKERS). More details about GAL can be found in: http://www.ohwr.org/attachments/1884/view-spec.pdf
13 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 Jean-Pierre Charras, jean-pierre.charras@ujf-grenoble.fr
  5. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file class_pad.cpp
  27. * D_PAD class implementation.
  28. */
  29. #include <fctsys.h>
  30. #include <PolyLine.h>
  31. #include <common.h>
  32. #include <confirm.h>
  33. #include <kicad_string.h>
  34. #include <trigo.h>
  35. #include <richio.h>
  36. #include <wxstruct.h>
  37. #include <macros.h>
  38. #include <msgpanel.h>
  39. #include <base_units.h>
  40. #include <pcbnew.h>
  41. #include <pcbnew_id.h> // ID_TRACK_BUTT
  42. #include <class_board.h>
  43. #include <class_module.h>
  44. #include <polygon_test_point_inside.h>
  45. #include <convert_from_iu.h>
  46. #include <boost/foreach.hpp>
  47. int D_PAD::m_PadSketchModePenSize = 0; // Pen size used to draw pads in sketch mode
  48. D_PAD::D_PAD( MODULE* parent ) :
  49. BOARD_CONNECTED_ITEM( parent, PCB_PAD_T )
  50. {
  51. m_NumPadName = 0;
  52. m_Size.x = m_Size.y = DMils2iu( 600 ); // Default pad size 60 mils.
  53. m_Drill.x = m_Drill.y = DMils2iu( 300 ); // Default drill size 30 mils.
  54. m_Orient = 0; // Pad rotation in 1/10 degrees.
  55. m_LengthPadToDie = 0;
  56. if( m_Parent && m_Parent->Type() == PCB_MODULE_T )
  57. {
  58. m_Pos = GetParent()->GetPosition();
  59. }
  60. SetShape( PAD_SHAPE_CIRCLE ); // Default pad shape is PAD_CIRCLE.
  61. SetDrillShape( PAD_DRILL_SHAPE_CIRCLE ); // Default pad drill shape is a circle.
  62. m_Attribute = PAD_ATTRIB_STANDARD; // Default pad type is NORMAL (thru hole)
  63. m_LocalClearance = 0;
  64. m_LocalSolderMaskMargin = 0;
  65. m_LocalSolderPasteMargin = 0;
  66. m_LocalSolderPasteMarginRatio = 0.0;
  67. m_ZoneConnection = PAD_ZONE_CONN_INHERITED; // Use parent setting by default
  68. m_ThermalWidth = 0; // Use parent setting by default
  69. m_ThermalGap = 0; // Use parent setting by default
  70. // Set layers mask to default for a standard thru hole pad.
  71. m_layerMask = StandardMask();
  72. SetSubRatsnest( 0 ); // used in ratsnest calculations
  73. m_boundingRadius = -1;
  74. }
  75. LSET D_PAD::StandardMask()
  76. {
  77. static LSET saved = LSET::AllCuMask() | LSET( 3, F_SilkS, B_Mask, F_Mask );
  78. return saved;
  79. }
  80. LSET D_PAD::SMDMask()
  81. {
  82. static LSET saved( 3, F_Cu, F_Paste, F_Mask );
  83. return saved;
  84. }
  85. LSET D_PAD::ConnSMDMask()
  86. {
  87. static LSET saved( 2, F_Cu, F_Mask );
  88. return saved;
  89. }
  90. LSET D_PAD::UnplatedHoleMask()
  91. {
  92. static LSET saved = LSET::AllCuMask() | LSET( 3, F_SilkS, B_Mask, F_Mask );
  93. return saved;
  94. }
  95. int D_PAD::boundingRadius() const
  96. {
  97. int x, y;
  98. int radius;
  99. switch( GetShape() )
  100. {
  101. case PAD_SHAPE_CIRCLE:
  102. radius = m_Size.x / 2;
  103. break;
  104. case PAD_SHAPE_OVAL:
  105. radius = std::max( m_Size.x, m_Size.y ) / 2;
  106. break;
  107. case PAD_SHAPE_RECT:
  108. radius = 1 + KiROUND( EuclideanNorm( m_Size ) / 2 );
  109. break;
  110. case PAD_SHAPE_TRAPEZOID:
  111. x = m_Size.x + std::abs( m_DeltaSize.y ); // Remember: m_DeltaSize.y is the m_Size.x change
  112. y = m_Size.y + std::abs( m_DeltaSize.x ); // Remember: m_DeltaSize.x is the m_Size.y change
  113. radius = 1 + KiROUND( hypot( x, y ) / 2 );
  114. break;
  115. default:
  116. radius = 0;
  117. }
  118. return radius;
  119. }
  120. const EDA_RECT D_PAD::GetBoundingBox() const
  121. {
  122. EDA_RECT area;
  123. wxPoint quadrant1, quadrant2, quadrant3, quadrant4;
  124. int x, y, dx, dy;
  125. switch( GetShape() )
  126. {
  127. case PAD_SHAPE_CIRCLE:
  128. area.SetOrigin( m_Pos );
  129. area.Inflate( m_Size.x / 2 );
  130. break;
  131. case PAD_SHAPE_OVAL:
  132. //Use the maximal two most distant points and track their rotation
  133. // (utilise symmetry to avoid four points)
  134. quadrant1.x = m_Size.x/2;
  135. quadrant1.y = 0;
  136. quadrant2.x = 0;
  137. quadrant2.y = m_Size.y/2;
  138. RotatePoint( &quadrant1, m_Orient );
  139. RotatePoint( &quadrant2, m_Orient );
  140. dx = std::max( std::abs( quadrant1.x ) , std::abs( quadrant2.x ) );
  141. dy = std::max( std::abs( quadrant1.y ) , std::abs( quadrant2.y ) );
  142. area.SetOrigin( m_Pos.x-dx, m_Pos.y-dy );
  143. area.SetSize( 2*dx, 2*dy );
  144. break;
  145. case PAD_SHAPE_RECT:
  146. //Use two corners and track their rotation
  147. // (utilise symmetry to avoid four points)
  148. quadrant1.x = m_Size.x/2;
  149. quadrant1.y = m_Size.y/2;
  150. quadrant2.x = -m_Size.x/2;
  151. quadrant2.y = m_Size.y/2;
  152. RotatePoint( &quadrant1, m_Orient );
  153. RotatePoint( &quadrant2, m_Orient );
  154. dx = std::max( std::abs( quadrant1.x ) , std::abs( quadrant2.x ) );
  155. dy = std::max( std::abs( quadrant1.y ) , std::abs( quadrant2.y ) );
  156. area.SetOrigin( m_Pos.x-dx, m_Pos.y-dy );
  157. area.SetSize( 2*dx, 2*dy );
  158. break;
  159. case PAD_SHAPE_TRAPEZOID:
  160. //Use the four corners and track their rotation
  161. // (Trapezoids will not be symmetric)
  162. quadrant1.x = (m_Size.x + m_DeltaSize.y)/2;
  163. quadrant1.y = (m_Size.y - m_DeltaSize.x)/2;
  164. quadrant2.x = -(m_Size.x + m_DeltaSize.y)/2;
  165. quadrant2.y = (m_Size.y + m_DeltaSize.x)/2;
  166. quadrant3.x = -(m_Size.x - m_DeltaSize.y)/2;
  167. quadrant3.y = -(m_Size.y + m_DeltaSize.x)/2;
  168. quadrant4.x = (m_Size.x - m_DeltaSize.y)/2;
  169. quadrant4.y = -(m_Size.y - m_DeltaSize.x)/2;
  170. RotatePoint( &quadrant1, m_Orient );
  171. RotatePoint( &quadrant2, m_Orient );
  172. RotatePoint( &quadrant3, m_Orient );
  173. RotatePoint( &quadrant4, m_Orient );
  174. x = std::min( quadrant1.x, std::min( quadrant2.x, std::min( quadrant3.x, quadrant4.x) ) );
  175. y = std::min( quadrant1.y, std::min( quadrant2.y, std::min( quadrant3.y, quadrant4.y) ) );
  176. dx = std::max( quadrant1.x, std::max( quadrant2.x, std::max( quadrant3.x, quadrant4.x) ) );
  177. dy = std::max( quadrant1.y, std::max( quadrant2.y, std::max( quadrant3.y, quadrant4.y) ) );
  178. area.SetOrigin( m_Pos.x+x, m_Pos.y+y );
  179. area.SetSize( dx-x, dy-y );
  180. break;
  181. default:
  182. break;
  183. }
  184. return area;
  185. }
  186. void D_PAD::SetDrawCoord()
  187. {
  188. MODULE* module = (MODULE*) m_Parent;
  189. m_Pos = m_Pos0;
  190. if( module == NULL )
  191. return;
  192. double angle = module->GetOrientation();
  193. RotatePoint( &m_Pos.x, &m_Pos.y, angle );
  194. m_Pos += module->GetPosition();
  195. }
  196. void D_PAD::SetLocalCoord()
  197. {
  198. MODULE* module = (MODULE*) m_Parent;
  199. if( module == NULL )
  200. {
  201. m_Pos0 = m_Pos;
  202. return;
  203. }
  204. m_Pos0 = m_Pos - module->GetPosition();
  205. RotatePoint( &m_Pos0.x, &m_Pos0.y, -module->GetOrientation() );
  206. }
  207. void D_PAD::SetAttribute( PAD_ATTR_T aAttribute )
  208. {
  209. m_Attribute = aAttribute;
  210. if( aAttribute == PAD_ATTRIB_SMD )
  211. m_Drill = wxSize( 0, 0 );
  212. }
  213. void D_PAD::SetOrientation( double aAngle )
  214. {
  215. NORMALIZE_ANGLE_POS( aAngle );
  216. m_Orient = aAngle;
  217. }
  218. void D_PAD::Flip( const wxPoint& aCentre )
  219. {
  220. int y = GetPosition().y - aCentre.y;
  221. y = -y; // invert about x axis.
  222. y += aCentre.y;
  223. SetY( y );
  224. m_Pos0.y = -m_Pos0.y;
  225. m_Offset.y = -m_Offset.y;
  226. m_DeltaSize.y = -m_DeltaSize.y;
  227. SetOrientation( -GetOrientation() );
  228. // flip pads layers
  229. // PADS items are currently on all copper layers, or
  230. // currently, only on Front or Back layers.
  231. // So the copper layers count is not taken in account
  232. SetLayerSet( FlipLayerMask( m_layerMask ) );
  233. // m_boundingRadius = -1; the shape has not been changed
  234. }
  235. void D_PAD::AppendConfigs( PARAM_CFG_ARRAY* aResult )
  236. {
  237. // Parameters stored in config are only significant parameters
  238. // for a template.
  239. // So not all parameters are stored, just few.
  240. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadDrill" ),
  241. &m_Drill.x,
  242. Millimeter2iu( 0.6 ),
  243. Millimeter2iu( 0.1 ), Millimeter2iu( 10.0 ),
  244. NULL, MM_PER_IU ) );
  245. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadDrillOvalY" ),
  246. &m_Drill.y,
  247. Millimeter2iu( 0.6 ),
  248. Millimeter2iu( 0.1 ), Millimeter2iu( 10.0 ),
  249. NULL, MM_PER_IU ) );
  250. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadSizeH" ),
  251. &m_Size.x,
  252. Millimeter2iu( 1.4 ),
  253. Millimeter2iu( 0.1 ), Millimeter2iu( 20.0 ),
  254. NULL, MM_PER_IU ) );
  255. aResult->push_back( new PARAM_CFG_INT_WITH_SCALE( wxT( "PadSizeV" ),
  256. &m_Size.y,
  257. Millimeter2iu( 1.4 ),
  258. Millimeter2iu( 0.1 ), Millimeter2iu( 20.0 ),
  259. NULL, MM_PER_IU ) );
  260. }
  261. // Returns the position of the pad.
  262. const wxPoint D_PAD::ShapePos() const
  263. {
  264. if( m_Offset.x == 0 && m_Offset.y == 0 )
  265. return m_Pos;
  266. wxPoint loc_offset = m_Offset;
  267. RotatePoint( &loc_offset, m_Orient );
  268. wxPoint shape_pos = m_Pos + loc_offset;
  269. return shape_pos;
  270. }
  271. const wxString D_PAD::GetPadName() const
  272. {
  273. wxString name;
  274. StringPadName( name );
  275. return name;
  276. }
  277. void D_PAD::StringPadName( wxString& text ) const
  278. {
  279. text.Empty();
  280. for( int ii = 0; ii < PADNAMEZ && m_Padname[ii]; ii++ )
  281. {
  282. // m_Padname is 8 bit KiCad font junk, do not sign extend
  283. text.Append( (unsigned char) m_Padname[ii] );
  284. }
  285. }
  286. // Change pad name
  287. void D_PAD::SetPadName( const wxString& name )
  288. {
  289. int ii, len;
  290. len = name.Length();
  291. if( len > PADNAMEZ )
  292. len = PADNAMEZ;
  293. // m_Padname[] is not UTF8, it is an 8 bit character that matches the KiCad font,
  294. // so only copy the lower 8 bits of each character.
  295. for( ii = 0; ii < len; ii++ )
  296. m_Padname[ii] = (char) name.GetChar( ii );
  297. for( ii = len; ii < PADNAMEZ; ii++ )
  298. m_Padname[ii] = '\0';
  299. }
  300. bool D_PAD::IncrementItemReference()
  301. {
  302. // Take the next available pad number
  303. return IncrementPadName( true, true );
  304. }
  305. bool D_PAD::IncrementPadName( bool aSkipUnconnectable, bool aFillSequenceGaps )
  306. {
  307. bool skip = aSkipUnconnectable && ( GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED );
  308. if( !skip )
  309. SetPadName( GetParent()->GetNextPadName( aFillSequenceGaps ) );
  310. return !skip;
  311. }
  312. void D_PAD::Copy( D_PAD* source )
  313. {
  314. if( source == NULL )
  315. return;
  316. m_Pos = source->m_Pos;
  317. m_layerMask = source->m_layerMask;
  318. m_NumPadName = source->m_NumPadName;
  319. m_netinfo = source->m_netinfo;
  320. m_Drill = source->m_Drill;
  321. m_drillShape = source->m_drillShape;
  322. m_Offset = source->m_Offset;
  323. m_Size = source->m_Size;
  324. m_DeltaSize = source->m_DeltaSize;
  325. m_Pos0 = source->m_Pos0;
  326. m_boundingRadius = source->m_boundingRadius;
  327. m_padShape = source->m_padShape;
  328. m_Attribute = source->m_Attribute;
  329. m_Orient = source->m_Orient;
  330. m_LengthPadToDie = source->m_LengthPadToDie;
  331. m_LocalClearance = source->m_LocalClearance;
  332. m_LocalSolderMaskMargin = source->m_LocalSolderMaskMargin;
  333. m_LocalSolderPasteMargin = source->m_LocalSolderPasteMargin;
  334. m_LocalSolderPasteMarginRatio = source->m_LocalSolderPasteMarginRatio;
  335. m_ZoneConnection = source->m_ZoneConnection;
  336. m_ThermalWidth = source->m_ThermalWidth;
  337. m_ThermalGap = source->m_ThermalGap;
  338. SetSubRatsnest( 0 );
  339. SetSubNet( 0 );
  340. }
  341. void D_PAD::CopyNetlistSettings( D_PAD* aPad, bool aCopyLocalSettings )
  342. {
  343. // Don't do anything foolish like trying to copy to yourself.
  344. wxCHECK_RET( aPad != NULL && aPad != this, wxT( "Cannot copy to NULL or yourself." ) );
  345. aPad->SetNetCode( GetNetCode() );
  346. if( aCopyLocalSettings )
  347. {
  348. aPad->SetLocalClearance( m_LocalClearance );
  349. aPad->SetLocalSolderMaskMargin( m_LocalSolderMaskMargin );
  350. aPad->SetLocalSolderPasteMargin( m_LocalSolderPasteMargin );
  351. aPad->SetLocalSolderPasteMarginRatio( m_LocalSolderPasteMarginRatio );
  352. aPad->SetZoneConnection( m_ZoneConnection );
  353. aPad->SetThermalWidth( m_ThermalWidth );
  354. aPad->SetThermalGap( m_ThermalGap );
  355. }
  356. }
  357. int D_PAD::GetClearance( BOARD_CONNECTED_ITEM* aItem ) const
  358. {
  359. // A pad can have specific clearance parameters that
  360. // overrides its NETCLASS clearance value
  361. int clearance = m_LocalClearance;
  362. if( clearance == 0 )
  363. {
  364. // If local clearance is 0, use the parent footprint clearance value
  365. if( GetParent() && GetParent()->GetLocalClearance() )
  366. clearance = GetParent()->GetLocalClearance();
  367. }
  368. if( clearance == 0 ) // If the parent footprint clearance value = 0, use NETCLASS value
  369. return BOARD_CONNECTED_ITEM::GetClearance( aItem );
  370. // We have a specific clearance.
  371. // if aItem, return the biggest clearance
  372. if( aItem )
  373. {
  374. int hisClearance = aItem->GetClearance();
  375. return std::max( hisClearance, clearance );
  376. }
  377. // Return the specific clearance.
  378. return clearance;
  379. }
  380. // Mask margins handling:
  381. int D_PAD::GetSolderMaskMargin() const
  382. {
  383. int margin = m_LocalSolderMaskMargin;
  384. MODULE* module = GetParent();
  385. if( module )
  386. {
  387. if( margin == 0 )
  388. {
  389. if( module->GetLocalSolderMaskMargin() )
  390. margin = module->GetLocalSolderMaskMargin();
  391. }
  392. if( margin == 0 )
  393. {
  394. BOARD* brd = GetBoard();
  395. margin = brd->GetDesignSettings().m_SolderMaskMargin;
  396. }
  397. }
  398. // ensure mask have a size always >= 0
  399. if( margin < 0 )
  400. {
  401. int minsize = -std::min( m_Size.x, m_Size.y ) / 2;
  402. if( margin < minsize )
  403. margin = minsize;
  404. }
  405. return margin;
  406. }
  407. wxSize D_PAD::GetSolderPasteMargin() const
  408. {
  409. int margin = m_LocalSolderPasteMargin;
  410. double mratio = m_LocalSolderPasteMarginRatio;
  411. MODULE* module = GetParent();
  412. if( module )
  413. {
  414. if( margin == 0 )
  415. margin = module->GetLocalSolderPasteMargin();
  416. BOARD * brd = GetBoard();
  417. if( margin == 0 )
  418. margin = brd->GetDesignSettings().m_SolderPasteMargin;
  419. if( mratio == 0.0 )
  420. mratio = module->GetLocalSolderPasteMarginRatio();
  421. if( mratio == 0.0 )
  422. {
  423. mratio = brd->GetDesignSettings().m_SolderPasteMarginRatio;
  424. }
  425. }
  426. wxSize pad_margin;
  427. pad_margin.x = margin + KiROUND( m_Size.x * mratio );
  428. pad_margin.y = margin + KiROUND( m_Size.y * mratio );
  429. // ensure mask have a size always >= 0
  430. if( pad_margin.x < -m_Size.x / 2 )
  431. pad_margin.x = -m_Size.x / 2;
  432. if( pad_margin.y < -m_Size.y / 2 )
  433. pad_margin.y = -m_Size.y / 2;
  434. return pad_margin;
  435. }
  436. ZoneConnection D_PAD::GetZoneConnection() const
  437. {
  438. MODULE* module = GetParent();
  439. if( m_ZoneConnection == PAD_ZONE_CONN_INHERITED && module )
  440. return module->GetZoneConnection();
  441. else
  442. return m_ZoneConnection;
  443. }
  444. int D_PAD::GetThermalWidth() const
  445. {
  446. MODULE* module = GetParent();
  447. if( m_ThermalWidth == 0 && module )
  448. return module->GetThermalWidth();
  449. else
  450. return m_ThermalWidth;
  451. }
  452. int D_PAD::GetThermalGap() const
  453. {
  454. MODULE* module = GetParent();
  455. if( m_ThermalGap == 0 && module )
  456. return module->GetThermalGap();
  457. else
  458. return m_ThermalGap;
  459. }
  460. void D_PAD::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM>& aList )
  461. {
  462. MODULE* module;
  463. wxString Line;
  464. BOARD* board;
  465. module = (MODULE*) m_Parent;
  466. if( module )
  467. {
  468. wxString msg = module->GetReference();
  469. aList.push_back( MSG_PANEL_ITEM( _( "Footprint" ), msg, DARKCYAN ) );
  470. StringPadName( Line );
  471. aList.push_back( MSG_PANEL_ITEM( _( "Pad" ), Line, BROWN ) );
  472. }
  473. aList.push_back( MSG_PANEL_ITEM( _( "Net" ), GetNetname(), DARKCYAN ) );
  474. /* For test and debug only: display m_physical_connexion and
  475. * m_logical_connexion */
  476. #if 1 // Used only to debug connectivity calculations
  477. Line.Printf( wxT( "%d-%d-%d " ), GetSubRatsnest(), GetSubNet(), GetZoneSubNet() );
  478. aList.push_back( MSG_PANEL_ITEM( wxT( "L-P-Z" ), Line, DARKGREEN ) );
  479. #endif
  480. board = GetBoard();
  481. aList.push_back( MSG_PANEL_ITEM( _( "Layer" ),
  482. LayerMaskDescribe( board, m_layerMask ), DARKGREEN ) );
  483. aList.push_back( MSG_PANEL_ITEM( ShowPadShape(), ShowPadAttr(), DARKGREEN ) );
  484. Line = ::CoordinateToString( m_Size.x );
  485. aList.push_back( MSG_PANEL_ITEM( _( "Width" ), Line, RED ) );
  486. Line = ::CoordinateToString( m_Size.y );
  487. aList.push_back( MSG_PANEL_ITEM( _( "Height" ), Line, RED ) );
  488. Line = ::CoordinateToString( (unsigned) m_Drill.x );
  489. if( GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
  490. {
  491. aList.push_back( MSG_PANEL_ITEM( _( "Drill" ), Line, RED ) );
  492. }
  493. else
  494. {
  495. Line = ::CoordinateToString( (unsigned) m_Drill.x );
  496. wxString msg;
  497. msg = ::CoordinateToString( (unsigned) m_Drill.y );
  498. Line += wxT( "/" ) + msg;
  499. aList.push_back( MSG_PANEL_ITEM( _( "Drill X / Y" ), Line, RED ) );
  500. }
  501. double module_orient = module ? module->GetOrientation() : 0;
  502. if( module_orient )
  503. Line.Printf( wxT( "%3.1f(+%3.1f)" ),
  504. ( m_Orient - module_orient ) / 10.0,
  505. module_orient / 10.0 );
  506. else
  507. Line.Printf( wxT( "%3.1f" ), m_Orient / 10.0 );
  508. aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), Line, LIGHTBLUE ) );
  509. Line = ::CoordinateToString( m_Pos.x ) + wxT( ", " ) + ::CoordinateToString( m_Pos.y );
  510. aList.push_back( MSG_PANEL_ITEM( _( "Position" ), Line, LIGHTBLUE ) );
  511. if( GetPadToDieLength() )
  512. {
  513. Line = ::CoordinateToString( GetPadToDieLength() );
  514. aList.push_back( MSG_PANEL_ITEM( _( "Length in package" ), Line, CYAN ) );
  515. }
  516. }
  517. void D_PAD::GetOblongDrillGeometry( wxPoint& aStartPoint,
  518. wxPoint& aEndPoint, int& aWidth ) const
  519. {
  520. // calculates the start point, end point and width
  521. // of an equivalent segment which have the same position and width as the hole
  522. int delta_cx, delta_cy;
  523. wxSize halfsize = GetDrillSize();
  524. halfsize.x /= 2;
  525. halfsize.y /= 2;
  526. if( m_Drill.x > m_Drill.y ) // horizontal
  527. {
  528. delta_cx = halfsize.x - halfsize.y;
  529. delta_cy = 0;
  530. aWidth = m_Drill.y;
  531. }
  532. else // vertical
  533. {
  534. delta_cx = 0;
  535. delta_cy = halfsize.y - halfsize.x;
  536. aWidth = m_Drill.x;
  537. }
  538. RotatePoint( &delta_cx, &delta_cy, m_Orient );
  539. aStartPoint.x = delta_cx;
  540. aStartPoint.y = delta_cy;
  541. aEndPoint.x = - delta_cx;
  542. aEndPoint.y = - delta_cy;
  543. }
  544. bool D_PAD::HitTest( const wxPoint& aPosition ) const
  545. {
  546. int dx, dy;
  547. wxPoint shape_pos = ShapePos();
  548. wxPoint delta = aPosition - shape_pos;
  549. // first test: a test point must be inside a minimum sized bounding circle.
  550. int radius = GetBoundingRadius();
  551. if( ( abs( delta.x ) > radius ) || ( abs( delta.y ) > radius ) )
  552. return false;
  553. dx = m_Size.x >> 1; // dx also is the radius for rounded pads
  554. dy = m_Size.y >> 1;
  555. switch( GetShape() )
  556. {
  557. case PAD_SHAPE_CIRCLE:
  558. if( KiROUND( EuclideanNorm( delta ) ) <= dx )
  559. return true;
  560. break;
  561. case PAD_SHAPE_TRAPEZOID:
  562. {
  563. wxPoint poly[4];
  564. BuildPadPolygon( poly, wxSize(0,0), 0 );
  565. RotatePoint( &delta, -m_Orient );
  566. return TestPointInsidePolygon( poly, 4, delta );
  567. }
  568. case PAD_SHAPE_OVAL:
  569. {
  570. RotatePoint( &delta, -m_Orient );
  571. // An oval pad has the same shape as a segment with rounded ends
  572. // After rotation, the test point is relative to an horizontal pad
  573. int dist;
  574. wxPoint offset;
  575. if( dy > dx ) // shape is a vertical oval
  576. {
  577. offset.y = dy - dx;
  578. dist = dx;
  579. }
  580. else //if( dy <= dx ) shape is an horizontal oval
  581. {
  582. offset.x = dy - dx;
  583. dist = dy;
  584. }
  585. return TestSegmentHit( delta, - offset, offset, dist );
  586. }
  587. break;
  588. case PAD_SHAPE_RECT:
  589. RotatePoint( &delta, -m_Orient );
  590. if( (abs( delta.x ) <= dx ) && (abs( delta.y ) <= dy) )
  591. return true;
  592. break;
  593. }
  594. return false;
  595. }
  596. int D_PAD::Compare( const D_PAD* padref, const D_PAD* padcmp )
  597. {
  598. int diff;
  599. if( ( diff = padref->GetShape() - padcmp->GetShape() ) != 0 )
  600. return diff;
  601. if( ( diff = padref->GetDrillShape() - padcmp->GetDrillShape() ) != 0)
  602. return diff;
  603. if( ( diff = padref->m_Drill.x - padcmp->m_Drill.x ) != 0 )
  604. return diff;
  605. if( ( diff = padref->m_Drill.y - padcmp->m_Drill.y ) != 0 )
  606. return diff;
  607. if( ( diff = padref->m_Size.x - padcmp->m_Size.x ) != 0 )
  608. return diff;
  609. if( ( diff = padref->m_Size.y - padcmp->m_Size.y ) != 0 )
  610. return diff;
  611. if( ( diff = padref->m_Offset.x - padcmp->m_Offset.x ) != 0 )
  612. return diff;
  613. if( ( diff = padref->m_Offset.y - padcmp->m_Offset.y ) != 0 )
  614. return diff;
  615. if( ( diff = padref->m_DeltaSize.x - padcmp->m_DeltaSize.x ) != 0 )
  616. return diff;
  617. if( ( diff = padref->m_DeltaSize.y - padcmp->m_DeltaSize.y ) != 0 )
  618. return diff;
  619. // Dick: specctra_export needs this
  620. // Lorenzo: gencad also needs it to implement padstacks!
  621. #if __cplusplus >= 201103L
  622. long long d = padref->m_layerMask.to_ullong() - padcmp->m_layerMask.to_ullong();
  623. if( d < 0 )
  624. return -1;
  625. else if( d > 0 )
  626. return 1;
  627. return 0;
  628. #else
  629. // these strings are not typically constructed, since we don't get here often.
  630. std::string s1 = padref->m_layerMask.to_string();
  631. std::string s2 = padcmp->m_layerMask.to_string();
  632. return s1.compare( s2 );
  633. #endif
  634. }
  635. void D_PAD::Rotate( const wxPoint& aRotCentre, double aAngle )
  636. {
  637. RotatePoint( &m_Pos, aRotCentre, aAngle );
  638. m_Orient += aAngle;
  639. NORMALIZE_ANGLE_360( m_Orient );
  640. SetLocalCoord();
  641. }
  642. wxString D_PAD::ShowPadShape() const
  643. {
  644. switch( GetShape() )
  645. {
  646. case PAD_SHAPE_CIRCLE:
  647. return _( "Circle" );
  648. case PAD_SHAPE_OVAL:
  649. return _( "Oval" );
  650. case PAD_SHAPE_RECT:
  651. return _( "Rect" );
  652. case PAD_SHAPE_TRAPEZOID:
  653. return _( "Trap" );
  654. default:
  655. return wxT( "???" );
  656. }
  657. }
  658. wxString D_PAD::ShowPadAttr() const
  659. {
  660. switch( GetAttribute() )
  661. {
  662. case PAD_ATTRIB_STANDARD:
  663. return _( "Std" );
  664. case PAD_ATTRIB_SMD:
  665. return _( "SMD" );
  666. case PAD_ATTRIB_CONN:
  667. return _( "Conn" );
  668. case PAD_ATTRIB_HOLE_NOT_PLATED:
  669. return _( "Not Plated" );
  670. default:
  671. return wxT( "???" );
  672. }
  673. }
  674. wxString D_PAD::GetSelectMenuText() const
  675. {
  676. wxString text;
  677. wxString padlayers( LayerMaskDescribe( GetBoard(), m_layerMask ) );
  678. wxString padname( GetPadName() );
  679. if( padname.IsEmpty() )
  680. {
  681. text.Printf( _( "Pad on %s of %s" ),
  682. GetChars( padlayers ),
  683. GetChars(GetParent()->GetReference() ) );
  684. }
  685. else
  686. {
  687. text.Printf( _( "Pad %s on %s of %s" ),
  688. GetChars(GetPadName() ), GetChars( padlayers ),
  689. GetChars(GetParent()->GetReference() ) );
  690. }
  691. return text;
  692. }
  693. EDA_ITEM* D_PAD::Clone() const
  694. {
  695. return new D_PAD( *this );
  696. }
  697. void D_PAD::ViewGetLayers( int aLayers[], int& aCount ) const
  698. {
  699. aCount = 0;
  700. // These types of pads contain a hole
  701. if( m_Attribute == PAD_ATTRIB_STANDARD || m_Attribute == PAD_ATTRIB_HOLE_NOT_PLATED )
  702. aLayers[aCount++] = ITEM_GAL_LAYER( PADS_HOLES_VISIBLE );
  703. if( IsOnLayer( F_Cu ) && IsOnLayer( B_Cu ) )
  704. {
  705. // Multi layer pad
  706. aLayers[aCount++] = ITEM_GAL_LAYER( PADS_VISIBLE );
  707. aLayers[aCount++] = NETNAMES_GAL_LAYER( PADS_NETNAMES_VISIBLE );
  708. }
  709. else if( IsOnLayer( F_Cu ) )
  710. {
  711. aLayers[aCount++] = ITEM_GAL_LAYER( PAD_FR_VISIBLE );
  712. aLayers[aCount++] = NETNAMES_GAL_LAYER( PAD_FR_NETNAMES_VISIBLE );
  713. }
  714. else if( IsOnLayer( B_Cu ) )
  715. {
  716. aLayers[aCount++] = ITEM_GAL_LAYER( PAD_BK_VISIBLE );
  717. aLayers[aCount++] = NETNAMES_GAL_LAYER( PAD_BK_NETNAMES_VISIBLE );
  718. }
  719. // Check non-copper layers. This list should include all the layers that the
  720. // footprint editor allows a pad to be placed on.
  721. static const LAYER_ID layers_mech[] = { F_Mask, B_Mask, F_Paste, B_Paste,
  722. F_Adhes, B_Adhes, F_SilkS, B_SilkS, Dwgs_User, Eco1_User, Eco2_User };
  723. BOOST_FOREACH( LAYER_ID each_layer, layers_mech )
  724. {
  725. if( IsOnLayer( each_layer ) )
  726. aLayers[aCount++] = each_layer;
  727. }
  728. #ifdef __WXDEBUG__
  729. if( aCount == 0 ) // Should not occur
  730. {
  731. wxString msg;
  732. msg.Printf( wxT( "footprint %s, pad %s: could not find valid layer for pad" ),
  733. GetParent() ? GetParent()->GetReference() : "<null>",
  734. GetPadName().IsEmpty() ? "(unnamed)" : GetPadName() );
  735. wxLogWarning( msg );
  736. }
  737. #endif
  738. }
  739. unsigned int D_PAD::ViewGetLOD( int aLayer ) const
  740. {
  741. // Netnames will be shown only if zoom is appropriate
  742. if( IsNetnameLayer( aLayer ) )
  743. {
  744. // Pad sizes can be zero briefly when someone is typing a number like "0.5" in the pad properties dialog.
  745. // Fail gracefully if this happens.
  746. if( ( m_Size.x == 0 ) && ( m_Size.y == 0 ) )
  747. return UINT_MAX;
  748. return ( Millimeter2iu( 100 ) / std::max( m_Size.x, m_Size.y ) );
  749. }
  750. // Other layers are shown without any conditions
  751. return 0;
  752. }
  753. const BOX2I D_PAD::ViewBBox() const
  754. {
  755. // Bounding box includes soldermask too
  756. int solderMaskMargin = GetSolderMaskMargin();
  757. VECTOR2I solderPasteMargin = VECTOR2D( GetSolderPasteMargin() );
  758. EDA_RECT bbox = GetBoundingBox();
  759. // Look for the biggest possible bounding box
  760. int xMargin = std::max( solderMaskMargin, solderPasteMargin.x );
  761. int yMargin = std::max( solderMaskMargin, solderPasteMargin.y );
  762. return BOX2I( VECTOR2I( bbox.GetOrigin() ) - VECTOR2I( xMargin, yMargin ),
  763. VECTOR2I( bbox.GetSize() ) + VECTOR2I( 2 * xMargin, 2 * yMargin ) );
  764. }