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.

1873 lines
62 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
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
18 years ago
16 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
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
18 years ago
18 years ago
18 years ago
18 years ago
16 years ago
16 years ago
16 years ago
18 years ago
18 years ago
16 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 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
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
16 years ago
18 years ago
16 years ago
18 years ago
18 years ago
16 years ago
16 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
18 years ago
18 years ago
16 years ago
16 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
16 years ago
18 years ago
18 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
18 years ago
16 years ago
18 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
18 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
16 years ago
18 years ago
16 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
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
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
18 years ago
16 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
16 years ago
18 years ago
16 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
* 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
18 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
18 years ago
18 years ago
18 years ago
18 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
18 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
18 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
18 years ago
18 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
18 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
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
18 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
18 years ago
18 years ago
18 years ago
18 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 1992-2013 jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  6. * Copyright (C) 1992-2013 KiCad Developers, see change_log.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 eeschema/netform.cpp
  27. * @brief Net list generation code.
  28. */
  29. #include <fctsys.h>
  30. #include <confirm.h>
  31. #include <kicad_string.h>
  32. #include <gestfich.h>
  33. #include <pgm_base.h>
  34. #include <wxEeschemaStruct.h>
  35. #include <netlist.h>
  36. #include <class_netlist_object.h>
  37. #include <class_library.h>
  38. #include <lib_pin.h>
  39. #include <sch_component.h>
  40. #include <sch_text.h>
  41. #include <sch_sheet.h>
  42. #include <wx/tokenzr.h>
  43. #include <xnode.h> // also nests: <wx/xml/xml.h>
  44. #include <build_version.h>
  45. #include <set>
  46. #define INTERMEDIATE_NETLIST_EXT wxT("xml")
  47. /**
  48. * Class UNIQUE_STRINGS
  49. * tracks unique wxStrings and is useful in telling if a string
  50. * has been seen before.
  51. */
  52. class UNIQUE_STRINGS
  53. {
  54. std::set<wxString> m_set; ///< set of wxStrings already found
  55. typedef std::set<wxString>::iterator us_iterator;
  56. public:
  57. /**
  58. * Function Clear
  59. * erases the record.
  60. */
  61. void Clear() { m_set.clear(); }
  62. /**
  63. * Function Lookup
  64. * returns true if \a aString already exists in the set, otherwise returns
  65. * false and adds \a aString to the set for next time.
  66. */
  67. bool Lookup( const wxString& aString );
  68. };
  69. bool UNIQUE_STRINGS::Lookup( const wxString& aString )
  70. {
  71. std::pair<us_iterator, bool> pair = m_set.insert( aString );
  72. return !pair.second;
  73. }
  74. /**
  75. * Class NETLIST_EXPORT_TOOL
  76. * is a private implementation class used in this source file to keep track
  77. * of and recycle datastructures used in the generation of various exported netlist
  78. * files. Since it is private it is not in a header file.
  79. */
  80. class NETLIST_EXPORT_TOOL
  81. {
  82. NETLIST_OBJECT_LIST * m_masterList; /// The main connected items flat list
  83. /// Used to temporary store and filter the list of pins of a schematic component
  84. /// when generating schematic component data in netlist (comp section)
  85. NETLIST_OBJECT_LIST m_SortedComponentPinList;
  86. /// Used for "multi parts per package" components,
  87. /// avoids processing a lib component more than once.
  88. UNIQUE_STRINGS m_ReferencesAlreadyFound;
  89. // share a code generated std::set<void*> to reduce code volume
  90. std::set<void*> m_LibParts; ///< unique library parts used
  91. std::set<void*> m_Libraries; ///< unique libraries used
  92. /**
  93. * Function sprintPinNetName
  94. * formats the net name for \a aPin using \a aNetNameFormat into \a aResult.
  95. * <p>
  96. * Net name is:
  97. * <ul>
  98. * <li> "?" if pin not connected
  99. * <li> "netname" for global net (like gnd, vcc ..
  100. * <li> "/path/netname" for the usual nets
  101. * </ul>
  102. */
  103. static void sprintPinNetName( wxString& aResult, const wxString& aNetNameFormat,
  104. NETLIST_OBJECT* aPin );
  105. /**
  106. * Function findNextComponentAndCreatePinList
  107. * finds a component from the DrawList and builds
  108. * its pin list in m_SortedComponentPinList. This list is sorted by pin num.
  109. * the component is the next actual component after aItem
  110. * (power symbols and virtual components that have their reference starting by '#'are skipped).
  111. */
  112. SCH_COMPONENT* findNextComponentAndCreatePinList( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
  113. SCH_COMPONENT* findNextComponent( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath );
  114. /**
  115. * Function eraseDuplicatePins
  116. * erase duplicate Pins from m_SortedComponentPinList (i.e. set pointer in this list to NULL).
  117. * (This is a list of pins found in the whole schematic, for a single
  118. * component.) These duplicate pins were put in list because some pins (powers... )
  119. * are found more than one time when we have a multiple parts per package
  120. * component. For instance, a 74ls00 has 4 parts, and therefore the VCC pin
  121. * and GND pin appears 4 times in the list.
  122. * Note: this list *MUST* be sorted by pin number (.m_PinNum member value)
  123. * Also set the m_Flag member of "removed" NETLIST_OBJECT pin item to 1
  124. */
  125. void eraseDuplicatePins( );
  126. /**
  127. * Function addPinToComponentPinList
  128. * adds a new pin description to the pin list m_SortedComponentPinList.
  129. * A pin description is a pointer to the corresponding structure
  130. * created by BuildNetList() in the table g_NetObjectslist.
  131. */
  132. bool addPinToComponentPinList( SCH_COMPONENT* Component,
  133. SCH_SHEET_PATH* sheet,
  134. LIB_PIN* PinEntry );
  135. /**
  136. * Function findAllInstancesOfComponent
  137. * is used for "multiple parts per package" components.
  138. * <p>
  139. * Search the entire design for all instances of \a aComponent based on
  140. * matching reference designator, and for each part, add all its pins
  141. * to the temporary sorted pin list.
  142. */
  143. void findAllInstancesOfComponent( SCH_COMPONENT* aComponent,
  144. LIB_COMPONENT* aEntry,
  145. SCH_SHEET_PATH* aSheetPath );
  146. /**
  147. * Function writeGENERICListOfNets
  148. * writes out nets (ranked by Netcode), and elements that are
  149. * connected as part of that net.
  150. */
  151. bool writeGENERICListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList );
  152. /**
  153. * Function writeListOfNetsCADSTAR
  154. * writes a net list (ranked by Netcode), and pins connected to it.
  155. * <p>
  156. * Format:
  157. * - ADD_TER RR2 6 \"$42\"
  158. * - B U1 100
  159. * - 6 CA
  160. * </p>
  161. */
  162. bool writeListOfNetsCADSTAR( FILE* f );
  163. /**
  164. * Function makeGenericRoot
  165. * builds the entire document tree for the generic export. This is factored
  166. * out here so we can write the tree in either S-expression file format
  167. * or in XML if we put the tree built here into a wxXmlDocument.
  168. */
  169. XNODE* makeGenericRoot();
  170. /**
  171. * Function makeGenericComponents
  172. * returns a sub-tree holding all the schematic components.
  173. */
  174. XNODE* makeGenericComponents();
  175. /**
  176. * Function makeGenericDesignHeader
  177. * fills out a project "design" header into an XML node.
  178. * @return XNODE* - the design header
  179. */
  180. XNODE* makeGenericDesignHeader();
  181. /**
  182. * Function makeGenericLibParts
  183. * fills out an XML node with the unique library parts and returns it.
  184. */
  185. XNODE* makeGenericLibParts();
  186. /**
  187. * Function makeGenericListOfNets
  188. * fills out an XML node with a list of nets and returns it.
  189. */
  190. XNODE* makeGenericListOfNets();
  191. /**
  192. * Function makeGenericLibraries
  193. * fills out an XML node with a list of used libraries and returns it.
  194. * Must have called makeGenericLibParts() before this function.
  195. */
  196. XNODE* makeGenericLibraries();
  197. public:
  198. NETLIST_EXPORT_TOOL( NETLIST_OBJECT_LIST * aMasterList )
  199. {
  200. m_masterList = aMasterList;
  201. }
  202. /**
  203. * Function WriteKiCadNetList
  204. * creates a netlist, using the S expressions.
  205. * the netlist creates the same data as the generic XML netlist,
  206. * but using SWEET (or S expression), more easy to read and faster to parse
  207. * @param aOutFileName = the full filename of the file to create
  208. * @return bool - true if there were no errors, else false.
  209. */
  210. bool WriteKiCadNetList( const wxString& aOutFileName );
  211. /**
  212. * Function WriteGENERICNetList
  213. * creates a generic netlist, now in XML.
  214. * @param aOutFileName = the full filename of the file to create
  215. * @return bool - true if there were no errors, else false.
  216. */
  217. bool WriteGENERICNetList( const wxString& aOutFileName );
  218. /**
  219. * Function WriteNetListPCBNEW
  220. * generates a net list file (Format 2 improves ORCAD PCB)
  221. *
  222. * @param f = the file to write to
  223. * @param with_pcbnew if true, then use Pcbnew format (OrcadPcb2 + a list of net),<p>
  224. * else use ORCADPCB2 basic format.
  225. */
  226. bool WriteNetListPCBNEW( FILE* f, bool with_pcbnew );
  227. /**
  228. * Function WriteNetListCADSTAR
  229. * generates a netlist file in CADSTAR Format.
  230. * Header:
  231. * HEA ..
  232. * TIM .. 2004 07 29 16 22 17
  233. * APA .. "Cadstar RINF Output - Version 6.0.2.3"
  234. * INCH UNI .. 1000.0 in
  235. * FULL TYP ..
  236. *
  237. * List of components:
  238. * .. ADD_COM X1 "CNT D41612 (48pts CONTOUR TM)"
  239. * .. ADD_COM U2 "74HCT245D" "74HCT245D"
  240. *
  241. * Connections:
  242. * .. ADD_TER RR2 * 6 "$ 42"
  243. * .. B U1 100
  244. * 6 CA
  245. *
  246. * ADD_TER .. U2 * 6 "$ 59"
  247. * .. B * U7 39
  248. * U6 17
  249. * U1 * 122
  250. *
  251. * .. ADD_TER P2 * 1 "$ 9"
  252. * .. B * T3 1
  253. *U1 * 14
  254. */
  255. bool WriteNetListCADSTAR( FILE* f );
  256. /**
  257. * Function WriteNetListPspice
  258. * generates a netlist file in PSPICE format.
  259. * <p>
  260. * All graphics text starting by [.-+] PSpice or [.-+] gnucap
  261. * are seen as spice directives and put in netlist
  262. * .-PSpice or .-gnucap put at beginning of the netlist
  263. * .+PSpice or .-genucap are put at end of the netList
  264. * @param f = the file to write to
  265. * @param aUsePrefix = true, adds an 'X' prefix to any reference designator starting with "U" or "IC",
  266. * false to leave reference designator unchanged.
  267. */
  268. bool WriteNetListPspice( FILE* f, bool aUsePrefix );
  269. /**
  270. * Function MakeCommandLine
  271. * builds up a string that describes a command line for
  272. * executing a child process. The input and output file names
  273. * along with any options to the executable are all possibly
  274. * in the returned string.
  275. *
  276. * @param aFormatString holds:
  277. * <ul>
  278. * <li>the name of the external program
  279. * <li>any options needed by that program
  280. * <li>formatting sequences, see below.
  281. * </ul>
  282. *
  283. * @param aTempfile is the name of an input file to the
  284. * external program.
  285. * @param aFinalFile is the name of an output file that
  286. * the user expects.
  287. *
  288. * <p> Supported formatting sequences and their meaning:
  289. * <ul>
  290. * <li> %B => base filename of selected output file, minus
  291. * path and extension.
  292. * <li> %I => complete filename and path of the temporary
  293. * input file.
  294. * <li> %O => complete filename and path of the user chosen
  295. * output file.
  296. * </ul>
  297. */
  298. static wxString MakeCommandLine( const wxString& aFormatString,
  299. const wxString& aTempfile, const wxString& aFinalFile );
  300. };
  301. wxString NETLIST_EXPORT_TOOL::MakeCommandLine( const wxString& aFormatString,
  302. const wxString& aTempfile, const wxString& aFinalFile )
  303. {
  304. wxString ret = aFormatString;
  305. wxFileName in = aTempfile;
  306. wxFileName out = aFinalFile;
  307. ret.Replace( wxT("%B"), out.GetName().GetData(), true );
  308. ret.Replace( wxT("%I"), in.GetFullPath().GetData(), true );
  309. ret.Replace( wxT("%O"), out.GetFullPath().GetData(), true );
  310. return ret;
  311. }
  312. /* Function WriteNetListFile
  313. * creates the netlist file. Netlist info must be existing
  314. * (call BuildNetListBase() to create this info )
  315. * param aConnectedItemsList = the initialized list of connected items
  316. * param aFormat = netlist format (NET_TYPE_PCBNEW ...)
  317. * param aFullFileName = full netlist file name
  318. * param aNetlistOptions = netlist options using OR'ed bits.
  319. * For SPICE netlist only:
  320. * if NET_USE_X_PREFIX is set : change "U" and "IC" refernce prefix to "X"
  321. * return true if success.
  322. */
  323. bool SCH_EDIT_FRAME::WriteNetListFile( NETLIST_OBJECT_LIST * aConnectedItemsList,
  324. int aFormat, const wxString& aFullFileName,
  325. unsigned aNetlistOptions )
  326. {
  327. bool ret = true;
  328. FILE* f = NULL;
  329. NETLIST_EXPORT_TOOL helper( aConnectedItemsList );
  330. bool open_file = aFormat < NET_TYPE_CUSTOM1;
  331. if( (aFormat == NET_TYPE_PCBNEW) && (aNetlistOptions & NET_PCBNEW_USE_NEW_FORMAT ) )
  332. open_file = false;
  333. if( open_file )
  334. {
  335. if( ( f = wxFopen( aFullFileName, wxT( "wt" ) ) ) == NULL )
  336. {
  337. wxString msg;
  338. msg.Printf( _( "Failed to create file <%s>" ),
  339. GetChars( aFullFileName ) );
  340. DisplayError( this, msg );
  341. return false;
  342. }
  343. }
  344. wxBusyCursor Busy;
  345. switch( aFormat )
  346. {
  347. case NET_TYPE_PCBNEW:
  348. if( (aNetlistOptions & NET_PCBNEW_USE_NEW_FORMAT ) )
  349. ret = helper.WriteKiCadNetList( aFullFileName );
  350. else
  351. {
  352. ret = helper.WriteNetListPCBNEW( f, true );
  353. fclose( f );
  354. }
  355. break;
  356. case NET_TYPE_ORCADPCB2:
  357. ret = helper.WriteNetListPCBNEW( f, false );
  358. fclose( f );
  359. break;
  360. case NET_TYPE_CADSTAR:
  361. ret = helper.WriteNetListCADSTAR( f );
  362. fclose( f );
  363. break;
  364. case NET_TYPE_SPICE:
  365. ret = helper.WriteNetListPspice( f, aNetlistOptions & NET_USE_X_PREFIX );
  366. fclose( f );
  367. break;
  368. default:
  369. {
  370. wxFileName tmpFile = aFullFileName;
  371. tmpFile.SetExt( INTERMEDIATE_NETLIST_EXT );
  372. DBG(printf("tmpFile:'%s'\n", TO_UTF8( tmpFile.GetFullPath() ) );)
  373. ret = helper.WriteGENERICNetList( tmpFile.GetFullPath() );
  374. if( !ret )
  375. break;
  376. // If user provided no plugin command line, return now.
  377. if( m_netListerCommand.IsEmpty() )
  378. break;
  379. // build full command line from user's format string, e.g.:
  380. // "xsltproc -o %O /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl %I"
  381. // becomes, after the user selects /tmp/s1.net as the output file from the file dialog:
  382. // "xsltproc -o /tmp/s1.net /usr/local/lib/kicad/plugins/netlist_form_pads-pcb.xsl /tmp/s1.xml"
  383. wxString commandLine = NETLIST_EXPORT_TOOL::MakeCommandLine( m_netListerCommand,
  384. tmpFile.GetFullPath(),
  385. aFullFileName );
  386. DBG(printf("commandLine:'%s'\n", TO_UTF8( commandLine ) );)
  387. ProcessExecute( commandLine, wxEXEC_SYNC );
  388. }
  389. break;
  390. }
  391. return ret;
  392. }
  393. /// Comparison routine for sorting by pin numbers.
  394. static bool sortPinsByNum( NETLIST_OBJECT* aPin1, NETLIST_OBJECT* aPin2 )
  395. {
  396. // return "lhs < rhs"
  397. return RefDesStringCompare( aPin1->GetPinNumText(), aPin2->GetPinNumText() ) < 0;
  398. }
  399. static bool sortPinsByNumber( LIB_PIN* aPin1, LIB_PIN* aPin2 )
  400. {
  401. // return "lhs < rhs"
  402. return RefDesStringCompare( aPin1->GetNumberString(), aPin2->GetNumberString() ) < 0;
  403. }
  404. void NETLIST_EXPORT_TOOL::sprintPinNetName( wxString& aResult,
  405. const wxString& aNetNameFormat, NETLIST_OBJECT* aPin )
  406. {
  407. int netcode = aPin->GetNet();
  408. // Not wxString::Clear(), which would free memory. We want the worst
  409. // case wxString memory to grow to avoid reallocation from within the
  410. // caller's loop.
  411. aResult.Empty();
  412. if( netcode != 0 && aPin->GetConnectionType() == PAD_CONNECT )
  413. {
  414. aResult = aPin->GetNetName();
  415. if( aResult.IsEmpty() ) // No net name: give a name from net code
  416. aResult.Printf( aNetNameFormat.GetData(), netcode );
  417. }
  418. }
  419. SCH_COMPONENT* NETLIST_EXPORT_TOOL::findNextComponent( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheetPath )
  420. {
  421. wxString ref;
  422. // continue searching from the middle of a linked list (the draw list)
  423. for( ; aItem; aItem = aItem->Next() )
  424. {
  425. if( aItem->Type() != SCH_COMPONENT_T )
  426. continue;
  427. // found next component
  428. SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
  429. // Power symbols and other components which have the reference starting
  430. // with "#" are not included in netlist (pseudo or virtual components)
  431. ref = comp->GetRef( aSheetPath );
  432. if( ref[0] == wxChar( '#' ) )
  433. continue;
  434. // if( Component->m_FlagControlMulti == 1 )
  435. // continue; /* yes */
  436. // removed because with multiple instances of one schematic
  437. // (several sheets pointing to 1 screen), this will be erroneously be
  438. // toggled.
  439. LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
  440. if( !entry )
  441. continue;
  442. // If component is a "multi parts per package" type
  443. if( entry->GetPartCount() > 1 )
  444. {
  445. // test if this reference has already been processed, and if so skip
  446. if( m_ReferencesAlreadyFound.Lookup( ref ) )
  447. continue;
  448. }
  449. // record the usage of this library component entry.
  450. m_LibParts.insert( entry ); // rejects non-unique pointers
  451. return comp;
  452. }
  453. return NULL;
  454. }
  455. SCH_COMPONENT* NETLIST_EXPORT_TOOL::findNextComponentAndCreatePinList( EDA_ITEM* aItem,
  456. SCH_SHEET_PATH* aSheetPath )
  457. {
  458. wxString ref;
  459. m_SortedComponentPinList.clear();
  460. // continue searching from the middle of a linked list (the draw list)
  461. for( ; aItem; aItem = aItem->Next() )
  462. {
  463. if( aItem->Type() != SCH_COMPONENT_T )
  464. continue;
  465. // found next component
  466. SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
  467. // Power symbols and other components which have the reference starting
  468. // with "#" are not included in netlist (pseudo or virtual components)
  469. ref = comp->GetRef( aSheetPath );
  470. if( ref[0] == wxChar( '#' ) )
  471. continue;
  472. // if( Component->m_FlagControlMulti == 1 )
  473. // continue; /* yes */
  474. // removed because with multiple instances of one schematic
  475. // (several sheets pointing to 1 screen), this will be erroneously be
  476. // toggled.
  477. LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
  478. if( !entry )
  479. continue;
  480. // If component is a "multi parts per package" type
  481. if( entry->GetPartCount() > 1 )
  482. {
  483. // test if this reference has already been processed, and if so skip
  484. if( m_ReferencesAlreadyFound.Lookup( ref ) )
  485. continue;
  486. // Collect all pins for this reference designator by searching
  487. // the entire design for other parts with the same reference designator.
  488. // This is only done once, it would be too expensive otherwise.
  489. findAllInstancesOfComponent( comp, entry, aSheetPath );
  490. }
  491. else // entry->GetPartCount() <= 1 means one part per package
  492. {
  493. LIB_PINS pins; // constructed once here
  494. entry->GetPins( pins, comp->GetUnitSelection( aSheetPath ), comp->GetConvert() );
  495. for( size_t i = 0; i < pins.size(); i++ )
  496. {
  497. LIB_PIN* pin = pins[i];
  498. wxASSERT( pin->Type() == LIB_PIN_T );
  499. addPinToComponentPinList( comp, aSheetPath, pin );
  500. }
  501. }
  502. // Sort pins in m_SortedComponentPinList by pin number
  503. sort( m_SortedComponentPinList.begin(),
  504. m_SortedComponentPinList.end(), sortPinsByNum );
  505. // Remove duplicate Pins in m_SortedComponentPinList
  506. eraseDuplicatePins( );
  507. // record the usage of this library component entry.
  508. m_LibParts.insert( entry ); // rejects non-unique pointers
  509. return comp;
  510. }
  511. return NULL;
  512. }
  513. /**
  514. * Function node
  515. * is a convenience function that creates a new XNODE with an optional textual child.
  516. * It also provides some insulation from a possible change in XML library.
  517. *
  518. * @param aName is the name to associate with a new node of type wxXML_ELEMENT_NODE.
  519. * @param aTextualContent is optional, and if given is the text to include in a child
  520. * of the returned node, and has type wxXML_TEXT_NODE.
  521. */
  522. static XNODE* node( const wxString& aName, const wxString& aTextualContent = wxEmptyString )
  523. {
  524. XNODE* n = new XNODE( wxXML_ELEMENT_NODE, aName );
  525. if( aTextualContent.Len() > 0 ) // excludes wxEmptyString, the parameter's default value
  526. n->AddChild( new XNODE( wxXML_TEXT_NODE, wxEmptyString, aTextualContent ) );
  527. return n;
  528. }
  529. XNODE* NETLIST_EXPORT_TOOL::makeGenericDesignHeader()
  530. {
  531. XNODE* xdesign = node( wxT("design") );
  532. // the root sheet is a special sheet, call it source
  533. xdesign->AddChild( node( wxT( "source" ), g_RootSheet->GetScreen()->GetFileName() ) );
  534. xdesign->AddChild( node( wxT( "date" ), DateAndTime() ) );
  535. // which Eeschema tool
  536. xdesign->AddChild( node( wxT( "tool" ), wxT( "Eeschema " ) + GetBuildVersion() ) );
  537. /* @todo might do a list of schematic pages
  538. <page name="">
  539. <title/>
  540. <revision/>
  541. <company/>
  542. <comments>
  543. <comment>blah</comment> <!-- comment1 -->
  544. <comment>blah</comment> <!-- comment2 -->
  545. </comments>
  546. <pagesize/>
  547. </page>
  548. :
  549. and a sheet hierarchy report here
  550. <sheets>
  551. <sheet name="sheetname1" page="pagenameA">
  552. <sheet name="sheetname2" page="pagenameB"/> use recursion to output?
  553. </sheet>
  554. </sheets>
  555. */
  556. return xdesign;
  557. }
  558. XNODE* NETLIST_EXPORT_TOOL::makeGenericLibraries()
  559. {
  560. XNODE* xlibs = node( wxT( "libraries" ) ); // auto_ptr
  561. for( std::set<void*>::iterator it = m_Libraries.begin(); it!=m_Libraries.end(); ++it )
  562. {
  563. CMP_LIBRARY* lib = (CMP_LIBRARY*) *it;
  564. XNODE* xlibrary;
  565. xlibs->AddChild( xlibrary = node( wxT( "library" ) ) );
  566. xlibrary->AddAttribute( wxT( "logical" ), lib->GetLogicalName() );
  567. xlibrary->AddChild( node( wxT( "uri" ), lib->GetFullFileName() ) );
  568. // @todo: add more fun stuff here
  569. }
  570. return xlibs;
  571. }
  572. XNODE* NETLIST_EXPORT_TOOL::makeGenericLibParts()
  573. {
  574. XNODE* xlibparts = node( wxT( "libparts" ) ); // auto_ptr
  575. wxString sLibpart = wxT( "libpart" );
  576. wxString sLib = wxT( "lib" );
  577. wxString sPart = wxT( "part" );
  578. wxString sAliases = wxT( "aliases" );
  579. wxString sAlias = wxT( "alias" );
  580. wxString sPins = wxT( "pins" ); // key for library component pins list
  581. wxString sPin = wxT( "pin" ); // key for one library component pin descr
  582. wxString sPinNum = wxT( "num" ); // key for one library component pin num
  583. wxString sPinName = wxT( "name" ); // key for one library component pin name
  584. wxString sPinType = wxT( "type" ); // key for one library component pin electrical type
  585. wxString sName = wxT( "name" );
  586. wxString sField = wxT( "field" );
  587. wxString sFields = wxT( "fields" );
  588. wxString sDescr = wxT( "description" );
  589. wxString sDocs = wxT( "docs" );
  590. wxString sFprints = wxT( "footprints" );
  591. wxString sFp = wxT( "fp" );
  592. LIB_PINS pinList;
  593. LIB_FIELDS fieldList;
  594. m_Libraries.clear();
  595. for( std::set<void*>::iterator it = m_LibParts.begin(); it!=m_LibParts.end(); ++it )
  596. {
  597. LIB_COMPONENT* lcomp = (LIB_COMPONENT*) *it;
  598. CMP_LIBRARY* library = lcomp->GetLibrary();
  599. m_Libraries.insert( library ); // inserts component's library if unique
  600. XNODE* xlibpart;
  601. xlibparts->AddChild( xlibpart = node( sLibpart ) );
  602. xlibpart->AddAttribute( sLib, library->GetLogicalName() );
  603. xlibpart->AddAttribute( sPart, lcomp->GetName() );
  604. if( lcomp->GetAliasCount() )
  605. {
  606. wxArrayString aliases = lcomp->GetAliasNames( false );
  607. if( aliases.GetCount() )
  608. {
  609. XNODE* xaliases = node( sAliases );
  610. xlibpart->AddChild( xaliases );
  611. for( unsigned i=0; i<aliases.GetCount(); ++i )
  612. {
  613. xaliases->AddChild( node( sAlias, aliases[i] ) );
  614. }
  615. }
  616. }
  617. //----- show the important properties -------------------------
  618. if( !lcomp->GetAlias( 0 )->GetDescription().IsEmpty() )
  619. xlibpart->AddChild( node( sDescr, lcomp->GetAlias( 0 )->GetDescription() ) );
  620. if( !lcomp->GetAlias( 0 )->GetDocFileName().IsEmpty() )
  621. xlibpart->AddChild( node( sDocs, lcomp->GetAlias( 0 )->GetDocFileName() ) );
  622. // Write the footprint list
  623. if( lcomp->GetFootPrints().GetCount() )
  624. {
  625. XNODE* xfootprints;
  626. xlibpart->AddChild( xfootprints = node( sFprints ) );
  627. for( unsigned i=0; i<lcomp->GetFootPrints().GetCount(); ++i )
  628. {
  629. xfootprints->AddChild( node( sFp, lcomp->GetFootPrints()[i] ) );
  630. }
  631. }
  632. //----- show the fields here ----------------------------------
  633. fieldList.clear();
  634. lcomp->GetFields( fieldList );
  635. XNODE* xfields;
  636. xlibpart->AddChild( xfields = node( sFields ) );
  637. for( unsigned i=0; i<fieldList.size(); ++i )
  638. {
  639. if( !fieldList[i].GetText().IsEmpty() )
  640. {
  641. XNODE* xfield;
  642. xfields->AddChild( xfield = node( sField, fieldList[i].GetText() ) );
  643. xfield->AddAttribute( sName, fieldList[i].GetName(false) );
  644. }
  645. }
  646. //----- show the pins here ------------------------------------
  647. pinList.clear();
  648. lcomp->GetPins( pinList, 0, 0 );
  649. /* we must erase redundant Pins references in pinList
  650. * These redundant pins exist because some pins
  651. * are found more than one time when a component has
  652. * multiple parts per package or has 2 representations (DeMorgan conversion)
  653. * For instance, a 74ls00 has DeMorgan conversion, with different pin shapes,
  654. * and therefore each pin appears 2 times in the list.
  655. * Common pins (VCC, GND) can also be found more than once.
  656. */
  657. sort( pinList.begin(), pinList.end(), sortPinsByNumber );
  658. for( int ii = 0; ii < (int)pinList.size()-1; ii++ )
  659. {
  660. if( pinList[ii]->GetNumber() == pinList[ii+1]->GetNumber() )
  661. { // 2 pins have the same number, remove the redundant pin at index i+1
  662. pinList.erase(pinList.begin() + ii + 1);
  663. ii--;
  664. }
  665. }
  666. if( pinList.size() )
  667. {
  668. XNODE* pins;
  669. xlibpart->AddChild( pins = node( sPins ) );
  670. for( unsigned i=0; i<pinList.size(); ++i )
  671. {
  672. XNODE* pin;
  673. pins->AddChild( pin = node( sPin ) );
  674. pin->AddAttribute( sPinNum, pinList[i]->GetNumberString() );
  675. pin->AddAttribute( sPinName, pinList[i]->GetName() );
  676. pin->AddAttribute( sPinType, pinList[i]->GetTypeString() );
  677. // caution: construction work site here, drive slowly
  678. }
  679. }
  680. }
  681. return xlibparts;
  682. }
  683. XNODE* NETLIST_EXPORT_TOOL::makeGenericListOfNets()
  684. {
  685. XNODE* xnets = node( wxT( "nets" ) ); // auto_ptr if exceptions ever get used.
  686. wxString netCodeTxt;
  687. wxString netName;
  688. wxString ref;
  689. wxString sNet = wxT( "net" );
  690. wxString sName = wxT( "name" );
  691. wxString sCode = wxT( "code" );
  692. wxString sRef = wxT( "ref" );
  693. wxString sPin = wxT( "pin" );
  694. wxString sNode = wxT( "node" );
  695. wxString sFmtd = wxT( "%d" );
  696. XNODE* xnet = 0;
  697. int netCode;
  698. int lastNetCode = -1;
  699. int sameNetcodeCount = 0;
  700. /* output:
  701. <net code="123" name="/cfcard.sch/WAIT#">
  702. <node ref="R23" pin="1"/>
  703. <node ref="U18" pin="12"/>
  704. </net>
  705. */
  706. m_LibParts.clear(); // must call this function before using m_LibParts.
  707. for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
  708. {
  709. NETLIST_OBJECT* nitem = m_masterList->GetItem( ii );
  710. SCH_COMPONENT* comp;
  711. // New net found, write net id;
  712. if( ( netCode = nitem->GetNet() ) != lastNetCode )
  713. {
  714. sameNetcodeCount = 0; // item count for this net
  715. netName = nitem->GetNetName();
  716. lastNetCode = netCode;
  717. }
  718. if( nitem->m_Type != NET_PIN )
  719. continue;
  720. if( nitem->m_Flag != 0 ) // Redundant pin, skip it
  721. continue;
  722. comp = nitem->GetComponentParent();
  723. // Get the reference for the net name and the main parent component
  724. ref = comp->GetRef( &nitem->m_SheetPath );
  725. if( ref[0] == wxChar( '#' ) )
  726. continue;
  727. if( ++sameNetcodeCount == 1 )
  728. {
  729. xnets->AddChild( xnet = node( sNet ) );
  730. netCodeTxt.Printf( sFmtd, netCode );
  731. xnet->AddAttribute( sCode, netCodeTxt );
  732. xnet->AddAttribute( sName, netName );
  733. }
  734. XNODE* xnode;
  735. xnet->AddChild( xnode = node( sNode ) );
  736. xnode->AddAttribute( sRef, ref );
  737. xnode->AddAttribute( sPin, nitem->GetPinNumText() );
  738. }
  739. return xnets;
  740. }
  741. XNODE* NETLIST_EXPORT_TOOL::makeGenericRoot()
  742. {
  743. XNODE* xroot = node( wxT( "export" ) );
  744. xroot->AddAttribute( wxT( "version" ), wxT( "D" ) );
  745. // add the "design" header
  746. xroot->AddChild( makeGenericDesignHeader() );
  747. xroot->AddChild( makeGenericComponents() );
  748. xroot->AddChild( makeGenericLibParts() );
  749. // must follow makeGenericLibParts()
  750. xroot->AddChild( makeGenericLibraries() );
  751. xroot->AddChild( makeGenericListOfNets() );
  752. return xroot;
  753. }
  754. XNODE* NETLIST_EXPORT_TOOL::makeGenericComponents()
  755. {
  756. XNODE* xcomps = node( wxT( "components" ) );
  757. wxString timeStamp;
  758. // some strings we need many times, but don't want to construct more
  759. // than once for performance. These are used within loops so the
  760. // enclosing wxString constructor would fire on each loop iteration if
  761. // they were in a nested scope.
  762. // these are actually constructor invocations, not assignments as it appears:
  763. wxString sFields = wxT( "fields" );
  764. wxString sField = wxT( "field" );
  765. wxString sComponent = wxT( "comp" ); // use "part" ?
  766. wxString sName = wxT( "name" );
  767. wxString sRef = wxT( "ref" );
  768. wxString sPins = wxT( "pins" );
  769. wxString sPin = wxT( "pin" );
  770. wxString sValue = wxT( "value" );
  771. wxString sSheetPath = wxT( "sheetpath" );
  772. wxString sFootprint = wxT( "footprint" );
  773. wxString sDatasheet = wxT( "datasheet" );
  774. wxString sTStamp = wxT( "tstamp" );
  775. wxString sTStamps = wxT( "tstamps" );
  776. wxString sTSFmt = wxT( "%8.8lX" ); // comp->m_TimeStamp
  777. wxString sLibSource = wxT( "libsource" );
  778. wxString sLibPart = wxT( "libpart" );
  779. wxString sLib = wxT( "lib" );
  780. wxString sPart = wxT( "part" );
  781. wxString sNames = wxT( "names" );
  782. m_ReferencesAlreadyFound.Clear();
  783. SCH_SHEET_LIST sheetList;
  784. // Output is xml, so there is no reason to remove spaces from the field values.
  785. // And XML element names need not be translated to various languages.
  786. for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
  787. {
  788. for( EDA_ITEM* schItem = path->LastDrawList(); schItem; schItem = schItem->Next() )
  789. {
  790. SCH_COMPONENT* comp = findNextComponentAndCreatePinList( schItem, path );
  791. if( !comp )
  792. break; // No component left
  793. schItem = comp;
  794. XNODE* xcomp; // current component being constructed
  795. // Output the component's elements in order of expected access frequency.
  796. // This may not always look best, but it will allow faster execution
  797. // under XSL processing systems which do sequential searching within
  798. // an element.
  799. xcomps->AddChild( xcomp = node( sComponent ) );
  800. xcomp->AddAttribute( sRef, comp->GetRef( path ) );
  801. xcomp->AddChild( node( sValue, comp->GetField( VALUE )->GetText() ) );
  802. if( !comp->GetField( FOOTPRINT )->IsVoid() )
  803. xcomp->AddChild( node( sFootprint, comp->GetField( FOOTPRINT )->GetText() ) );
  804. if( !comp->GetField( DATASHEET )->IsVoid() )
  805. xcomp->AddChild( node( sDatasheet, comp->GetField( DATASHEET )->GetText() ) );
  806. // Export all user defined fields within the component,
  807. // which start at field index MANDATORY_FIELDS. Only output the <fields>
  808. // container element if there are any <field>s.
  809. if( comp->GetFieldCount() > MANDATORY_FIELDS )
  810. {
  811. XNODE* xfields;
  812. xcomp->AddChild( xfields = node( sFields ) );
  813. for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx )
  814. {
  815. SCH_FIELD* f = comp->GetField( fldNdx );
  816. // only output a field if non empty and not just "~"
  817. if( !f->IsVoid() )
  818. {
  819. XNODE* xfield;
  820. xfields->AddChild( xfield = node( sField, f->GetText() ) );
  821. xfield->AddAttribute( sName, f->GetName() );
  822. }
  823. }
  824. }
  825. XNODE* xlibsource;
  826. xcomp->AddChild( xlibsource = node( sLibSource ) );
  827. // "logical" library name, which is in anticipation of a better search
  828. // algorithm for parts based on "logical_lib.part" and where logical_lib
  829. // is merely the library name minus path and extension.
  830. LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
  831. if( entry )
  832. xlibsource->AddAttribute( sLib, entry->GetLibrary()->GetLogicalName() );
  833. xlibsource->AddAttribute( sPart, comp->GetLibName() );
  834. XNODE* xsheetpath;
  835. xcomp->AddChild( xsheetpath = node( sSheetPath ) );
  836. xsheetpath->AddAttribute( sNames, path->PathHumanReadable() );
  837. xsheetpath->AddAttribute( sTStamps, path->Path() );
  838. timeStamp.Printf( sTSFmt, comp->GetTimeStamp() );
  839. xcomp->AddChild( node( sTStamp, timeStamp ) );
  840. }
  841. }
  842. return xcomps;
  843. }
  844. bool NETLIST_EXPORT_TOOL::WriteKiCadNetList( const wxString& aOutFileName )
  845. {
  846. // Prepare list of nets generation
  847. for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
  848. m_masterList->GetItem( ii )->m_Flag = 0;
  849. std::auto_ptr<XNODE> xroot( makeGenericRoot() );
  850. try
  851. {
  852. FILE_OUTPUTFORMATTER formatter( aOutFileName );
  853. xroot->Format( &formatter, 0 );
  854. }
  855. catch( const IO_ERROR& ioe )
  856. {
  857. DisplayError( NULL, ioe.errorText );
  858. return false;
  859. }
  860. return true;
  861. }
  862. bool NETLIST_EXPORT_TOOL::WriteGENERICNetList( const wxString& aOutFileName )
  863. {
  864. // Prepare list of nets generation
  865. for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
  866. m_masterList->GetItem( ii )->m_Flag = 0;
  867. // output the XML format netlist.
  868. wxXmlDocument xdoc;
  869. xdoc.SetRoot( makeGenericRoot() );
  870. return xdoc.Save( aOutFileName, 2 /* indent bug, today was ignored by wxXml lib */ );
  871. }
  872. bool NETLIST_EXPORT_TOOL::WriteNetListPspice( FILE* f, bool aUsePrefix )
  873. {
  874. int ret = 0;
  875. int nbitems;
  876. wxString text;
  877. wxArrayString spiceCommandAtBeginFile;
  878. wxArrayString spiceCommandAtEndFile;
  879. wxString msg;
  880. wxString netName;
  881. #define BUFYPOS_LEN 4
  882. wxChar bufnum[BUFYPOS_LEN + 1];
  883. std::vector<int> pinSequence; // numeric indices into m_SortedComponentPinList
  884. wxArrayString stdPinNameArray; // Array containing Standard Pin Names
  885. wxString delimeters = wxT( "{:,; }" );
  886. wxString disableStr = wxT( "N" );
  887. ret |= fprintf( f, "* %s (Spice format) creation date: %s\n\n",
  888. NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) );
  889. // Prepare list of nets generation (not used here, but...
  890. for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
  891. m_masterList->GetItem( ii )->m_Flag = 0;
  892. ret |= fprintf( f, "* To exclude a component from the Spice Netlist add [Spice_Netlist_Enabled] user FIELD set to: N\n" );
  893. ret |= fprintf( f, "* To reorder the component spice node sequence add [Spice_Node_Sequence] user FIELD and define sequence: 2,1,0\n" );
  894. // Create text list starting by [.-]pspice , or [.-]gnucap (simulator
  895. // commands) and create text list starting by [+]pspice , or [+]gnucap
  896. // (simulator commands)
  897. bufnum[BUFYPOS_LEN] = 0;
  898. SCH_SHEET_LIST sheetList;
  899. for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
  900. {
  901. for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() )
  902. {
  903. wxChar ident;
  904. if( item->Type() != SCH_TEXT_T )
  905. continue;
  906. SCH_TEXT* drawText = (SCH_TEXT*) item;
  907. text = drawText->GetText();
  908. if( text.IsEmpty() )
  909. continue;
  910. ident = text.GetChar( 0 );
  911. if( ident != '.' && ident != '-' && ident != '+' )
  912. continue;
  913. text.Remove( 0, 1 ); // Remove the first char.
  914. text.Remove( 6 ); // text contains 6 char.
  915. text.MakeLower();
  916. if( ( text == wxT( "pspice" ) ) || ( text == wxT( "gnucap" ) ) )
  917. {
  918. // Put the Y position as an ascii string, for sort by vertical
  919. // position, using usual sort string by alphabetic value
  920. int ypos = drawText->GetPosition().y;
  921. for( int ii = 0; ii < BUFYPOS_LEN; ii++ )
  922. {
  923. bufnum[BUFYPOS_LEN - 1 - ii] = (ypos & 63) + ' ';
  924. ypos >>= 6;
  925. }
  926. text = drawText->GetText().AfterFirst( ' ' );
  927. // First BUFYPOS_LEN char are the Y position.
  928. msg.Printf( wxT( "%s %s" ), bufnum, text.GetData() );
  929. if( ident == '+' )
  930. spiceCommandAtEndFile.Add( msg );
  931. else
  932. spiceCommandAtBeginFile.Add( msg );
  933. }
  934. }
  935. }
  936. // Print texts starting by [.-]pspice , ou [.-]gnucap (of course, without
  937. // the Y position string)
  938. nbitems = spiceCommandAtBeginFile.GetCount();
  939. if( nbitems )
  940. {
  941. spiceCommandAtBeginFile.Sort();
  942. for( int ii = 0; ii < nbitems; ii++ )
  943. {
  944. spiceCommandAtBeginFile[ii].Remove( 0, BUFYPOS_LEN );
  945. spiceCommandAtBeginFile[ii].Trim( true );
  946. spiceCommandAtBeginFile[ii].Trim( false );
  947. ret |= fprintf( f, "%s\n", TO_UTF8( spiceCommandAtBeginFile[ii] ) );
  948. }
  949. }
  950. ret |= fprintf( f, "\n" );
  951. // Create component list
  952. m_ReferencesAlreadyFound.Clear();
  953. for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
  954. {
  955. ret |= fprintf( f, "*Sheet Name:%s\n", TO_UTF8( sheet->PathHumanReadable() ) );
  956. for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() )
  957. {
  958. SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, sheet );
  959. if( !comp )
  960. break;
  961. item = comp;
  962. // Reset NodeSeqIndex Count:
  963. pinSequence.clear();
  964. // Check to see if component should be removed from Spice Netlist:
  965. SCH_FIELD* netlistEnabledField = comp->FindField( wxT( "Spice_Netlist_Enabled" ) );
  966. if( netlistEnabledField )
  967. {
  968. wxString netlistEnabled = netlistEnabledField->GetText();
  969. if( netlistEnabled.IsEmpty() )
  970. break;
  971. if( netlistEnabled.CmpNoCase( disableStr ) == 0 )
  972. continue;
  973. }
  974. // Check if Alternative Pin Sequence is Available:
  975. SCH_FIELD* spiceSeqField = comp->FindField( wxT( "Spice_Node_Sequence" ) );
  976. if( spiceSeqField )
  977. {
  978. // Get String containing the Sequence of Nodes:
  979. wxString nodeSeqIndexLineStr = spiceSeqField->GetText();
  980. // Verify Field Exists and is not empty:
  981. if( nodeSeqIndexLineStr.IsEmpty() )
  982. break;
  983. // Create an Array of Standard Pin Names from part definition:
  984. stdPinNameArray.Clear();
  985. for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
  986. {
  987. NETLIST_OBJECT* pin = m_SortedComponentPinList[ii];
  988. if( !pin )
  989. continue;
  990. stdPinNameArray.Add( pin->GetPinNumText() );
  991. }
  992. // Get Alt Pin Name Array From User:
  993. wxStringTokenizer tkz( nodeSeqIndexLineStr, delimeters );
  994. while( tkz.HasMoreTokens() )
  995. {
  996. wxString pinIndex = tkz.GetNextToken();
  997. int seq;
  998. // Find PinName In Standard List assign Standard List Index to Name:
  999. seq = stdPinNameArray.Index(pinIndex);
  1000. if( seq != wxNOT_FOUND )
  1001. {
  1002. pinSequence.push_back( seq );
  1003. }
  1004. }
  1005. }
  1006. //Get Standard Reference Designator:
  1007. wxString RefName = comp->GetRef( sheet );
  1008. //Conditionally add Prefix only for devices that begin with U or IC:
  1009. if( aUsePrefix )
  1010. {
  1011. if( RefName.StartsWith( wxT( "U" ) ) || RefName.StartsWith( wxT( "IC" ) ) )
  1012. RefName = wxT( "X" ) + RefName;
  1013. }
  1014. ret |= fprintf( f, "%s ", TO_UTF8( RefName) );
  1015. // Write pin list:
  1016. int activePinIndex = 0;
  1017. for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
  1018. {
  1019. // Case of Alt Sequence definition with Unused/Invalid Node index:
  1020. // Valid used Node Indexes are in the set {0,1,2,...m_SortedComponentPinList.size()-1}
  1021. if( pinSequence.size() )
  1022. {
  1023. // All Vector values must be less <= max package size
  1024. // And Total Vector size should be <= package size
  1025. if( ( (unsigned) pinSequence[ii] < m_SortedComponentPinList.size() ) && ( ii < pinSequence.size() ) )
  1026. {
  1027. // Case of Alt Pin Sequence in control good Index:
  1028. activePinIndex = pinSequence[ii];
  1029. }
  1030. else
  1031. {
  1032. // Case of Alt Pin Sequence in control Bad Index or not using all pins for simulation:
  1033. continue;
  1034. }
  1035. }
  1036. // Case of Standard Pin Sequence in control:
  1037. else
  1038. {
  1039. activePinIndex = ii;
  1040. }
  1041. NETLIST_OBJECT* pin = m_SortedComponentPinList[activePinIndex];
  1042. if( !pin )
  1043. continue;
  1044. sprintPinNetName( netName , wxT( "N-%.6d" ), pin );
  1045. //Replace parenthesis with underscore to prevent parse issues with Simulators:
  1046. netName.Replace(wxT("("),wxT("_"));
  1047. netName.Replace(wxT(")"),wxT("_"));
  1048. if( netName.IsEmpty() )
  1049. netName = wxT( "?" );
  1050. ret |= fprintf( f, " %s", TO_UTF8( netName ) );
  1051. }
  1052. // Get Component Value Name:
  1053. wxString CompValue = comp->GetField( VALUE )->GetText();
  1054. // Check if Override Model Name is Provided:
  1055. SCH_FIELD* spiceModelField = comp->FindField( wxT( "spice_model" ) );
  1056. if( spiceModelField )
  1057. {
  1058. // Get Model Name String:
  1059. wxString ModelNameStr = spiceModelField->GetText();
  1060. // Verify Field Exists and is not empty:
  1061. if( !ModelNameStr.IsEmpty() )
  1062. CompValue = ModelNameStr;
  1063. }
  1064. // Print Component Value:
  1065. ret |= fprintf( f, " %s\t\t",TO_UTF8( CompValue ) );
  1066. // Show Seq Spec on same line as component using line-comment ";":
  1067. for( unsigned i = 0; i < pinSequence.size(); ++i )
  1068. {
  1069. if( i==0 )
  1070. ret |= fprintf( f, ";Node Sequence Spec.<" );
  1071. ret |= fprintf( f, "%s", TO_UTF8( stdPinNameArray.Item( pinSequence[i] ) ) );
  1072. if( i < pinSequence.size()-1 )
  1073. ret |= fprintf( f, "," );
  1074. else
  1075. ret |= fprintf( f, ">" );
  1076. }
  1077. // Next Netlist line record:
  1078. ret |= fprintf( f, "\n" );
  1079. }
  1080. }
  1081. m_SortedComponentPinList.clear();
  1082. // Print texts starting with [+]pspice or [+]gnucap
  1083. nbitems = spiceCommandAtEndFile.GetCount();
  1084. if( nbitems )
  1085. {
  1086. ret |= fprintf( f, "\n" );
  1087. spiceCommandAtEndFile.Sort();
  1088. for( int ii = 0; ii < nbitems; ii++ )
  1089. {
  1090. spiceCommandAtEndFile[ii].Remove( 0, +BUFYPOS_LEN );
  1091. spiceCommandAtEndFile[ii].Trim( true );
  1092. spiceCommandAtEndFile[ii].Trim( false );
  1093. ret |= fprintf( f, "%s\n", TO_UTF8( spiceCommandAtEndFile[ii] ) );
  1094. }
  1095. }
  1096. ret |= fprintf( f, "\n.end\n" );
  1097. return ret >= 0;
  1098. }
  1099. bool NETLIST_EXPORT_TOOL::WriteNetListPCBNEW( FILE* f, bool with_pcbnew )
  1100. {
  1101. wxString field;
  1102. wxString footprint;
  1103. int ret = 0; // zero now, OR in the sign bit on error
  1104. wxString netName;
  1105. std::vector< SCH_REFERENCE > cmpList;
  1106. if( with_pcbnew )
  1107. ret |= fprintf( f, "# %s created %s\n(\n",
  1108. NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) );
  1109. else
  1110. ret |= fprintf( f, "( { %s created %s }\n",
  1111. NETLIST_HEAD_STRING, TO_UTF8( DateAndTime() ) );
  1112. // Prepare list of nets generation
  1113. for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
  1114. m_masterList->GetItem( ii )->m_Flag = 0;
  1115. // Create netlist module section
  1116. m_ReferencesAlreadyFound.Clear();
  1117. SCH_SHEET_LIST sheetList;
  1118. for( SCH_SHEET_PATH* path = sheetList.GetFirst(); path; path = sheetList.GetNext() )
  1119. {
  1120. for( EDA_ITEM* item = path->LastDrawList(); item; item = item->Next() )
  1121. {
  1122. SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, path );
  1123. if( !comp )
  1124. break;
  1125. item = comp;
  1126. // Get the Component FootprintFilter and put the component in
  1127. // cmpList if filter is present
  1128. LIB_COMPONENT* entry = CMP_LIBRARY::FindLibraryComponent( comp->GetLibName() );
  1129. if( entry )
  1130. {
  1131. if( entry->GetFootPrints().GetCount() != 0 ) // Put in list
  1132. {
  1133. cmpList.push_back( SCH_REFERENCE( comp, entry, *path ) );
  1134. }
  1135. }
  1136. if( !comp->GetField( FOOTPRINT )->IsVoid() )
  1137. {
  1138. footprint = comp->GetField( FOOTPRINT )->GetText();
  1139. footprint.Replace( wxT( " " ), wxT( "_" ) );
  1140. }
  1141. else
  1142. footprint = wxT( "$noname" );
  1143. field = comp->GetRef( path );
  1144. ret |= fprintf( f, " ( %s %s",
  1145. TO_UTF8( comp->GetPath( path ) ),
  1146. TO_UTF8( footprint ) );
  1147. ret |= fprintf( f, " %s", TO_UTF8( field ) );
  1148. field = comp->GetField( VALUE )->GetText();
  1149. field.Replace( wxT( " " ), wxT( "_" ) );
  1150. ret |= fprintf( f, " %s", TO_UTF8( field ) );
  1151. if( with_pcbnew ) // Add the lib name for this component
  1152. {
  1153. field = comp->GetLibName();
  1154. field.Replace( wxT( " " ), wxT( "_" ) );
  1155. ret |= fprintf( f, " {Lib=%s}", TO_UTF8( field ) );
  1156. }
  1157. ret |= fprintf( f, "\n" );
  1158. // Write pin list:
  1159. for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
  1160. {
  1161. NETLIST_OBJECT* pin = m_SortedComponentPinList[ii];
  1162. if( !pin )
  1163. continue;
  1164. sprintPinNetName( netName, wxT( "N-%.6d" ), pin );
  1165. if( netName.IsEmpty() )
  1166. netName = wxT( "?" );
  1167. netName.Replace( wxT( " " ), wxT( "_" ) );
  1168. ret |= fprintf( f, " ( %4.4s %s )\n", (char*) &pin->m_PinNum,
  1169. TO_UTF8( netName ) );
  1170. }
  1171. ret |= fprintf( f, " )\n" );
  1172. }
  1173. }
  1174. ret |= fprintf( f, ")\n*\n" );
  1175. m_SortedComponentPinList.clear();
  1176. // Write the allowed footprint list for each component
  1177. if( with_pcbnew && cmpList.size() )
  1178. {
  1179. wxString ref;
  1180. ret |= fprintf( f, "{ Allowed footprints by component:\n" );
  1181. for( unsigned ii = 0; ii < cmpList.size(); ii++ )
  1182. {
  1183. LIB_COMPONENT* entry = cmpList[ii].GetLibComponent();
  1184. ref = cmpList[ii].GetRef();
  1185. ref.Replace( wxT( " " ), wxT( "_" ) );
  1186. ret |= fprintf( f, "$component %s\n", TO_UTF8( ref ) );
  1187. // Write the footprint list
  1188. for( unsigned jj = 0; jj < entry->GetFootPrints().GetCount(); jj++ )
  1189. {
  1190. ret |= fprintf( f, " %s\n", TO_UTF8( entry->GetFootPrints()[jj] ) );
  1191. }
  1192. ret |= fprintf( f, "$endlist\n" );
  1193. }
  1194. ret |= fprintf( f, "$endfootprintlist\n}\n" );
  1195. }
  1196. if( with_pcbnew )
  1197. {
  1198. ret |= fprintf( f, "{ Pin List by Nets\n" );
  1199. if( !writeGENERICListOfNets( f, *m_masterList ) )
  1200. ret = -1;
  1201. ret |= fprintf( f, "}\n" );
  1202. ret |= fprintf( f, "#End\n" );
  1203. }
  1204. return ret >= 0;
  1205. }
  1206. bool NETLIST_EXPORT_TOOL::addPinToComponentPinList( SCH_COMPONENT* aComponent,
  1207. SCH_SHEET_PATH* aSheetPath, LIB_PIN* aPin )
  1208. {
  1209. // Search the PIN description for Pin in g_NetObjectslist
  1210. for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
  1211. {
  1212. NETLIST_OBJECT* pin = m_masterList->GetItem( ii );
  1213. if( pin->m_Type != NET_PIN )
  1214. continue;
  1215. if( pin->m_Link != aComponent )
  1216. continue;
  1217. if( pin->m_PinNum != aPin->GetNumber() )
  1218. continue;
  1219. // most expensive test at the end.
  1220. if( pin->m_SheetPath != *aSheetPath )
  1221. continue;
  1222. m_SortedComponentPinList.push_back( pin );
  1223. if( m_SortedComponentPinList.size() >= MAXPIN )
  1224. {
  1225. // Log message for Internal error
  1226. DisplayError( NULL, wxT( "addPinToComponentPinList err: MAXPIN reached" ) );
  1227. }
  1228. return true; // we're done, we appended.
  1229. }
  1230. return false;
  1231. }
  1232. /*
  1233. * remove duplicate pins from aPinList (list of pins relative to a given component)
  1234. * (i.e. set pointer to duplicate pins to NULL in this list).
  1235. * also set .m_Flag member of "removed" NETLIST_OBJECT pins to 1
  1236. * When pins are duplicated, not connected duplicate is removed
  1237. * (for instance when a multiple part per package component has its power pins connected
  1238. * only on a part).
  1239. */
  1240. void NETLIST_EXPORT_TOOL::eraseDuplicatePins( )
  1241. {
  1242. for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
  1243. {
  1244. if( m_SortedComponentPinList[ii] == NULL ) /* already deleted */
  1245. continue;
  1246. /* Search for duplicated pins
  1247. * If found, remove duplicates. The priority is to keep connected pins
  1248. * and remove unconnected
  1249. * - So this allows (for instance when using multi op amps per package
  1250. * - to connect only one op amp to power
  1251. * Because the pin list is sorted by m_PinNum value, duplicated pins
  1252. * are necessary successive in list
  1253. */
  1254. int idxref = ii;
  1255. for( unsigned jj = ii + 1; jj < m_SortedComponentPinList.size(); jj++ )
  1256. {
  1257. if( m_SortedComponentPinList[jj] == NULL ) // Already removed
  1258. continue;
  1259. // if other pin num, stop search,
  1260. // because all pins having the same number are consecutive in list.
  1261. if( m_SortedComponentPinList[idxref]->m_PinNum != m_SortedComponentPinList[jj]->m_PinNum )
  1262. break;
  1263. if( m_SortedComponentPinList[idxref]->GetConnectionType() == PAD_CONNECT )
  1264. {
  1265. m_SortedComponentPinList[jj]->m_Flag = 1;
  1266. m_SortedComponentPinList[jj] = NULL;
  1267. }
  1268. else /* the reference pin is not connected: remove this pin if the
  1269. * other pin is connected */
  1270. {
  1271. if( m_SortedComponentPinList[jj]->GetConnectionType() == PAD_CONNECT )
  1272. {
  1273. m_SortedComponentPinList[idxref]->m_Flag = 1;
  1274. m_SortedComponentPinList[idxref] = NULL;
  1275. idxref = jj;
  1276. }
  1277. else // the 2 pins are not connected: remove the tested pin,
  1278. { // and continue ...
  1279. m_SortedComponentPinList[jj]->m_Flag = 1;
  1280. m_SortedComponentPinList[jj] = NULL;
  1281. }
  1282. }
  1283. }
  1284. }
  1285. }
  1286. void NETLIST_EXPORT_TOOL::findAllInstancesOfComponent( SCH_COMPONENT* aComponent,
  1287. LIB_COMPONENT* aEntry,
  1288. SCH_SHEET_PATH* aSheetPath )
  1289. {
  1290. wxString ref = aComponent->GetRef( aSheetPath );
  1291. wxString ref2;
  1292. SCH_SHEET_LIST sheetList;
  1293. for( SCH_SHEET_PATH* sheet = sheetList.GetFirst(); sheet; sheet = sheetList.GetNext() )
  1294. {
  1295. for( EDA_ITEM* item = sheet->LastDrawList(); item; item = item->Next() )
  1296. {
  1297. if( item->Type() != SCH_COMPONENT_T )
  1298. continue;
  1299. SCH_COMPONENT* comp2 = (SCH_COMPONENT*) item;
  1300. ref2 = comp2->GetRef( sheet );
  1301. if( ref2.CmpNoCase( ref ) != 0 )
  1302. continue;
  1303. int unit2 = comp2->GetUnitSelection( sheet ); // slow
  1304. for( LIB_PIN* pin = aEntry->GetNextPin(); pin; pin = aEntry->GetNextPin( pin ) )
  1305. {
  1306. wxASSERT( pin->Type() == LIB_PIN_T );
  1307. if( pin->GetUnit() && pin->GetUnit() != unit2 )
  1308. continue;
  1309. if( pin->GetConvert() && pin->GetConvert() != comp2->GetConvert() )
  1310. continue;
  1311. // A suitable pin is found: add it to the current list
  1312. addPinToComponentPinList( comp2, sheet, pin );
  1313. }
  1314. }
  1315. }
  1316. }
  1317. bool NETLIST_EXPORT_TOOL::writeGENERICListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList )
  1318. {
  1319. int ret = 0;
  1320. int netCode;
  1321. int lastNetCode = -1;
  1322. int sameNetcodeCount = 0;
  1323. wxString netName;
  1324. wxString ref;
  1325. wxString netcodeName;
  1326. char firstItemInNet[256];
  1327. for( unsigned ii = 0; ii < aObjectsList.size(); ii++ )
  1328. {
  1329. SCH_COMPONENT* comp;
  1330. NETLIST_OBJECT* nitem = aObjectsList[ii];
  1331. // New net found, write net id;
  1332. if( ( netCode = nitem->GetNet() ) != lastNetCode )
  1333. {
  1334. sameNetcodeCount = 0; // Items count for this net
  1335. netName = nitem->GetNetName();
  1336. netcodeName.Printf( wxT( "Net %d " ), netCode );
  1337. netcodeName << wxT( "\"" ) << netName << wxT( "\"" );
  1338. // Add the netname without prefix, in cases we need only the
  1339. // "short" netname
  1340. netcodeName += wxT( " \"" ) + nitem->GetShortNetName() + wxT( "\"" );
  1341. lastNetCode = netCode;
  1342. }
  1343. if( nitem->m_Type != NET_PIN )
  1344. continue;
  1345. if( nitem->m_Flag != 0 ) // Redundant pin, skip it
  1346. continue;
  1347. comp = nitem->GetComponentParent();
  1348. // Get the reference for the net name and the main parent component
  1349. ref = comp->GetRef( &nitem->m_SheetPath );
  1350. if( ref[0] == wxChar( '#' ) )
  1351. continue; // Pseudo component (Like Power symbol)
  1352. // Print the pin list for this net, use special handling if
  1353. // 2 or more items are connected:
  1354. // if first item for this net found, defer printing this connection
  1355. // until a second item will is found
  1356. if( ++sameNetcodeCount == 1 )
  1357. {
  1358. snprintf( firstItemInNet, sizeof(firstItemInNet), " %s %.4s\n",
  1359. TO_UTF8( ref ),
  1360. (const char*) &aObjectsList[ii]->m_PinNum );
  1361. }
  1362. // Second item for this net found, print the Net name, and the
  1363. // first item
  1364. if( sameNetcodeCount == 2 )
  1365. {
  1366. ret |= fprintf( f, "%s\n", TO_UTF8( netcodeName ) );
  1367. ret |= fputs( firstItemInNet, f );
  1368. }
  1369. if( sameNetcodeCount >= 2 )
  1370. ret |= fprintf( f, " %s %.4s\n", TO_UTF8( ref ),
  1371. (const char*) &nitem->m_PinNum );
  1372. }
  1373. return ret >= 0;
  1374. }
  1375. /* Generate CADSTAR net list. */
  1376. static wxString StartLine( wxT( "." ) );
  1377. bool NETLIST_EXPORT_TOOL::WriteNetListCADSTAR( FILE* f )
  1378. {
  1379. int ret = 0;
  1380. wxString StartCmpDesc = StartLine + wxT( "ADD_COM" );
  1381. wxString msg;
  1382. wxString footprint;
  1383. SCH_SHEET_PATH* sheet;
  1384. EDA_ITEM* DrawList;
  1385. SCH_COMPONENT* component;
  1386. wxString title = wxT( "Eeschema " ) + GetBuildVersion();
  1387. ret |= fprintf( f, "%sHEA\n", TO_UTF8( StartLine ) );
  1388. ret |= fprintf( f, "%sTIM %s\n", TO_UTF8( StartLine ), TO_UTF8( DateAndTime() ) );
  1389. ret |= fprintf( f, "%sAPP ", TO_UTF8( StartLine ) );
  1390. ret |= fprintf( f, "\"%s\"\n", TO_UTF8( title ) );
  1391. ret |= fprintf( f, "\n" );
  1392. // Prepare list of nets generation
  1393. for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
  1394. m_masterList->GetItem( ii )->m_Flag = 0;
  1395. // Create netlist module section
  1396. m_ReferencesAlreadyFound.Clear();
  1397. SCH_SHEET_LIST SheetList;
  1398. for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() )
  1399. {
  1400. for( DrawList = sheet->LastDrawList(); DrawList != NULL; DrawList = DrawList->Next() )
  1401. {
  1402. DrawList = component = findNextComponentAndCreatePinList( DrawList, sheet );
  1403. if( component == NULL )
  1404. break;
  1405. /*
  1406. doing nothing with footprint
  1407. if( !component->GetField( FOOTPRINT )->IsVoid() )
  1408. {
  1409. footprint = component->GetField( FOOTPRINT )->m_Text;
  1410. footprint.Replace( wxT( " " ), wxT( "_" ) );
  1411. }
  1412. else
  1413. footprint = wxT( "$noname" );
  1414. */
  1415. msg = component->GetRef( sheet );
  1416. ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) );
  1417. ret |= fprintf( f, "%s", TO_UTF8( msg ) );
  1418. msg = component->GetField( VALUE )->GetText();
  1419. msg.Replace( wxT( " " ), wxT( "_" ) );
  1420. ret |= fprintf( f, " \"%s\"", TO_UTF8( msg ) );
  1421. ret |= fprintf( f, "\n" );
  1422. }
  1423. }
  1424. ret |= fprintf( f, "\n" );
  1425. m_SortedComponentPinList.clear();
  1426. if( ! writeListOfNetsCADSTAR( f ) )
  1427. ret = -1; // set error
  1428. ret |= fprintf( f, "\n%sEND\n", TO_UTF8( StartLine ) );
  1429. return ret >= 0;
  1430. }
  1431. bool NETLIST_EXPORT_TOOL::writeListOfNetsCADSTAR( FILE* f )
  1432. {
  1433. int ret = 0;
  1434. wxString InitNetDesc = StartLine + wxT( "ADD_TER" );
  1435. wxString StartNetDesc = StartLine + wxT( "TER" );
  1436. wxString netcodeName, InitNetDescLine;
  1437. unsigned ii;
  1438. int print_ter = 0;
  1439. int NetCode, lastNetCode = -1;
  1440. SCH_COMPONENT* Cmp;
  1441. wxString netName;
  1442. for( ii = 0; ii < m_masterList->size(); ii++ )
  1443. {
  1444. NETLIST_OBJECT* nitem = m_masterList->GetItem( ii );
  1445. // Get the NetName of the current net :
  1446. if( ( NetCode = nitem->GetNet() ) != lastNetCode )
  1447. {
  1448. netName = nitem->GetNetName();
  1449. netcodeName = wxT( "\"" );
  1450. if( !netName.IsEmpty() )
  1451. netcodeName << netName;
  1452. else // this net has no name: create a default name $<net number>
  1453. netcodeName << wxT( "$" ) << NetCode;
  1454. netcodeName += wxT( "\"" );
  1455. lastNetCode = NetCode;
  1456. print_ter = 0;
  1457. }
  1458. if( nitem->m_Type != NET_PIN )
  1459. continue;
  1460. if( nitem->m_Flag != 0 )
  1461. continue;
  1462. Cmp = nitem->GetComponentParent();
  1463. wxString refstr = Cmp->GetRef( &nitem->m_SheetPath );
  1464. if( refstr[0] == '#' )
  1465. continue; // Power supply symbols.
  1466. switch( print_ter )
  1467. {
  1468. case 0:
  1469. {
  1470. char buf[5];
  1471. wxString str_pinnum;
  1472. strncpy( buf, (char*) &nitem->m_PinNum, 4 );
  1473. buf[4] = 0;
  1474. str_pinnum = FROM_UTF8( buf );
  1475. InitNetDescLine.Printf( wxT( "\n%s %s %.4s %s" ),
  1476. GetChars( InitNetDesc ),
  1477. GetChars( refstr ),
  1478. GetChars( str_pinnum ),
  1479. GetChars( netcodeName ) );
  1480. }
  1481. print_ter++;
  1482. break;
  1483. case 1:
  1484. ret |= fprintf( f, "%s\n", TO_UTF8( InitNetDescLine ) );
  1485. ret |= fprintf( f, "%s %s %.4s\n",
  1486. TO_UTF8( StartNetDesc ),
  1487. TO_UTF8( refstr ),
  1488. (char*) &nitem->m_PinNum );
  1489. print_ter++;
  1490. break;
  1491. default:
  1492. ret |= fprintf( f, " %s %.4s\n",
  1493. TO_UTF8( refstr ),
  1494. (char*) &nitem->m_PinNum );
  1495. break;
  1496. }
  1497. nitem->m_Flag = 1;
  1498. }
  1499. return ret >= 0;
  1500. }