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.

1518 lines
45 KiB

* 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
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
19 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
19 years ago
14 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
14 years ago
19 years ago
19 years ago
14 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 years ago
19 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
* 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
13 years ago
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
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
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
13 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2004-2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 2004-2018 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 draw_frame.cpp
  27. */
  28. #include <fctsys.h>
  29. #include <pgm_base.h>
  30. #include <kiface_i.h>
  31. #include <gr_basic.h>
  32. #include <common.h>
  33. #include <bitmaps.h>
  34. #include <macros.h>
  35. #include <id.h>
  36. #include <class_drawpanel.h>
  37. #include <base_screen.h>
  38. #include <msgpanel.h>
  39. #include <draw_frame.h>
  40. #include <confirm.h>
  41. #include <kicad_device_context.h>
  42. #include <dialog_helpers.h>
  43. #include <base_units.h>
  44. #include <math/box2.h>
  45. #include <lockfile.h>
  46. #include <trace_helpers.h>
  47. #include <wx/fontdlg.h>
  48. #include <wx/snglinst.h>
  49. #include <view/view.h>
  50. #include <view/view_controls.h>
  51. #include <gal/graphics_abstraction_layer.h>
  52. #include <tool/tool_manager.h>
  53. #include <tool/tool_dispatcher.h>
  54. #include <tool/actions.h>
  55. /**
  56. * Definition for enabling and disabling scroll bar setting trace output. See the
  57. * wxWidgets documentation on useing the WXTRACE environment variable.
  58. */
  59. static const wxString traceScrollSettings( wxT( "KicadScrollSettings" ) );
  60. ///@{
  61. /// \ingroup config
  62. /// User units
  63. static const wxString UserUnitsEntryKeyword( wxT( "Units" ) );
  64. static const wxString FpEditorUserUnitsEntryKeyword( wxT( "FpEditorUnits" ) );
  65. /// Nonzero to show grid (suffix)
  66. static const wxString ShowGridEntryKeyword( wxT( "ShowGrid" ) );
  67. /// Grid color ID (suffix)
  68. static const wxString GridColorEntryKeyword( wxT( "GridColor" ) );
  69. /// Most recently used grid size (suffix)
  70. static const wxString LastGridSizeIdKeyword( wxT( "_LastGridSize" ) );
  71. /// GAL Display Options
  72. static const wxString GalDisplayOptionsKeyword( wxT( "GalDisplayOptions" ) );
  73. const wxChar EDA_DRAW_FRAME::CANVAS_TYPE_KEY[] = wxT( "canvas_type" );
  74. static const wxString FirstRunShownKeyword( wxT( "FirstRunShown" ) );
  75. ///@}
  76. /**
  77. * Integer to set the maximum number of undo items on the stack. If zero,
  78. * undo items are unlimited.
  79. *
  80. * Present as:
  81. *
  82. * - SchematicFrameDevelMaxUndoItems (file: eeschema)
  83. * - LibeditFrameDevelMaxUndoItems (file: eeschema)
  84. * - PcbFrameDevelMaxUndoItems (file: pcbnew)
  85. * - ModEditFrameDevelMaxUndoItems (file: pcbnew)
  86. *
  87. * \ingroup develconfig
  88. */
  89. static const wxString MaxUndoItemsEntry(wxT( "DevelMaxUndoItems" ) );
  90. BEGIN_EVENT_TABLE( EDA_DRAW_FRAME, KIWAY_PLAYER )
  91. EVT_CHAR_HOOK( EDA_DRAW_FRAME::OnCharHook )
  92. EVT_MOUSEWHEEL( EDA_DRAW_FRAME::OnMouseEvent )
  93. EVT_MENU_OPEN( EDA_DRAW_FRAME::OnMenuOpen )
  94. EVT_ACTIVATE( EDA_DRAW_FRAME::OnActivate )
  95. EVT_MENU_RANGE( ID_ZOOM_BEGIN, ID_ZOOM_END, EDA_DRAW_FRAME::OnZoom )
  96. EVT_MENU_RANGE( ID_POPUP_ZOOM_START_RANGE, ID_POPUP_ZOOM_END_RANGE,
  97. EDA_DRAW_FRAME::OnZoom )
  98. EVT_MENU_RANGE( ID_POPUP_GRID_LEVEL_1000, ID_POPUP_GRID_USER,
  99. EDA_DRAW_FRAME::OnSelectGrid )
  100. EVT_TOOL( ID_TB_OPTIONS_SHOW_GRID, EDA_DRAW_FRAME::OnToggleGridState )
  101. EVT_TOOL_RANGE( ID_TB_OPTIONS_SELECT_UNIT_MM, ID_TB_OPTIONS_SELECT_UNIT_INCH,
  102. EDA_DRAW_FRAME::OnSelectUnits )
  103. EVT_TOOL( ID_TB_OPTIONS_SELECT_CURSOR, EDA_DRAW_FRAME::OnToggleCrossHairStyle )
  104. EVT_UPDATE_UI( wxID_UNDO, EDA_DRAW_FRAME::OnUpdateUndo )
  105. EVT_UPDATE_UI( wxID_REDO, EDA_DRAW_FRAME::OnUpdateRedo )
  106. EVT_UPDATE_UI( ID_TB_OPTIONS_SHOW_GRID, EDA_DRAW_FRAME::OnUpdateGrid )
  107. EVT_UPDATE_UI( ID_TB_OPTIONS_SELECT_CURSOR, EDA_DRAW_FRAME::OnUpdateCrossHairStyle )
  108. EVT_UPDATE_UI_RANGE( ID_TB_OPTIONS_SELECT_UNIT_MM, ID_TB_OPTIONS_SELECT_UNIT_INCH,
  109. EDA_DRAW_FRAME::OnUpdateUnits )
  110. END_EVENT_TABLE()
  111. EDA_DRAW_FRAME::EDA_DRAW_FRAME( KIWAY* aKiway, wxWindow* aParent,
  112. FRAME_T aFrameType,
  113. const wxString& aTitle,
  114. const wxPoint& aPos, const wxSize& aSize,
  115. long aStyle, const wxString & aFrameName ) :
  116. KIWAY_PLAYER( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ),
  117. m_galDisplayOptions( std::make_unique<KIGFX::GAL_DISPLAY_OPTIONS>() )
  118. {
  119. m_socketServer = nullptr;
  120. m_drawToolBar = NULL;
  121. m_optionsToolBar = NULL;
  122. m_auxiliaryToolBar = NULL;
  123. m_gridSelectBox = NULL;
  124. m_zoomSelectBox = NULL;
  125. m_hotkeysDescrList = NULL;
  126. m_canvas = NULL;
  127. m_canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
  128. m_canvasTypeDirty = false;
  129. m_galCanvas = NULL;
  130. m_galCanvasActive = false;
  131. m_actions = NULL;
  132. m_toolManager = NULL;
  133. m_toolDispatcher = NULL;
  134. m_messagePanel = NULL;
  135. m_currentScreen = NULL;
  136. m_toolId = ID_NO_TOOL_SELECTED;
  137. m_lastDrawToolId = ID_NO_TOOL_SELECTED;
  138. m_showAxis = false; // true to draw axis.
  139. m_showBorderAndTitleBlock = false; // true to display reference sheet.
  140. m_showGridAxis = false; // true to draw the grid axis
  141. m_showOriginAxis = false; // true to draw the grid origin
  142. m_LastGridSizeId = 0;
  143. m_drawGrid = true; // hide/Show grid. default = show
  144. m_gridColor = COLOR4D( DARKGRAY ); // Default grid color
  145. m_showPageLimits = false;
  146. m_drawBgColor = COLOR4D( BLACK ); // the background color of the draw canvas:
  147. // BLACK for Pcbnew, BLACK or WHITE for eeschema
  148. m_snapToGrid = true;
  149. m_MsgFrameHeight = EDA_MSG_PANEL::GetRequiredHeight();
  150. m_movingCursorWithKeyboard = false;
  151. m_zoomLevelCoeff = 1.0;
  152. m_auimgr.SetFlags(wxAUI_MGR_DEFAULT);
  153. CreateStatusBar( 6 );
  154. // set the size of the status bar subwindows:
  155. wxWindow* stsbar = GetStatusBar();
  156. int dims[] = {
  157. // remainder of status bar on far left is set to a default or whatever is left over.
  158. -1,
  159. // When using GetTextSize() remember the width of character '1' is not the same
  160. // as the width of '0' unless the font is fixed width, and it usually won't be.
  161. // zoom:
  162. GetTextSize( wxT( "Z 762000" ), stsbar ).x + 10,
  163. // cursor coords
  164. GetTextSize( wxT( "X 0234.567890 Y 0234.567890" ), stsbar ).x + 10,
  165. // delta distances
  166. GetTextSize( wxT( "dx 0234.567890 dx 0234.567890 d 0234.567890" ), stsbar ).x + 10,
  167. // units display, Inches is bigger than mm
  168. GetTextSize( _( "Inches" ), stsbar ).x + 10,
  169. // Size for the panel used as "Current tool in play": will take longest string from
  170. // void PCB_EDIT_FRAME::OnSelectTool( wxCommandEvent& aEvent ) in pcbnew/edit.cpp
  171. GetTextSize( wxT( "Add layer alignment target" ), stsbar ).x + 10,
  172. };
  173. SetStatusWidths( DIM( dims ), dims );
  174. // Create child subwindows.
  175. GetClientSize( &m_FrameSize.x, &m_FrameSize.y );
  176. m_FramePos.x = m_FramePos.y = 0;
  177. m_FrameSize.y -= m_MsgFrameHeight;
  178. m_canvas = new EDA_DRAW_PANEL( this, -1, wxPoint( 0, 0 ), m_FrameSize );
  179. m_messagePanel = new EDA_MSG_PANEL( this, -1, wxPoint( 0, m_FrameSize.y ),
  180. wxSize( m_FrameSize.x, m_MsgFrameHeight ) );
  181. m_messagePanel->SetBackgroundColour( COLOR4D( LIGHTGRAY ).ToColour() );
  182. }
  183. EDA_DRAW_FRAME::~EDA_DRAW_FRAME()
  184. {
  185. delete m_socketServer;
  186. for( auto socket : m_sockets )
  187. {
  188. socket->Shutdown();
  189. socket->Destroy();
  190. }
  191. if( m_canvasTypeDirty )
  192. saveCanvasTypeSetting( m_canvasType );
  193. delete m_actions;
  194. delete m_toolManager;
  195. delete m_toolDispatcher;
  196. delete m_galCanvas;
  197. delete m_currentScreen;
  198. m_currentScreen = NULL;
  199. m_auimgr.UnInit();
  200. ReleaseFile();
  201. }
  202. void EDA_DRAW_FRAME::OnCharHook( wxKeyEvent& event )
  203. {
  204. wxLogTrace( kicadTraceKeyEvent, "EDA_DRAW_FRAME::OnCharHook %s", dump( event ) );
  205. // Key events can be filtered here.
  206. // Currently no filtering is made.
  207. event.Skip();
  208. }
  209. void EDA_DRAW_FRAME::ReleaseFile()
  210. {
  211. m_file_checker = nullptr;
  212. }
  213. bool EDA_DRAW_FRAME::LockFile( const wxString& aFileName )
  214. {
  215. m_file_checker = ::LockFile( aFileName );
  216. return bool( m_file_checker );
  217. }
  218. void EDA_DRAW_FRAME::unitsChangeRefresh()
  219. {
  220. UpdateStatusBar();
  221. UpdateMsgPanel();
  222. }
  223. void EDA_DRAW_FRAME::CommonSettingsChanged()
  224. {
  225. EDA_BASE_FRAME::CommonSettingsChanged();
  226. bool option;
  227. Pgm().CommonSettings()->Read( ENBL_MOUSEWHEEL_PAN_KEY, &option );
  228. m_canvas->SetEnableMousewheelPan( option );
  229. Pgm().CommonSettings()->Read( ENBL_ZOOM_NO_CENTER_KEY, &option );
  230. m_canvas->SetEnableZoomNoCenter( option );
  231. Pgm().CommonSettings()->Read( ENBL_AUTO_PAN_KEY, &option );
  232. m_canvas->SetEnableAutoPan( option );
  233. }
  234. void EDA_DRAW_FRAME::EraseMsgBox()
  235. {
  236. if( m_messagePanel )
  237. m_messagePanel->EraseMsgBox();
  238. }
  239. void EDA_DRAW_FRAME::OnActivate( wxActivateEvent& event )
  240. {
  241. if( m_canvas )
  242. m_canvas->SetCanStartBlock( -1 );
  243. event.Skip(); // required under wxMAC
  244. }
  245. void EDA_DRAW_FRAME::OnMenuOpen( wxMenuEvent& event )
  246. {
  247. if( m_canvas )
  248. m_canvas->SetCanStartBlock( -1 );
  249. event.Skip();
  250. }
  251. void EDA_DRAW_FRAME::SkipNextLeftButtonReleaseEvent()
  252. {
  253. m_canvas->SetIgnoreLeftButtonReleaseEvent( true );
  254. }
  255. void EDA_DRAW_FRAME::OnToggleGridState( wxCommandEvent& aEvent )
  256. {
  257. SetGridVisibility( !IsGridVisible() );
  258. if( IsGalCanvasActive() )
  259. {
  260. GetGalCanvas()->GetGAL()->SetGridVisibility( IsGridVisible() );
  261. GetGalCanvas()->GetView()->MarkTargetDirty( KIGFX::TARGET_NONCACHED );
  262. }
  263. m_canvas->Refresh();
  264. }
  265. bool EDA_DRAW_FRAME::GetToolToggled( int aToolId )
  266. {
  267. // Checks all the toolbars and returns true if the given tool id is toggled.
  268. return ( ( m_mainToolBar && m_mainToolBar->GetToolToggled( aToolId ) ) ||
  269. ( m_optionsToolBar && m_optionsToolBar->GetToolToggled( aToolId ) ) ||
  270. ( m_drawToolBar && m_drawToolBar->GetToolToggled( aToolId ) ) ||
  271. ( m_auxiliaryToolBar && m_auxiliaryToolBar->GetToolToggled( aToolId ) )
  272. );
  273. }
  274. wxAuiToolBarItem* EDA_DRAW_FRAME::GetToolbarTool( int aToolId )
  275. {
  276. // Checks all the toolbars and returns a reference to the given tool id
  277. // (or the first tool found, but only one or 0 tool is expected, because on
  278. // Windows, when different tools have the same ID, it creates issues)
  279. if( m_mainToolBar && m_mainToolBar->FindTool( aToolId ) )
  280. return m_mainToolBar->FindTool( aToolId );
  281. if( m_optionsToolBar && m_optionsToolBar->FindTool( aToolId ) )
  282. return m_optionsToolBar->FindTool( aToolId );
  283. if( m_drawToolBar && m_drawToolBar->FindTool( aToolId ) )
  284. return m_drawToolBar->FindTool( aToolId );
  285. if( m_auxiliaryToolBar && m_auxiliaryToolBar->FindTool( aToolId ) )
  286. return m_auxiliaryToolBar->FindTool( aToolId );
  287. return nullptr;
  288. }
  289. void EDA_DRAW_FRAME::OnSelectUnits( wxCommandEvent& aEvent )
  290. {
  291. if( aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_MM && m_UserUnits != MILLIMETRES )
  292. {
  293. m_UserUnits = MILLIMETRES;
  294. unitsChangeRefresh();
  295. }
  296. else if( aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_INCH && m_UserUnits != INCHES )
  297. {
  298. m_UserUnits = INCHES;
  299. unitsChangeRefresh();
  300. }
  301. }
  302. void EDA_DRAW_FRAME::OnToggleCrossHairStyle( wxCommandEvent& aEvent )
  303. {
  304. INSTALL_UNBUFFERED_DC( dc, m_canvas );
  305. m_canvas->CrossHairOff( &dc );
  306. auto& galOpts = GetGalDisplayOptions();
  307. galOpts.m_fullscreenCursor = !galOpts.m_fullscreenCursor;
  308. galOpts.NotifyChanged();
  309. m_canvas->CrossHairOn( &dc );
  310. }
  311. void EDA_DRAW_FRAME::OnUpdateUndo( wxUpdateUIEvent& aEvent )
  312. {
  313. if( GetScreen() )
  314. aEvent.Enable( GetScreen()->GetUndoCommandCount() > 0 );
  315. }
  316. void EDA_DRAW_FRAME::OnUpdateRedo( wxUpdateUIEvent& aEvent )
  317. {
  318. if( GetScreen() )
  319. aEvent.Enable( GetScreen()->GetRedoCommandCount() > 0 );
  320. }
  321. void EDA_DRAW_FRAME::OnUpdateUnits( wxUpdateUIEvent& aEvent )
  322. {
  323. bool enable;
  324. enable = ( ((aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_MM) && (m_UserUnits == MILLIMETRES))
  325. || ((aEvent.GetId() == ID_TB_OPTIONS_SELECT_UNIT_INCH) && (m_UserUnits == INCHES)) );
  326. aEvent.Check( enable );
  327. DisplayUnitsMsg();
  328. }
  329. void EDA_DRAW_FRAME::OnUpdateGrid( wxUpdateUIEvent& aEvent )
  330. {
  331. wxString tool_tip = IsGridVisible() ? _( "Hide grid" ) : _( "Show grid" );
  332. aEvent.Check( IsGridVisible() );
  333. m_optionsToolBar->SetToolShortHelp( ID_TB_OPTIONS_SHOW_GRID, tool_tip );
  334. }
  335. void EDA_DRAW_FRAME::OnUpdateCrossHairStyle( wxUpdateUIEvent& aEvent )
  336. {
  337. aEvent.Check( GetGalDisplayOptions().m_fullscreenCursor );
  338. }
  339. void EDA_DRAW_FRAME::ReCreateAuxiliaryToolbar()
  340. {
  341. }
  342. void EDA_DRAW_FRAME::ReCreateMenuBar()
  343. {
  344. }
  345. bool EDA_DRAW_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, EDA_ITEM* aItem )
  346. {
  347. return false;
  348. }
  349. int EDA_DRAW_FRAME::WriteHotkeyConfig( struct EDA_HOTKEY_CONFIG* aDescList, wxString* aFullFileName )
  350. {
  351. int result = EDA_BASE_FRAME::WriteHotkeyConfig( aDescList, aFullFileName );
  352. if( IsGalCanvasActive() )
  353. GetToolManager()->UpdateHotKeys();
  354. return result;
  355. }
  356. void EDA_DRAW_FRAME::ToolOnRightClick( wxCommandEvent& event )
  357. {
  358. }
  359. void EDA_DRAW_FRAME::PrintPage( wxDC* aDC, LSET aPrintMask, bool aPrintMirrorMode, void* aData )
  360. {
  361. wxMessageBox( wxT("EDA_DRAW_FRAME::PrintPage() error") );
  362. }
  363. void EDA_DRAW_FRAME::OnSelectGrid( wxCommandEvent& event )
  364. {
  365. int* clientData;
  366. int eventId = ID_POPUP_GRID_LEVEL_100;
  367. if( event.GetEventType() == wxEVT_CHOICE )
  368. {
  369. if( m_gridSelectBox == NULL ) // Should not happen
  370. return;
  371. /*
  372. * Don't use wxCommandEvent::GetClientData() here. It always
  373. * returns NULL in GTK. This solution is not as elegant but
  374. * it works.
  375. */
  376. int index = m_gridSelectBox->GetSelection();
  377. wxASSERT( index != wxNOT_FOUND );
  378. clientData = (int*) m_gridSelectBox->wxItemContainer::GetClientData( index );
  379. if( clientData != NULL )
  380. eventId = *clientData;
  381. }
  382. else
  383. {
  384. eventId = event.GetId();
  385. }
  386. int idx = eventId - ID_POPUP_GRID_LEVEL_1000;
  387. // Notify GAL
  388. TOOL_MANAGER* mgr = GetToolManager();
  389. if( mgr && IsGalCanvasActive() )
  390. {
  391. mgr->RunAction( "common.Control.gridPreset", true, idx );
  392. }
  393. else
  394. SetPresetGrid( idx );
  395. m_canvas->Refresh();
  396. }
  397. void EDA_DRAW_FRAME::OnSelectZoom( wxCommandEvent& event )
  398. {
  399. if( m_zoomSelectBox == NULL )
  400. return; // Should not happen!
  401. int id = m_zoomSelectBox->GetCurrentSelection();
  402. if( id < 0 || !( id < (int)m_zoomSelectBox->GetCount() ) )
  403. return;
  404. if( id == 0 ) // Auto zoom (Fit in Page)
  405. {
  406. Zoom_Automatique( true );
  407. }
  408. else
  409. {
  410. double selectedZoom = GetScreen()->m_ZoomList[id-1];
  411. if( GetScreen()->GetZoom() == selectedZoom )
  412. return;
  413. GetScreen()->SetZoom( selectedZoom );
  414. RedrawScreen( GetScrollCenterPosition(), false );
  415. }
  416. // Notify GAL
  417. TOOL_MANAGER* mgr = GetToolManager();
  418. if( mgr && IsGalCanvasActive() )
  419. {
  420. mgr->RunAction( "common.Control.zoomPreset", true, id );
  421. UpdateStatusBar();
  422. }
  423. }
  424. double EDA_DRAW_FRAME::GetZoom()
  425. {
  426. return GetScreen()->GetZoom();
  427. }
  428. void EDA_DRAW_FRAME::OnMouseEvent( wxMouseEvent& event )
  429. {
  430. event.Skip();
  431. }
  432. void EDA_DRAW_FRAME::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
  433. {
  434. }
  435. void EDA_DRAW_FRAME::DisplayToolMsg( const wxString& msg )
  436. {
  437. SetStatusText( msg, 5 );
  438. }
  439. void EDA_DRAW_FRAME::DisplayUnitsMsg()
  440. {
  441. wxString msg;
  442. switch( m_UserUnits )
  443. {
  444. case INCHES:
  445. msg = _( "Inches" );
  446. break;
  447. case MILLIMETRES:
  448. msg = _( "mm" );
  449. break;
  450. default:
  451. msg = _( "Units" );
  452. break;
  453. }
  454. SetStatusText( msg, 4 );
  455. }
  456. void EDA_DRAW_FRAME::OnSize( wxSizeEvent& SizeEv )
  457. {
  458. m_FrameSize = GetClientSize( );
  459. SizeEv.Skip();
  460. }
  461. void EDA_DRAW_FRAME::SetToolID( int aId, int aCursor, const wxString& aToolMsg )
  462. {
  463. // Keep default cursor in toolbars
  464. SetCursor( wxNullCursor );
  465. // Change m_canvas cursor if requested.
  466. if( m_canvas && aCursor >= 0 )
  467. m_canvas->SetCurrentCursor( aCursor );
  468. // Change GAL canvas cursor if requested.
  469. if( IsGalCanvasActive() && aCursor >= 0 )
  470. GetGalCanvas()->SetCurrentCursor( aCursor );
  471. DisplayToolMsg( aToolMsg );
  472. if( aId < 0 )
  473. return;
  474. wxCHECK2_MSG( aId >= ID_NO_TOOL_SELECTED, aId = ID_NO_TOOL_SELECTED,
  475. wxString::Format( wxT( "Current tool ID cannot be set to %d." ), aId ) );
  476. m_toolId = aId;
  477. }
  478. void EDA_DRAW_FRAME::SetNoToolSelected()
  479. {
  480. // Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
  481. int defaultCursor = wxCURSOR_DEFAULT;
  482. // Change GAL canvas cursor if requested.
  483. if( IsGalCanvasActive() )
  484. defaultCursor = GetGalCanvas()->GetDefaultCursor();
  485. else if( m_canvas )
  486. defaultCursor = m_canvas->GetDefaultCursor();
  487. SetToolID( ID_NO_TOOL_SELECTED, defaultCursor, wxEmptyString );
  488. }
  489. wxPoint EDA_DRAW_FRAME::GetGridPosition( const wxPoint& aPosition ) const
  490. {
  491. wxPoint pos = aPosition;
  492. if( m_currentScreen != NULL && m_snapToGrid )
  493. pos = GetNearestGridPosition( aPosition );
  494. return pos;
  495. }
  496. void EDA_DRAW_FRAME::SetNextGrid()
  497. {
  498. BASE_SCREEN * screen = GetScreen();
  499. int new_grid_cmd = screen->GetGridCmdId();
  500. // if the grid id is the not the last, increment it
  501. if( screen->GridExists( new_grid_cmd + 1 ) )
  502. new_grid_cmd += 1;
  503. SetPresetGrid( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 );
  504. }
  505. void EDA_DRAW_FRAME::SetPrevGrid()
  506. {
  507. BASE_SCREEN * screen = GetScreen();
  508. int new_grid_cmd = screen->GetGridCmdId();
  509. // if the grid id is the not the first, increment it
  510. if( screen->GridExists( new_grid_cmd - 1 ) )
  511. new_grid_cmd -= 1;
  512. SetPresetGrid( new_grid_cmd - ID_POPUP_GRID_LEVEL_1000 );
  513. }
  514. void EDA_DRAW_FRAME::SetPresetGrid( int aIndex )
  515. {
  516. BASE_SCREEN * screen = GetScreen();
  517. if( ! screen->GridExists( aIndex + ID_POPUP_GRID_LEVEL_1000 ) )
  518. aIndex = screen->GetGrids()[0].m_CmdId;
  519. // aIndex is a Command Id relative to ID_POPUP_GRID_LEVEL_1000 comand id code.
  520. // we need an index in grid list (the cmd id in list is is screen->GetGrids()[0].m_CmdId):
  521. int glistIdx = aIndex + ID_POPUP_GRID_LEVEL_1000 - screen->GetGrids()[0].m_CmdId;
  522. if( m_gridSelectBox )
  523. {
  524. if( glistIdx < 0 || glistIdx >= (int) m_gridSelectBox->GetCount() )
  525. {
  526. wxASSERT_MSG( false, "Invalid grid index" );
  527. return;
  528. }
  529. m_gridSelectBox->SetSelection( glistIdx );
  530. }
  531. // Be sure m_LastGridSizeId is up to date.
  532. m_LastGridSizeId = aIndex;
  533. GetScreen()->SetGrid( aIndex + ID_POPUP_GRID_LEVEL_1000 );
  534. // Put cursor on new grid
  535. SetCrossHairPosition( RefPos( true ) );
  536. }
  537. int EDA_DRAW_FRAME::BlockCommand( EDA_KEY key )
  538. {
  539. return 0;
  540. }
  541. void EDA_DRAW_FRAME::InitBlockPasteInfos()
  542. {
  543. GetScreen()->m_BlockLocate.ClearItemsList();
  544. m_canvas->SetMouseCaptureCallback( NULL );
  545. }
  546. void EDA_DRAW_FRAME::HandleBlockPlace( wxDC* DC )
  547. {
  548. }
  549. bool EDA_DRAW_FRAME::HandleBlockEnd( wxDC* DC )
  550. {
  551. return false;
  552. }
  553. void EDA_DRAW_FRAME::UpdateStatusBar()
  554. {
  555. SetStatusText( GetZoomLevelIndicator(), 1 );
  556. // Absolute and relative cursor positions are handled by overloading this function and
  557. // handling the internal to user units conversion at the appropriate level.
  558. // refresh units display
  559. DisplayUnitsMsg();
  560. }
  561. const wxString EDA_DRAW_FRAME::GetZoomLevelIndicator() const
  562. {
  563. wxString Line;
  564. double level = 0.0;
  565. if( IsGalCanvasActive() )
  566. {
  567. KIGFX::GAL* gal = m_galCanvas->GetGAL();
  568. KIGFX::VIEW* view = m_galCanvas->GetView();
  569. double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
  570. level = m_zoomLevelCoeff * zoomFactor * view->GetScale();
  571. }
  572. else if( BASE_SCREEN* screen = GetScreen() )
  573. {
  574. level = m_zoomLevelCoeff / (double) screen->GetZoom();
  575. }
  576. // returns a human readable value which can be displayed as zoom
  577. // level indicator in dialogs.
  578. Line.Printf( wxT( "Z %.2f" ), level );
  579. return Line;
  580. }
  581. void EDA_DRAW_FRAME::LoadSettings( wxConfigBase* aCfg )
  582. {
  583. EDA_BASE_FRAME::LoadSettings( aCfg );
  584. wxString baseCfgName = ConfigBaseName();
  585. // Read units used in dialogs and toolbars
  586. EDA_UNITS_T unitsTmp;
  587. if( aCfg->Read( baseCfgName + UserUnitsEntryKeyword, (int*) &unitsTmp ) )
  588. SetUserUnits( unitsTmp );
  589. else
  590. SetUserUnits( MILLIMETRES );
  591. // Read show/hide grid entry
  592. bool btmp;
  593. if( aCfg->Read( baseCfgName + ShowGridEntryKeyword, &btmp ) )
  594. SetGridVisibility( btmp );
  595. // Read grid color:
  596. COLOR4D wtmp = COLOR4D::UNSPECIFIED;
  597. if( wtmp.SetFromWxString( aCfg->Read(
  598. baseCfgName + GridColorEntryKeyword, wxT( "NONE" ) ) ) )
  599. SetGridColor( wtmp );
  600. aCfg->Read( baseCfgName + LastGridSizeIdKeyword, &m_LastGridSizeId, 0L );
  601. // m_LastGridSizeId is an offset, expected to be >= 0
  602. if( m_LastGridSizeId < 0 )
  603. m_LastGridSizeId = 0;
  604. m_UndoRedoCountMax = aCfg->Read( baseCfgName + MaxUndoItemsEntry,
  605. long( DEFAULT_MAX_UNDO_ITEMS ) );
  606. aCfg->Read( baseCfgName + FirstRunShownKeyword, &m_firstRunDialogSetting, 0L );
  607. m_galDisplayOptions->ReadConfig( aCfg, baseCfgName + GalDisplayOptionsKeyword );
  608. }
  609. void EDA_DRAW_FRAME::SaveSettings( wxConfigBase* aCfg )
  610. {
  611. EDA_BASE_FRAME::SaveSettings( aCfg );
  612. wxString baseCfgName = ConfigBaseName();
  613. aCfg->Write( baseCfgName + UserUnitsEntryKeyword, (int) m_UserUnits );
  614. aCfg->Write( baseCfgName + ShowGridEntryKeyword, IsGridVisible() );
  615. aCfg->Write( baseCfgName + GridColorEntryKeyword,
  616. GetGridColor().ToColour().GetAsString( wxC2S_CSS_SYNTAX ) );
  617. aCfg->Write( baseCfgName + LastGridSizeIdKeyword, ( long ) m_LastGridSizeId );
  618. aCfg->Write( baseCfgName + FirstRunShownKeyword, m_firstRunDialogSetting );
  619. if( GetScreen() )
  620. aCfg->Write( baseCfgName + MaxUndoItemsEntry, long( GetScreen()->GetMaxUndoItems() ) );
  621. m_galDisplayOptions->WriteConfig( aCfg, baseCfgName + GalDisplayOptionsKeyword );
  622. }
  623. void EDA_DRAW_FRAME::AppendMsgPanel( const wxString& textUpper,
  624. const wxString& textLower,
  625. COLOR4D color, int pad )
  626. {
  627. if( m_messagePanel == NULL )
  628. return;
  629. m_messagePanel->AppendMessage( textUpper, textLower, color, pad );
  630. }
  631. void EDA_DRAW_FRAME::ClearMsgPanel()
  632. {
  633. if( m_messagePanel == NULL )
  634. return;
  635. m_messagePanel->EraseMsgBox();
  636. }
  637. void EDA_DRAW_FRAME::SetMsgPanel( const MSG_PANEL_ITEMS& aList )
  638. {
  639. if( m_messagePanel == NULL )
  640. return;
  641. ClearMsgPanel();
  642. for( unsigned i = 0; i < aList.size(); i++ )
  643. m_messagePanel->AppendMessage( aList[i] );
  644. }
  645. void EDA_DRAW_FRAME::SetMsgPanel( EDA_ITEM* aItem )
  646. {
  647. wxCHECK_RET( aItem != NULL, wxT( "Invalid EDA_ITEM pointer. Bad programmer." ) );
  648. MSG_PANEL_ITEMS items;
  649. aItem->GetMsgPanelInfo( m_UserUnits, items );
  650. SetMsgPanel( items );
  651. }
  652. void EDA_DRAW_FRAME::UpdateMsgPanel()
  653. {
  654. EDA_ITEM* item = GetScreen()->GetCurItem();
  655. if( item )
  656. SetMsgPanel( item );
  657. }
  658. // FIXME: There needs to be a better way for child windows to load preferences.
  659. // This function pushes four preferences from a parent window to a child window
  660. // i.e. from eeschema to the schematic symbol editor
  661. void EDA_DRAW_FRAME::PushPreferences( const EDA_DRAW_PANEL* aParentCanvas )
  662. {
  663. m_canvas->SetEnableZoomNoCenter( aParentCanvas->GetEnableZoomNoCenter() );
  664. m_canvas->SetEnableAutoPan( aParentCanvas->GetEnableAutoPan() );
  665. }
  666. bool EDA_DRAW_FRAME::HandleBlockBegin( wxDC* aDC, EDA_KEY aKey, const wxPoint& aPosition,
  667. int aExplicitCommand )
  668. {
  669. BLOCK_SELECTOR* block = &GetScreen()->m_BlockLocate;
  670. if( ( block->GetCommand() != BLOCK_IDLE ) || ( block->GetState() != STATE_NO_BLOCK ) )
  671. return false;
  672. if( aExplicitCommand == 0 )
  673. block->SetCommand( (BLOCK_COMMAND_T) BlockCommand( aKey ) );
  674. else
  675. block->SetCommand( (BLOCK_COMMAND_T) aExplicitCommand );
  676. if( block->GetCommand() == 0 )
  677. return false;
  678. switch( block->GetCommand() )
  679. {
  680. case BLOCK_IDLE:
  681. break;
  682. case BLOCK_MOVE: // Move
  683. case BLOCK_DRAG: // Drag (block defined)
  684. case BLOCK_DRAG_ITEM: // Drag from a drag item command
  685. case BLOCK_DUPLICATE: // Duplicate
  686. case BLOCK_DUPLICATE_AND_INCREMENT: // Duplicate and increment relevant references
  687. case BLOCK_DELETE: // Delete
  688. case BLOCK_COPY: // Copy
  689. case BLOCK_ROTATE: // Rotate 90 deg
  690. case BLOCK_FLIP: // Flip
  691. case BLOCK_ZOOM: // Window Zoom
  692. case BLOCK_MIRROR_X:
  693. case BLOCK_MIRROR_Y: // mirror
  694. case BLOCK_PRESELECT_MOVE: // Move with preselection list
  695. block->InitData( m_canvas, aPosition );
  696. break;
  697. case BLOCK_PASTE:
  698. block->InitData( m_canvas, aPosition );
  699. block->SetLastCursorPosition( wxPoint( 0, 0 ) );
  700. InitBlockPasteInfos();
  701. if( block->GetCount() == 0 ) // No data to paste
  702. {
  703. DisplayError( this, wxT( "No block to paste" ), 20 );
  704. GetScreen()->m_BlockLocate.SetCommand( BLOCK_IDLE );
  705. m_canvas->SetMouseCaptureCallback( NULL );
  706. block->SetState( STATE_NO_BLOCK );
  707. block->SetMessageBlock( this );
  708. return true;
  709. }
  710. if( !m_canvas->IsMouseCaptured() )
  711. {
  712. block->ClearItemsList();
  713. DisplayError( this,
  714. wxT( "EDA_DRAW_FRAME::HandleBlockBegin() Err: m_mouseCaptureCallback NULL" ) );
  715. block->SetState( STATE_NO_BLOCK );
  716. block->SetMessageBlock( this );
  717. return true;
  718. }
  719. block->SetState( STATE_BLOCK_MOVE );
  720. m_canvas->CallMouseCapture( aDC, aPosition, false );
  721. break;
  722. default:
  723. {
  724. wxString msg;
  725. msg << wxT( "EDA_DRAW_FRAME::HandleBlockBegin() error: Unknown command " ) <<
  726. block->GetCommand();
  727. DisplayError( this, msg );
  728. }
  729. break;
  730. }
  731. block->SetMessageBlock( this );
  732. return true;
  733. }
  734. // I am not seeing a problem with this size yet:
  735. static const double MAX_AXIS = INT_MAX - 100;
  736. #define VIRT_MIN (-MAX_AXIS/2.0) ///< min X or Y coordinate in virtual space
  737. #define VIRT_MAX (MAX_AXIS/2.0) ///< max X or Y coordinate in virtual space
  738. void EDA_DRAW_FRAME::AdjustScrollBars( const wxPoint& aCenterPositionIU )
  739. {
  740. BASE_SCREEN* screen = GetScreen();
  741. if( !screen || !m_canvas )
  742. return;
  743. double scale = screen->GetScalingFactor();
  744. wxLogTrace( traceScrollSettings, wxT( "Center Position = ( %d, %d ), scale = %.10g" ),
  745. aCenterPositionIU.x, aCenterPositionIU.y, scale );
  746. // Calculate the portion of the drawing that can be displayed in the
  747. // client area at the current zoom level.
  748. // visible viewport in device units ~ pixels
  749. wxSize clientSizeDU = m_canvas->GetClientSize();
  750. // Size of the client window in IU
  751. DSIZE clientSizeIU( clientSizeDU.x / scale, clientSizeDU.y / scale );
  752. // Full drawing or "page" rectangle in internal units
  753. DBOX pageRectIU( wxPoint( 0, 0 ), wxSize( GetPageSizeIU().x, GetPageSizeIU().y ) );
  754. // Remark: if something is modified here, perhaps EDA_DRAW_FRAME::RedrawScreen2()
  755. // will need changes accordint to the way the center is computed
  756. // Account for scrollbars
  757. wxSize scrollbarSizeDU = m_canvas->GetSize() - m_canvas->GetClientSize();
  758. wxSize scrollbarSizeIU = scrollbarSizeDU * (1 / scale);
  759. wxPoint centerAdjustedIU = aCenterPositionIU + scrollbarSizeIU / 2;
  760. // The upper left corner of the client rectangle in internal units.
  761. double xIU = centerAdjustedIU.x - clientSizeIU.x / 2.0;
  762. double yIU = centerAdjustedIU.y - clientSizeIU.y / 2.0;
  763. // If drawn around the center, adjust the client rectangle accordingly.
  764. if( screen->m_Center )
  765. {
  766. // half page offset.
  767. xIU += pageRectIU.GetWidth() / 2.0;
  768. yIU += pageRectIU.GetHeight() / 2.0;
  769. }
  770. DBOX clientRectIU( wxPoint( xIU, yIU ), wxSize( clientSizeIU.x, clientSizeIU.y ) );
  771. wxPoint centerPositionIU;
  772. // put "int" limits on the clientRect
  773. if( clientRectIU.GetLeft() < VIRT_MIN )
  774. clientRectIU.MoveLeftTo( VIRT_MIN );
  775. if( clientRectIU.GetTop() < VIRT_MIN )
  776. clientRectIU.MoveTopTo( VIRT_MIN );
  777. if( clientRectIU.GetRight() > VIRT_MAX )
  778. clientRectIU.MoveRightTo( VIRT_MAX );
  779. if( clientRectIU.GetBottom() > VIRT_MAX )
  780. clientRectIU.MoveBottomTo( VIRT_MAX );
  781. centerPositionIU.x = KiROUND( clientRectIU.GetX() + clientRectIU.GetWidth() / 2 );
  782. centerPositionIU.y = KiROUND( clientRectIU.GetY() + clientRectIU.GetHeight() / 2 );
  783. if( screen->m_Center )
  784. {
  785. centerPositionIU.x -= KiROUND( pageRectIU.GetWidth() / 2.0 );
  786. centerPositionIU.y -= KiROUND( pageRectIU.GetHeight() / 2.0 );
  787. }
  788. DSIZE virtualSizeIU;
  789. if( pageRectIU.GetLeft() < clientRectIU.GetLeft() && pageRectIU.GetRight() > clientRectIU.GetRight() )
  790. {
  791. virtualSizeIU.x = pageRectIU.GetSize().x;
  792. }
  793. else
  794. {
  795. double pageCenterX = pageRectIU.GetX() + ( pageRectIU.GetWidth() / 2 );
  796. double clientCenterX = clientRectIU.GetX() + ( clientRectIU.GetWidth() / 2 );
  797. if( clientRectIU.GetWidth() > pageRectIU.GetWidth() )
  798. {
  799. if( pageCenterX > clientCenterX )
  800. virtualSizeIU.x = ( pageCenterX - clientRectIU.GetLeft() ) * 2;
  801. else if( pageCenterX < clientCenterX )
  802. virtualSizeIU.x = ( clientRectIU.GetRight() - pageCenterX ) * 2;
  803. else
  804. virtualSizeIU.x = clientRectIU.GetWidth();
  805. }
  806. else
  807. {
  808. if( pageCenterX > clientCenterX )
  809. virtualSizeIU.x = pageRectIU.GetWidth() + ( (pageRectIU.GetLeft() - clientRectIU.GetLeft() ) * 2 );
  810. else if( pageCenterX < clientCenterX )
  811. virtualSizeIU.x = pageRectIU.GetWidth() + ( (clientRectIU.GetRight() - pageRectIU.GetRight() ) * 2 );
  812. else
  813. virtualSizeIU.x = pageRectIU.GetWidth();
  814. }
  815. }
  816. if( pageRectIU.GetTop() < clientRectIU.GetTop() && pageRectIU.GetBottom() > clientRectIU.GetBottom() )
  817. {
  818. virtualSizeIU.y = pageRectIU.GetSize().y;
  819. }
  820. else
  821. {
  822. double pageCenterY = pageRectIU.GetY() + ( pageRectIU.GetHeight() / 2 );
  823. double clientCenterY = clientRectIU.GetY() + ( clientRectIU.GetHeight() / 2 );
  824. if( clientRectIU.GetHeight() > pageRectIU.GetHeight() )
  825. {
  826. if( pageCenterY > clientCenterY )
  827. virtualSizeIU.y = ( pageCenterY - clientRectIU.GetTop() ) * 2;
  828. else if( pageCenterY < clientCenterY )
  829. virtualSizeIU.y = ( clientRectIU.GetBottom() - pageCenterY ) * 2;
  830. else
  831. virtualSizeIU.y = clientRectIU.GetHeight();
  832. }
  833. else
  834. {
  835. if( pageCenterY > clientCenterY )
  836. virtualSizeIU.y = pageRectIU.GetHeight() +
  837. ( ( pageRectIU.GetTop() - clientRectIU.GetTop() ) * 2 );
  838. else if( pageCenterY < clientCenterY )
  839. virtualSizeIU.y = pageRectIU.GetHeight() +
  840. ( ( clientRectIU.GetBottom() - pageRectIU.GetBottom() ) * 2 );
  841. else
  842. virtualSizeIU.y = pageRectIU.GetHeight();
  843. }
  844. }
  845. // put "int" limits on the virtualSizeIU
  846. virtualSizeIU.x = std::min( virtualSizeIU.x, MAX_AXIS );
  847. virtualSizeIU.y = std::min( virtualSizeIU.y, MAX_AXIS );
  848. if( screen->m_Center )
  849. {
  850. screen->m_DrawOrg.x = -KiROUND( virtualSizeIU.x / 2.0 );
  851. screen->m_DrawOrg.y = -KiROUND( virtualSizeIU.y / 2.0 );
  852. }
  853. else
  854. {
  855. screen->m_DrawOrg.x = -KiROUND( ( virtualSizeIU.x - pageRectIU.GetWidth() ) / 2.0 );
  856. screen->m_DrawOrg.y = -KiROUND( ( virtualSizeIU.y - pageRectIU.GetHeight() ) / 2.0 );
  857. }
  858. /* Always set scrollbar pixels per unit to 1 unless you want the zoom
  859. * around cursor to jump around. This reported problem occurs when the
  860. * zoom point is not on a pixel per unit increment. If you set the
  861. * pixels per unit to 10, you have potential for the zoom point to
  862. * jump around +/-5 pixels from the nearest grid point.
  863. */
  864. screen->m_ScrollPixelsPerUnitX = screen->m_ScrollPixelsPerUnitY = 1;
  865. // Number of scroll bar units for the given zoom level in device units.
  866. double unitsX = virtualSizeIU.x * scale;
  867. double unitsY = virtualSizeIU.y * scale;
  868. // Store the requested center position for later use
  869. SetScrollCenterPosition( aCenterPositionIU );
  870. // Calculate the scroll bar position in internal units to place the
  871. // center position at the center of client rectangle.
  872. double posX = centerPositionIU.x - clientRectIU.GetWidth() / 2.0 - screen->m_DrawOrg.x;
  873. double posY = centerPositionIU.y - clientRectIU.GetHeight() / 2.0 - screen->m_DrawOrg.y;
  874. // Convert scroll bar position to device units.
  875. posX = KiROUND( posX * scale );
  876. posY = KiROUND( posY * scale );
  877. if( posX < 0 )
  878. {
  879. wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %.10g" ), posX );
  880. posX = 0;
  881. }
  882. if( posX > unitsX )
  883. {
  884. wxLogTrace( traceScrollSettings, wxT( "Required scroll bar X position %.10g" ), posX );
  885. posX = unitsX;
  886. }
  887. if( posY < 0 )
  888. {
  889. wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %.10g" ), posY );
  890. posY = 0;
  891. }
  892. if( posY > unitsY )
  893. {
  894. wxLogTrace( traceScrollSettings, wxT( "Required scroll bar Y position %.10g" ), posY );
  895. posY = unitsY;
  896. }
  897. screen->m_ScrollbarPos = wxPoint( KiROUND( posX ), KiROUND( posY ) );
  898. screen->m_ScrollbarNumber = wxSize( KiROUND( unitsX ), KiROUND( unitsY ) );
  899. wxLogTrace( traceScrollSettings,
  900. wxT( "Drawing = (%.10g, %.10g), Client = (%.10g, %.10g), Offset = (%d, %d), SetScrollbars(%d, %d, %d, %d, %d, %d)" ),
  901. virtualSizeIU.x, virtualSizeIU.y, clientSizeIU.x, clientSizeIU.y,
  902. screen->m_DrawOrg.x, screen->m_DrawOrg.y,
  903. screen->m_ScrollPixelsPerUnitX, screen->m_ScrollPixelsPerUnitY,
  904. screen->m_ScrollbarNumber.x, screen->m_ScrollbarNumber.y,
  905. screen->m_ScrollbarPos.x, screen->m_ScrollbarPos.y );
  906. bool noRefresh = true;
  907. m_canvas->SetScrollbars( screen->m_ScrollPixelsPerUnitX,
  908. screen->m_ScrollPixelsPerUnitY,
  909. screen->m_ScrollbarNumber.x,
  910. screen->m_ScrollbarNumber.y,
  911. screen->m_ScrollbarPos.x,
  912. screen->m_ScrollbarPos.y, noRefresh );
  913. }
  914. void EDA_DRAW_FRAME::UseGalCanvas( bool aEnable )
  915. {
  916. KIGFX::VIEW* view = GetGalCanvas()->GetView();
  917. KIGFX::GAL* gal = GetGalCanvas()->GetGAL();
  918. // Display the same view after canvas switching
  919. if( aEnable )
  920. {
  921. // Switch to GAL renderer from legacy
  922. if( !m_galCanvasActive )
  923. {
  924. // Set up viewport
  925. double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
  926. double zoom = 1.0 / ( zoomFactor * m_canvas->GetZoom() );
  927. view->SetScale( zoom );
  928. view->SetCenter( VECTOR2D( m_canvas->GetScreenCenterLogicalPosition() ) );
  929. }
  930. // Set up grid settings
  931. gal->SetGridVisibility( IsGridVisible() );
  932. gal->SetGridSize( VECTOR2D( GetScreen()->GetGridSize() ) );
  933. gal->SetGridOrigin( VECTOR2D( GetGridOrigin() ) );
  934. // Transfer EDA_DRAW_PANEL settings
  935. GetGalCanvas()->GetViewControls()->EnableCursorWarping( !m_canvas->GetEnableZoomNoCenter() );
  936. GetGalCanvas()->GetViewControls()->EnableMousewheelPan( m_canvas->GetEnableMousewheelPan() );
  937. GetGalCanvas()->GetViewControls()->EnableAutoPan( m_canvas->GetEnableAutoPan() );
  938. }
  939. else if( m_galCanvasActive )
  940. {
  941. // Switch to legacy renderer from GAL
  942. double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor();
  943. // TODO replace it with EDA_DRAW_PANEL_GAL::GetLegacyZoom
  944. m_canvas->SetZoom( 1.0 / ( zoomFactor * view->GetScale() ) );
  945. VECTOR2D center = view->GetCenter();
  946. AdjustScrollBars( wxPoint( center.x, center.y ) );
  947. }
  948. m_canvas->SetEvtHandlerEnabled( !aEnable );
  949. GetGalCanvas()->SetEvtHandlerEnabled( aEnable );
  950. // Switch panes
  951. m_auimgr.GetPane( wxT( "DrawFrame" ) ).Show( !aEnable );
  952. m_auimgr.GetPane( wxT( "DrawFrameGal" ) ).Show( aEnable );
  953. m_auimgr.Update();
  954. // Reset current tool on switch();
  955. SetNoToolSelected();
  956. m_galCanvasActive = aEnable;
  957. }
  958. bool EDA_DRAW_FRAME::SwitchCanvas( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType )
  959. {
  960. auto galCanvas = GetGalCanvas();
  961. wxCHECK( galCanvas, false );
  962. bool use_gal = galCanvas->SwitchBackend( aCanvasType );
  963. use_gal &= aCanvasType != EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
  964. UseGalCanvas( use_gal );
  965. m_canvasType = use_gal ? aCanvasType : EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
  966. m_canvasTypeDirty = true;
  967. return use_gal;
  968. }
  969. EDA_DRAW_PANEL_GAL::GAL_TYPE EDA_DRAW_FRAME::loadCanvasTypeSetting() const
  970. {
  971. EDA_DRAW_PANEL_GAL::GAL_TYPE canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
  972. wxConfigBase* cfg = Kiface().KifaceSettings();
  973. if( cfg )
  974. canvasType = (EDA_DRAW_PANEL_GAL::GAL_TYPE) cfg->ReadLong( CANVAS_TYPE_KEY,
  975. EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE );
  976. if( canvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
  977. || canvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
  978. {
  979. assert( false );
  980. canvasType = EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE;
  981. }
  982. return canvasType;
  983. }
  984. bool EDA_DRAW_FRAME::saveCanvasTypeSetting( EDA_DRAW_PANEL_GAL::GAL_TYPE aCanvasType )
  985. {
  986. if( aCanvasType < EDA_DRAW_PANEL_GAL::GAL_TYPE_NONE
  987. || aCanvasType >= EDA_DRAW_PANEL_GAL::GAL_TYPE_LAST )
  988. {
  989. assert( false );
  990. return false;
  991. }
  992. wxConfigBase* cfg = Kiface().KifaceSettings();
  993. if( cfg )
  994. return cfg->Write( CANVAS_TYPE_KEY, (long) aCanvasType );
  995. return false;
  996. }
  997. //-----< BASE_SCREEN API moved here >--------------------------------------------
  998. wxPoint EDA_DRAW_FRAME::GetCrossHairPosition( bool aInvertY ) const
  999. {
  1000. // subject to change, borrow from old BASE_SCREEN for now.
  1001. if( IsGalCanvasActive() )
  1002. {
  1003. VECTOR2I cursor = GetGalCanvas()->GetViewControls()->GetCursorPosition();
  1004. return wxPoint( cursor.x, cursor.y );
  1005. }
  1006. else
  1007. {
  1008. BASE_SCREEN* screen = GetScreen(); // virtual call
  1009. return screen->getCrossHairPosition( aInvertY );
  1010. }
  1011. }
  1012. void EDA_DRAW_FRAME::SetCrossHairPosition( const wxPoint& aPosition, bool aSnapToGrid )
  1013. {
  1014. BASE_SCREEN* screen = GetScreen(); // virtual call
  1015. screen->setCrossHairPosition( aPosition, GetGridOrigin(), aSnapToGrid );
  1016. }
  1017. wxPoint EDA_DRAW_FRAME::GetCursorPosition( bool aOnGrid, wxRealPoint* aGridSize ) const
  1018. {
  1019. BASE_SCREEN* screen = GetScreen(); // virtual call
  1020. return screen->getCursorPosition( aOnGrid, GetGridOrigin(), aGridSize );
  1021. }
  1022. wxPoint EDA_DRAW_FRAME::GetNearestGridPosition( const wxPoint& aPosition, wxRealPoint* aGridSize ) const
  1023. {
  1024. BASE_SCREEN* screen = GetScreen(); // virtual call
  1025. return screen->getNearestGridPosition( aPosition, GetGridOrigin(), aGridSize );
  1026. }
  1027. wxPoint EDA_DRAW_FRAME::GetCrossHairScreenPosition() const
  1028. {
  1029. BASE_SCREEN* screen = GetScreen(); // virtual call
  1030. return screen->getCrossHairScreenPosition();
  1031. }
  1032. void EDA_DRAW_FRAME::SetMousePosition( const wxPoint& aPosition )
  1033. {
  1034. BASE_SCREEN* screen = GetScreen(); // virtual call
  1035. screen->setMousePosition( aPosition );
  1036. }
  1037. wxPoint EDA_DRAW_FRAME::RefPos( bool useMouse ) const
  1038. {
  1039. BASE_SCREEN* screen = GetScreen(); // virtual call
  1040. return screen->refPos( useMouse );
  1041. }
  1042. const wxPoint& EDA_DRAW_FRAME::GetScrollCenterPosition() const
  1043. {
  1044. BASE_SCREEN* screen = GetScreen(); // virtual call
  1045. return screen->getScrollCenterPosition();
  1046. }
  1047. void EDA_DRAW_FRAME::SetScrollCenterPosition( const wxPoint& aPoint )
  1048. {
  1049. BASE_SCREEN* screen = GetScreen(); // virtual call
  1050. screen->setScrollCenterPosition( aPoint );
  1051. }
  1052. //-----</BASE_SCREEN API moved here >--------------------------------------------
  1053. void EDA_DRAW_FRAME::RefreshCrossHair( const wxPoint &aOldPos,
  1054. const wxPoint &aEvtPos,
  1055. wxDC* aDC )
  1056. {
  1057. wxPoint newpos = GetCrossHairPosition();
  1058. // Redraw the crosshair if it moved
  1059. if( aOldPos != newpos )
  1060. {
  1061. SetCrossHairPosition( aOldPos, false );
  1062. m_canvas->CrossHairOff( aDC );
  1063. SetCrossHairPosition( newpos, false );
  1064. m_canvas->CrossHairOn( aDC );
  1065. if( m_canvas->IsMouseCaptured() )
  1066. {
  1067. #ifdef USE_WX_OVERLAY
  1068. wxDCOverlay oDC( m_overlay, (wxWindowDC*)aDC );
  1069. oDC.Clear();
  1070. m_canvas->CallMouseCapture( aDC, aEvtPos, false );
  1071. #else
  1072. m_canvas->CallMouseCapture( aDC, aEvtPos, true );
  1073. #endif
  1074. }
  1075. #ifdef USE_WX_OVERLAY
  1076. else
  1077. {
  1078. m_overlay.Reset();
  1079. }
  1080. #endif
  1081. }
  1082. }
  1083. bool EDA_DRAW_FRAME::GeneralControlKeyMovement( int aHotKey, wxPoint *aPos,
  1084. bool aSnapToGrid )
  1085. {
  1086. bool key_handled = false;
  1087. // If requested snap the current position to the grid
  1088. if( aSnapToGrid )
  1089. *aPos = GetNearestGridPosition( *aPos );
  1090. switch( aHotKey )
  1091. {
  1092. // All these keys have almost the same treatment
  1093. case GR_KB_CTRL | WXK_NUMPAD8:
  1094. case GR_KB_CTRL | WXK_UP:
  1095. case GR_KB_CTRL | WXK_NUMPAD2:
  1096. case GR_KB_CTRL | WXK_DOWN:
  1097. case GR_KB_CTRL | WXK_NUMPAD4:
  1098. case GR_KB_CTRL | WXK_LEFT:
  1099. case GR_KB_CTRL | WXK_NUMPAD6:
  1100. case GR_KB_CTRL | WXK_RIGHT:
  1101. case WXK_NUMPAD8:
  1102. case WXK_UP:
  1103. case WXK_NUMPAD2:
  1104. case WXK_DOWN:
  1105. case WXK_NUMPAD4:
  1106. case WXK_LEFT:
  1107. case WXK_NUMPAD6:
  1108. case WXK_RIGHT:
  1109. key_handled = true;
  1110. {
  1111. /* Here's a tricky part: when doing cursor key movement, the
  1112. * 'previous' point should be taken from memory, *not* from the
  1113. * freshly computed position in the event. Otherwise you can't do
  1114. * sub-pixel movement. The m_movingCursorWithKeyboard oneshot 'eats'
  1115. * the automatic motion event generated by cursor warping */
  1116. wxRealPoint gridSize = GetScreen()->GetGridSize();
  1117. *aPos = GetCrossHairPosition();
  1118. // Bonus: ^key moves faster (x10)
  1119. switch( aHotKey )
  1120. {
  1121. case GR_KB_CTRL|WXK_NUMPAD8:
  1122. case GR_KB_CTRL|WXK_UP:
  1123. aPos->y -= KiROUND( 10 * gridSize.y );
  1124. break;
  1125. case GR_KB_CTRL|WXK_NUMPAD2:
  1126. case GR_KB_CTRL|WXK_DOWN:
  1127. aPos->y += KiROUND( 10 * gridSize.y );
  1128. break;
  1129. case GR_KB_CTRL|WXK_NUMPAD4:
  1130. case GR_KB_CTRL|WXK_LEFT:
  1131. aPos->x -= KiROUND( 10 * gridSize.x );
  1132. break;
  1133. case GR_KB_CTRL|WXK_NUMPAD6:
  1134. case GR_KB_CTRL|WXK_RIGHT:
  1135. aPos->x += KiROUND( 10 * gridSize.x );
  1136. break;
  1137. case WXK_NUMPAD8:
  1138. case WXK_UP:
  1139. aPos->y -= KiROUND( gridSize.y );
  1140. break;
  1141. case WXK_NUMPAD2:
  1142. case WXK_DOWN:
  1143. aPos->y += KiROUND( gridSize.y );
  1144. break;
  1145. case WXK_NUMPAD4:
  1146. case WXK_LEFT:
  1147. aPos->x -= KiROUND( gridSize.x );
  1148. break;
  1149. case WXK_NUMPAD6:
  1150. case WXK_RIGHT:
  1151. aPos->x += KiROUND( gridSize.x );
  1152. break;
  1153. default: /* Can't happen since we entered the statement */
  1154. break;
  1155. }
  1156. m_canvas->MoveCursor( *aPos );
  1157. m_movingCursorWithKeyboard = true;
  1158. }
  1159. break;
  1160. default:
  1161. break;
  1162. }
  1163. return key_handled;
  1164. }
  1165. bool EDA_DRAW_FRAME::isBusy() const
  1166. {
  1167. const BASE_SCREEN* screen = const_cast< BASE_SCREEN* >( GetScreen() );
  1168. if( !screen )
  1169. return false;
  1170. return ( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
  1171. || ( screen->m_BlockLocate.GetState() != STATE_NO_BLOCK );
  1172. }