Commit 54deeadd authored by Clownce Deng's avatar Clownce Deng

chore: add first

parent 0153fbf3
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
*.pyd
# Binaries
# --------
*.lib
*.dll
*.exe
# TopLinker
# ----------------------------------------------------------------------------
**/dist/
**/build/
!src/lib/*.qm
# SINCPM
sincpm-lock.json
# qdoc
qdoc/html/
*.qch
doc.tags
\ No newline at end of file
cmake_minimum_required(VERSION 3.1)
cmake_policy(VERSION 3.1)
cmake_minimum_required(VERSION 3.16)
cmake_policy(VERSION 3.16)
# Enable policy to not use RPATH settings for install_name on macOS.
if(POLICY CMP0068)
......@@ -15,12 +15,17 @@ endif()
project(pcbcam LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
find_package(Qt5 5.12 REQUIRED COMPONENTS Core Gui Widgets)
# find_package(Qt6 6.2.1 REQUIRED COMPONENTS Core Gui Widgets Qml)
find_package(Qt6 COMPONENTS Core REQUIRED)
find_package(Qt6 COMPONENTS Gui REQUIRED)
find_package(Qt6 COMPONENTS Widgets REQUIRED)
find_package(Qt6 COMPONENTS Qml REQUIRED)
find_package(Qt6 COMPONENTS Network REQUIRED)
# ================================ General configuration ======================================
# Set CPP standard to C++11 minimum.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
# The library for which we will create bindings. You can change the name to something
# relevant for your project.
......@@ -41,64 +46,72 @@ set(typesystem_file ${CMAKE_SOURCE_DIR}/bindings.xml)
# Specify which C++ files will be generated by shiboken. This includes the module wrapper
# and a '.cpp' file per C++ type. These are needed for generating the module shared
# library.
set(name_space "")
set(generated_sources
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcam_module_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamabstractdataio_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamattrdefine_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcam_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcam_attrcompareinfo_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcam_featureselectionfilter_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamconfig_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamcore_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamfeature_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamfeatureline_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamfeaturepad_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamfeaturearc_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamfeaturetext_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamfeaturebarcode_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamfeaturesurface_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamfont_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamfontcharline_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamjob_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamlayer_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcammath_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcammatrixlayer_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamstep_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsteprepeat_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbol_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolr_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbols_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolrect_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolrectr_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolrectc_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymboloval_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymboldi_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymboloct_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymboldonutr_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymboldonuts_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolhexl_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolhexs_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolbfr_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolbfs_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymboltri_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolovalh_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolthr_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolths_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolsths_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolstho_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolsrths_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolrcths_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolrctho_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolel_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolmoire_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymboluser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamsymbolfactory_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamutil_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamodbfeatureparser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamodbmatrixparser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamparserhelper_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcamcanvas_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pcbcampopviewwindow_wrapper.cpp)
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamabstractdataio_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamattrdefine_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcam_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcam_featureselectionfilter_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcam_attrcompareinfo_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamconfig_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamcore_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfeature_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfeatureline_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfeaturepad_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfeaturearc_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfeaturetext_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfeaturebarcode_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfeaturesurface_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfeaturepath_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfeaturecomponent_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfont_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamfontcharline_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamjob_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamlayer_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcammath_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcammatrixlayer_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamstep_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsteprepeat_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbol_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolr_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbols_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolrect_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolrectr_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolrectc_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymboloval_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymboldi_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymboloct_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymboldonutr_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymboldonuts_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolhexl_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolhexs_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolbfr_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolbfs_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymboltri_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolovalh_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolthr_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolths_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolsths_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolstho_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolsrths_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolrcths_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolrctho_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolel_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolmoire_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymboluser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamsymbolfactory_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamutil_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamdrillparser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamgerber274xparser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamodbcomponentparser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamodbedadataparser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamodbfeatureinfo_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamodbfeatureparser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamodbmatrixparser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamparserhelper_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcamcanvas_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${name_space}pcbcampopviewwindow_wrapper.cpp)
# ================================== Shiboken detection ======================================
......@@ -109,8 +122,8 @@ endif()
message(STATUS "Using python interpreter: ${python_interpreter}")
# Macro to get various pyside / python include / link flags and paths.
# Uses the not entirely supported utils/pyside2_config.py file.
macro(pyside2_config option output_var)
# Uses the not entirely supported utils/pyside_config.py file.
macro(pyside_config option output_var)
if(${ARGC} GREATER 2)
set(is_list ${ARGV2})
else()
......@@ -118,13 +131,13 @@ macro(pyside2_config option output_var)
endif()
execute_process(
COMMAND ${python_interpreter} "${CMAKE_SOURCE_DIR}/pyside2_config.py"
COMMAND ${python_interpreter} "${CMAKE_SOURCE_DIR}/pyside_config.py"
${option}
OUTPUT_VARIABLE ${output_var}
OUTPUT_STRIP_TRAILING_WHITESPACE)
if ("${${output_var}}" STREQUAL "")
message(FATAL_ERROR "Error: Calling pyside2_config.py ${option} returned no output.")
message(FATAL_ERROR "Error: Calling pyside_config.py ${option} returned no output.")
endif()
if(is_list)
string (REPLACE " " ";" ${output_var} "${${output_var}}")
......@@ -132,17 +145,17 @@ macro(pyside2_config option output_var)
endmacro()
# Query for the shiboken generator path, Python path, include paths and linker flags.
pyside2_config(--shiboken2-module-path shiboken2_module_path)
pyside2_config(--shiboken2-generator-path shiboken2_generator_path)
pyside2_config(--pyside2-path pyside2_path)
pyside2_config(--pyside2-include-path pyside2_include_dir 1)
pyside2_config(--python-include-path python_include_dir)
pyside2_config(--shiboken2-generator-include-path shiboken_include_dir 1)
pyside2_config(--shiboken2-module-shared-libraries-cmake shiboken_shared_libraries 0)
pyside2_config(--python-link-flags-cmake python_linking_data 0)
pyside2_config(--pyside2-shared-libraries-cmake pyside2_shared_libraries 0)
set(shiboken_path "${shiboken2_generator_path}/shiboken2${CMAKE_EXECUTABLE_SUFFIX}")
pyside_config(--shiboken-module-path shiboken_module_path)
pyside_config(--shiboken-generator-path shiboken_generator_path)
pyside_config(--pyside-path pyside_path)
pyside_config(--pyside-include-path pyside_include_dir 1)
pyside_config(--python-include-path python_include_dir)
pyside_config(--shiboken-generator-include-path shiboken_include_dir 1)
pyside_config(--shiboken-module-shared-libraries-cmake shiboken_shared_libraries 0)
pyside_config(--python-link-flags-cmake python_linking_data 0)
pyside_config(--pyside-shared-libraries-cmake pyside_shared_libraries 0)
set(shiboken_path "${shiboken_generator_path}/shiboken6${CMAKE_EXECUTABLE_SUFFIX}")
if(NOT EXISTS ${shiboken_path})
message(FATAL_ERROR "Shiboken executable not found at path: ${shiboken_path}")
endif()
......@@ -158,7 +171,7 @@ endif()
# Enable rpaths so that the built shared libraries find their dependencies.
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH ${shiboken2_module_path} ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_INSTALL_RPATH ${shiboken_module_path} ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# =============================================================================================
# !!! End of dubious section.
......@@ -169,34 +182,38 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Get all relevant Qt include dirs, to pass them on to shiboken.
get_property(QT_CORE_INCLUDE_DIRS TARGET Qt5::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(QT_GUI_INCLUDE_DIRS TARGET Qt5::Gui PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(QT_WIDGETS_INCLUDE_DIRS TARGET Qt5::Widgets PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
set(QT_INCLUDE_DIRS ${QT_CORE_INCLUDE_DIRS} ${QT_GUI_INCLUDE_DIRS} ${QT_WIDGETS_INCLUDE_DIRS})
get_property(QT_CORE_INCLUDE_DIRS TARGET Qt6::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(QT_GUI_INCLUDE_DIRS TARGET Qt6::Gui PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(QT_WIDGETS_INCLUDE_DIRS TARGET Qt6::Widgets PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(QT_QML_INCLUDE_DIRS TARGET Qt6::Qml PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(QT_NETWORK_INCLUDE_DIRS TARGET Qt6::Network PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
set(QT_INCLUDE_DIRS ${QT_CORE_INCLUDE_DIRS} ${QT_GUI_INCLUDE_DIRS} ${QT_WIDGETS_INCLUDE_DIRS} ${QT_QML_INCLUDE_DIRS} ${QT_NETWORK_INCLUDE_DIRS})
set(INCLUDES "")
foreach(INCLUDE_DIR ${QT_INCLUDE_DIRS})
list(APPEND INCLUDES "-I${INCLUDE_DIR}")
endforeach()
# On macOS, check if Qt is a framework build. This affects how include paths should be handled.
get_target_property(QtCore_is_framework Qt5::Core FRAMEWORK)
get_target_property(QtCore_is_framework Qt6::Core FRAMEWORK)
if (QtCore_is_framework)
get_target_property(qt_core_library_location Qt5::Core LOCATION)
get_target_property(qt_core_library_location Qt6::Core LOCATION)
get_filename_component(qt_core_library_location_dir "${qt_core_library_location}" DIRECTORY)
get_filename_component(lib_dir "${qt_core_library_location_dir}/../" ABSOLUTE)
list(APPEND INCLUDES "--framework-include-paths=${lib_dir}")
endif()
# We need to include the headers for the module bindings that we use.
set(pyside2_additional_includes "")
foreach(INCLUDE_DIR ${pyside2_include_dir})
list(APPEND pyside2_additional_includes "${INCLUDE_DIR}/QtCore")
list(APPEND pyside2_additional_includes "${INCLUDE_DIR}/QtGui")
list(APPEND pyside2_additional_includes "${INCLUDE_DIR}/QtWidgets")
set(pyside_additional_includes "")
foreach(INCLUDE_DIR ${pyside_include_dir})
list(APPEND pyside_additional_includes "${INCLUDE_DIR}/QtCore")
list(APPEND pyside_additional_includes "${INCLUDE_DIR}/QtGui")
list(APPEND pyside_additional_includes "${INCLUDE_DIR}/QtWidgets")
list(APPEND pyside_additional_includes "${INCLUDE_DIR}/QtQml")
list(APPEND pyside_additional_includes "${INCLUDE_DIR}/QtNetwork")
endforeach()
# Define the wiggly shared library for which we will create bindings.
# Define the shared library for which we will create bindings.
set(${project_library}_sources
lib/core/abstractdataio.h
lib/core/attrdefine.cpp
......@@ -215,6 +232,10 @@ set(${project_library}_sources
lib/core/symbol.cpp
lib/core/symbolfactory.cpp
lib/core/util.cpp
lib/parser/drillparser.cpp
lib/parser/gerber274xparser.cpp
lib/parser/odbcomponentparser.cpp
lib/parser/odbedadataparser.cpp
lib/parser/odbfeatureparser.cpp
lib/parser/odbmatrixparser.cpp
lib/parser/parserhelper.cpp
......@@ -224,7 +245,7 @@ add_library(${project_library} SHARED ${${project_library}_sources})
set_property(TARGET ${project_library} PROPERTY PREFIX "")
# Needed mostly on Windows to export symbols, and create a .lib file, otherwise the binding
# library can't link to the wiggly library.
# library can't link to the pcbcam library.
target_compile_definitions(${project_library} PRIVATE BINDINGS_BUILD)
......@@ -238,7 +259,7 @@ set(shiboken_options --generator-set=shiboken --enable-parent-ctor-heuristic
${INCLUDES}
-I${CMAKE_SOURCE_DIR}
-T${CMAKE_SOURCE_DIR}
-T${pyside2_path}/typesystems
-T${pyside_path}/typesystems
--output-directory=${CMAKE_CURRENT_BINARY_DIR}
)
......@@ -265,15 +286,23 @@ add_library(${bindings_library} SHARED ${${bindings_library}_sources})
# Apply relevant include and link flags.
target_include_directories(${bindings_library} PRIVATE ${pyside2_additional_includes})
target_include_directories(${bindings_library} PRIVATE ${pyside2_include_dir})
target_include_directories(${bindings_library} PRIVATE ${pyside_additional_includes})
target_include_directories(${bindings_library} PRIVATE ${pyside_include_dir})
target_include_directories(${bindings_library} PRIVATE ${python_include_dir})
target_include_directories(${bindings_library} PRIVATE ${shiboken_include_dir})
target_link_libraries(${project_library} PRIVATE Qt5::Widgets)
target_link_libraries(${bindings_library} PRIVATE Qt5::Widgets)
target_link_libraries(${project_library} PRIVATE Qt6::Core)
target_link_libraries(${bindings_library} PRIVATE Qt6::Core)
target_link_libraries(${project_library} PRIVATE Qt6::Gui)
target_link_libraries(${bindings_library} PRIVATE Qt6::Gui)
target_link_libraries(${project_library} PRIVATE Qt6::Widgets)
target_link_libraries(${bindings_library} PRIVATE Qt6::Widgets)
target_link_libraries(${project_library} PRIVATE Qt6::Qml)
target_link_libraries(${bindings_library} PRIVATE Qt6::Qml)
target_link_libraries(${project_library} PRIVATE Qt6::Network)
target_link_libraries(${bindings_library} PRIVATE Qt6::Network)
target_link_libraries(${bindings_library} PRIVATE ${project_library})
target_link_libraries(${bindings_library} PRIVATE ${pyside2_shared_libraries})
target_link_libraries(${bindings_library} PRIVATE ${pyside_shared_libraries})
target_link_libraries(${bindings_library} PRIVATE ${shiboken_shared_libraries})
# Adjust the name of generated module.
......@@ -312,7 +341,7 @@ if(WIN32)
# Circumvent some "#pragma comment(lib)"s in "include/pyconfig.h" which might force to link
# against a wrong python shared library.
set(python_versions_list 3 32 33 34 35 36 37 38)
set(python_versions_list 3 36 37 38 39)
set(python_additional_link_flags "")
foreach(ver ${python_versions_list})
set(python_additional_link_flags
......@@ -325,7 +354,7 @@ if(WIN32)
PROPERTIES LINK_FLAGS "${python_additional_link_flags}")
# Compile a list of shiboken shared libraries to be installed, so that
# the user doesn't have to set the PATH manually to point to the PySide2 package.
# the user doesn't have to set the PATH manually to point to the PySide package.
foreach(library_path ${shiboken_shared_libraries})
string(REGEX REPLACE ".lib$" ".dll" library_path ${library_path})
file(TO_CMAKE_PATH ${library_path} library_path)
......
......@@ -17,6 +17,10 @@
#include "lib/core/symbol.h"
#include "lib/core/symbolfactory.h"
#include "lib/core/util.h"
#include "lib/parser/drillparser.h"
#include "lib/parser/gerber274xparser.h"
#include "lib/parser/odbcomponentparser.h"
#include "lib/parser/odbedadataparser.h"
#include "lib/parser/odbfeatureparser.h"
#include "lib/parser/odbmatrixparser.h"
#include "lib/parser/parserhelper.h"
......
......@@ -4,6 +4,10 @@
<load-typesystem name="typesystem_core.xml" generate="no"/>
<load-typesystem name="typesystem_gui.xml" generate="no"/>
<load-typesystem name="typesystem_widgets.xml" generate="no"/>
<load-typesystem name="typesystem_qml.xml" generate="no"/>
<load-typesystem name="typesystem_network.xml" generate="no"/>
<!-- <namespace-type name="titan"> -->
<!--abstractdataio-->
<object-type name="PcbCamAbstractDataIo"/>
......@@ -27,6 +31,8 @@
<enum-type name="FeatureSelectionOperation"/>
<enum-type name="FeatureSelectionMode"/>
<enum-type name="UnitsType"/>
<enum-type name="ZerosOmit"/>
<enum-type name="CoordNotation"/>
<enum-type name="LogicOperator"/>
<enum-type name="SnapMode" flags="SnapModes"/>
<enum-type name="DisplayOption" flags="DisplayOptions"/>
......@@ -35,7 +41,6 @@
<object-type name="AttrCompareInfo"/>
</object-type>
<!--config-->
<object-type name="PcbCamConfig"/>
......@@ -50,6 +55,8 @@
<object-type name="PcbCamFeatureText"/>
<object-type name="PcbCamFeatureBarcode"/>
<object-type name="PcbCamFeatureSurface"/>
<object-type name="PcbCamFeaturePath"/>
<object-type name="PcbCamFeatureComponent"/>
<!--font-->
<object-type name="PcbCamFont"/>
......@@ -110,11 +117,32 @@
<object-type name="PcbCamSymbolFactory"/>
<!--util-->
<rejection class="PcbCamUtil" function-name="point2segDist"/>
<rejection class="PcbCamUtil" function-name="point2polylineDist"/>
<!-- <rejection class="PcbCamUtil" function-name="point2segDist"/> -->
<!-- <rejection class="PcbCamUtil" function-name="point2polylineDist"/> -->
<object-type name="PcbCamUtil"/>
<!-- <rejection class="*" function-name="calcPathArc"/> -->
<!--drillparser-->
<object-type name="PcbCamDrillParser">
<enum-type name="DrillFormat"/>
<!-- <object-type name="DrillStatement"/> -->
</object-type>
<!--gerber274xparser-->
<object-type name="PcbCamGerber274XParser">
<enum-type name="Cmd"/>
<!-- <object-type name="ApertureInfo"/> -->
</object-type>
<!--odbcomponentparser-->
<object-type name="PcbCamOdbComponentParser"/>
<!--odbedadataparser-->
<object-type name="PcbCamOdbEdaDataParser"/>
<!--odbfeatureparser-->
<object-type name="PcbCamOdbFeatureInfo"/>
<object-type name="PcbCamOdbFeatureParser"/>
<!--odbmatrixparser-->
......@@ -131,4 +159,5 @@
<!--popviewwindow-->
<object-type name="PcbCamPopViewWindow"/>
<!-- </namespace-type> -->
</typesystem>
\ No newline at end of file
from PySide6.QtWidgets import QDialog, QLineEdit, QVBoxLayout
# Python binding from the C++ widget
from timp.foo import FooWidget as FooWidgetCPP
class Dialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
wiggly_widget_cpp = FooWidgetCPP(self)
lineEdit = QLineEdit(self)
layout = QVBoxLayout(self)
layout.addWidget(wiggly_widget_cpp)
layout.addWidget(lineEdit)
wiggly_widget_cpp.setRunning(True)
lineEdit.textChanged.connect(wiggly_widget_cpp.setText)
lineEdit.setText("Hello world!")
self.setWindowTitle("Wiggly")
self.resize(360, 145)
import sys
from PySide6.QtWidgets import QApplication
from pcbcam import PcbCamCanvas
from pcbcam import PcbCamUtil as UT
if __name__ == "__main__":
app = QApplication()
# w = PcbCamCanvas()
# w.show()
a = UT.formatNumber(12.135456789, 2)
print(a)
print(int(PcbCamCanvas.PanViewMode))
sys.exit(0)
# sys.exit(app.exec())
......@@ -3,7 +3,6 @@
#include "../titanpcbcamglobal.h"
#include <QObject>
TITAN_BEGIN_NAMESPACE
class TITAN_PCBCAM_EXPORT PcbCamAbstractDataIo : public QObject
{
......@@ -14,10 +13,9 @@ public:
virtual void clearJobDataCache(const QString &/*iJobPath*/) {}
virtual QVariantList getDbList() = 0;
virtual QVariantList getJobList(const QString &iDb = "") = 0;
virtual QByteArray readJobData(const QString &iJobPath, const QString &iRealtivePath, QString *oError = nullptr) = 0;
virtual bool writeJobData(const QString &iJobPath, const QString &iRealtivePath, const QByteArray &iData, const QString *oError = nullptr) = 0;
virtual QByteArray readJobData(const QString &iJobPath, const QString &iRealtivePath) = 0;
virtual bool writeJobData(const QString &iJobPath, const QString &iRealtivePath, const QByteArray &iData) = 0;
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_ABSTRACTDATAIO_H
#include "arcpainterinfo.h"
#include <QtMath>
#include <QDebug>
TITAN_BEGIN_NAMESPACE
class PcbCamArcPainterInfoData : public QSharedData
{
public:
PcbCamArcPainterInfoData() { }
PcbCamArcPainterInfoData(const PcbCamArcPainterInfoData &other): QSharedData(other){ }
~PcbCamArcPainterInfoData() { }
QRectF rect;
qreal startAngle {0.0};
qreal spanAngle {0.0};
};
PcbCamArcPainterInfo::PcbCamArcPainterInfo(qreal xs, qreal ys, qreal xe, qreal ye, qreal xc, qreal yc, bool cw) : d(new PcbCamArcPainterInfoData)
{
qreal sax = xs - xc, say = ys - yc;
qreal eax = xe - xc, eay = ye - yc;
qreal r = qSqrt(sax * sax + say * say);
qreal sa = qAtan2(-say, sax);
qreal ea = qAtan2(-eay, eax);
if (cw) {
if (ea <= sa) {
ea += 2.0 * M_PI;
}
}
else {
if (sa <= ea) {
sa += 2.0 * M_PI;
}
}
d->rect = QRectF(xc - r, yc - r, r * 2.0, r * 2.0);
d->startAngle = sa * (180.0 / M_PI) *16;
d->spanAngle = (ea - sa) * (180.0 / M_PI) * 16;
}
PcbCamArcPainterInfo::PcbCamArcPainterInfo(const PcbCamArcPainterInfo &rhs) : d(rhs.d)
{
}
PcbCamArcPainterInfo &PcbCamArcPainterInfo::operator=(const PcbCamArcPainterInfo &rhs)
{
if (this != &rhs)
d.operator=(rhs.d);
return *this;
}
PcbCamArcPainterInfo::~PcbCamArcPainterInfo()
{
}
QRectF PcbCamArcPainterInfo::rect() const
{
return d->rect;
}
qreal PcbCamArcPainterInfo::startAngle() const
{
return d->startAngle;
}
qreal PcbCamArcPainterInfo::spanAngle() const
{
return d->spanAngle;
}
TITAN_END_NAMESPACE
#ifndef TITAN_PCBCAM_ARCPAINTERINFO_H
#define TITAN_PCBCAM_ARCPAINTERINFO_H
#include "titanpcbcamglobal.h"
#include <QSharedDataPointer>
#include <QRectF>
TITAN_BEGIN_NAMESPACE
class PcbCamArcPainterInfoData;
class TITAN_PCBCAM_EXPORT PcbCamArcPainterInfo
{
public:
PcbCamArcPainterInfo(qreal xs, qreal ys, qreal xe, qreal ye, qreal xc, qreal yc, bool cw);
PcbCamArcPainterInfo(const PcbCamArcPainterInfo &);
PcbCamArcPainterInfo &operator=(const PcbCamArcPainterInfo &);
~PcbCamArcPainterInfo();
QRectF rect() const;
qreal startAngle() const;
qreal spanAngle() const;
private:
QSharedDataPointer<PcbCamArcPainterInfoData> d;
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_ARCPAINTERINFO_H
#include "attrdefine.h"
TITAN_BEGIN_NAMESPACE
class PcbCamAttrDefineData : public QSharedData
{
public:
......@@ -244,5 +242,3 @@ PcbCamAttrDefine::Entity PcbCamAttrDefine::entityFromString(const QString &iStr)
return entity;
}
TITAN_END_NAMESPACE
......@@ -5,7 +5,6 @@
#include <QStringList>
#include <QVariant>
TITAN_BEGIN_NAMESPACE
class PcbCamAttrDefineData;
class TITAN_PCBCAM_EXPORT PcbCamAttrDefine
......@@ -84,9 +83,7 @@ private:
QSharedDataPointer<PcbCamAttrDefineData> d;
};
TITAN_END_NAMESPACE
Q_DECLARE_OPERATORS_FOR_FLAGS(titan::PcbCamAttrDefine::Entity)
Q_DECLARE_OPERATORS_FOR_FLAGS(PcbCamAttrDefine::Entity)
#endif // TITAN_PCBCAM_ATTRDEFINE_H
......@@ -5,8 +5,6 @@
#include <QString>
#include <QRegularExpression>
TITAN_BEGIN_NAMESPACE
class TITAN_PCBCAM_EXPORT PcbCam : public QObject
{
Q_OBJECT
......@@ -202,8 +200,8 @@ public:
ushort type {0}; //比较类型(0:是否有此属性; 1:属性值是否相等; 2:数值是否在范围)
QString name;
QString strValue;
double minValue = INTMAX_MIN;
double maxValue = INTMAX_MAX;
double minValue = static_cast<double>(INTMAX_MIN);
double maxValue = static_cast<double>(INTMAX_MAX);
AttrCompareInfo() {}
AttrCompareInfo(const QString &iAttrStr) {
auto idx = iAttrStr.indexOf("=");
......@@ -231,7 +229,6 @@ public:
};
};
TITAN_END_NAMESPACE
#endif //TITAN_PCBCAM_COMMON_H
#include "config.h"
TITAN_BEGIN_NAMESPACE
class PcbCamConfigData : public QSharedData
{
public:
......@@ -60,4 +58,3 @@ void PcbCamConfig::setTarCmd(const QString &iCmd)
d->tarCmd = iCmd;
}
TITAN_END_NAMESPACE
......@@ -3,7 +3,6 @@
#include "../titanpcbcamglobal.h"
#include <QSharedDataPointer>
TITAN_BEGIN_NAMESPACE
class PcbCamConfigData;
class TITAN_PCBCAM_EXPORT PcbCamConfig
......@@ -25,6 +24,5 @@ private:
QSharedDataPointer<PcbCamConfigData> d;
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_CONFIG_H
......@@ -2,8 +2,6 @@
#include <QFile>
#include <QDir>
TITAN_BEGIN_NAMESPACE
class PcbCamCorePrivate
{
......@@ -66,4 +64,3 @@ PcbCamCore::~PcbCamCore()
}
TITAN_END_NAMESPACE
......@@ -7,7 +7,6 @@
#include "./abstractdataio.h"
#include "./config.h"
TITAN_BEGIN_NAMESPACE
class PcbCamCorePrivate;
class TITAN_PCBCAM_EXPORT PcbCamCore : public QObject
......@@ -42,6 +41,4 @@ private:
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_CORE_H
......@@ -4,7 +4,6 @@
#include "./util.h"
#include "./font.h"
TITAN_BEGIN_NAMESPACE
class PcbCamFeaturePrivate
{
......@@ -938,5 +937,3 @@ QRectF PcbCamFeatureComponent::boundingRect() const
return PcbCamUtil::matrix(d->pos, QPointF(0, 0), d->rotation, d->mirror).mapRect(symbol()->boundingRect());
}
TITAN_END_NAMESPACE
......@@ -9,8 +9,6 @@
#include "./common.h"
#include "./font.h"
TITAN_BEGIN_NAMESPACE
class PcbCamSymbol;
class PcbCamFeaturePrivate;
......@@ -269,6 +267,5 @@ private:
Q_DISABLE_COPY(PcbCamFeatureComponent)
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_FEATURE_H
#include "font.h"
TITAN_BEGIN_NAMESPACE
class PcbCamFontData : public QSharedData
{
......@@ -95,4 +94,3 @@ void PcbCamFont::setCharLines(QChar iChar, const QList<PcbCamFontCharLine> &iLin
d->charLinesMap.insert(iChar, iLines);
}
TITAN_END_NAMESPACE
......@@ -5,7 +5,6 @@
#include "./common.h"
#include "./fontcharline.h"
TITAN_BEGIN_NAMESPACE
class PcbCamFontData;
class TITAN_PCBCAM_EXPORT PcbCamFont
......@@ -36,6 +35,5 @@ private:
QSharedDataPointer<PcbCamFontData> d;
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_FONT_H
#include "fontcharline.h"
TITAN_BEGIN_NAMESPACE
class PcbCamFontCharLineData : public QSharedData
{
public:
......@@ -83,4 +81,3 @@ void PcbCamFontCharLine::setWidth(double iWidth)
d->width = iWidth;
}
TITAN_END_NAMESPACE
......@@ -5,7 +5,6 @@
#include <QLineF>
#include "./common.h"
TITAN_BEGIN_NAMESPACE
class PcbCamFontCharLineData;
class TITAN_PCBCAM_EXPORT PcbCamFontCharLine {
......@@ -36,6 +35,5 @@ private:
QSharedDataPointer<PcbCamFontCharLineData> d;
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_FONTCHARLINE_H
......@@ -22,7 +22,6 @@
#include "./config.h"
#include "./core.h"
TITAN_BEGIN_NAMESPACE
class PcbCamJobPrivate
{
......@@ -255,10 +254,16 @@ PcbCamAttrDefine PcbCamJob::userAttrDefine(const QString &iName) const
return d->userAttrDefineMap.value(iName.toLower());
}
QHash<QString, PcbCamAttrDefine> PcbCamJob::userAttrDefine() const
QStringList PcbCamJob::userAttrDefineKeys() const
{
Q_D(const PcbCamJob);
return d->userAttrDefineMap;
return d->userAttrDefineMap.keys();
}
QList<PcbCamAttrDefine> PcbCamJob::userAttrDefineValues() const
{
Q_D(const PcbCamJob);
return d->userAttrDefineMap.values();
}
void PcbCamJob::addUserAttrDefine(const PcbCamAttrDefine &iAttrDefine)
......@@ -347,7 +352,11 @@ bool PcbCamJob::createLayer(const QString &iLayerName, PcbCam::LayerContext iLay
layer.setRow(d->getMaxLayerRow() + 1);
layer.setId(d->getMaxLayerId() + 1);
d->matrixLayers.append(layer);
emit actionNotified("create_layer", QVariantMap{{"name", iLayerName}, {"context", (int)iLayerContext}, {"type", iLayerType}});
QVariantMap userData;
userData.insert("name", iLayerName);
userData.insert("context", (int)iLayerContext);
userData.insert("type", iLayerType);
emit actionNotified("create_layer", QVariant::fromValue(userData));
return true;
}
......@@ -398,7 +407,10 @@ bool PcbCamJob::renameLayer(const QString &iOldLayerName, const QString &iNewLay
d->layersMap.insert(step + "/" + new_ln, steplayer);
}
}
emit actionNotified("rename_layer", QVariantMap{{"old_name", iOldLayerName}, {"new_name", iNewLayerName}});
QVariantMap userData;
userData.insert("old_name", iOldLayerName);
userData.insert("new_name", iNewLayerName);
emit actionNotified("rename_layer", QVariant::fromValue(userData));
return true;
}
}
......@@ -743,7 +755,7 @@ void PcbCamJob::loadStepLayer(const QString &iStep, const QString &iLayer)
}
QString err;
QVariantMap attr = PcbCamParserHelper::parseOdbStructuredText(readJobFile("steps/"+iStep.toLower()+"/layers/"+iLayer.toLower()+"/attrlist"), &err);
QVariantMap attr = PcbCamParserHelper::parseOdbStructuredText(readJobFile("steps/"+iStep.toLower()+"/layers/"+iLayer.toLower()+"/attrlist"));
if (!err.isEmpty()) {
notifyMessage(err, "ERROR");
}
......@@ -790,7 +802,7 @@ void PcbCamJob::loadFont(const QString &iFontName)
QString err;
PcbCamFont *font = new PcbCamFont();
font->setName(iFontName);
if (PcbCamParserHelper::parseOdbFont(fontData, font, &err)) {
if (PcbCamParserHelper::parseOdbFont(fontData, font)) {
d->fontsMap.insert(iFontName, font);
} else {
delete font;
......@@ -809,7 +821,7 @@ void PcbCamJob::notifyMessage(const QString &iText, const QString &iType, const
bool PcbCamJob::readMiscInfo()
{
QString err;
QVariantMap data = PcbCamParserHelper::parseOdbStructuredText(readJobFile("misc/info"), &err);
QVariantMap data = PcbCamParserHelper::parseOdbStructuredText(readJobFile("misc/info"));
if (!err.isEmpty()) {
notifyMessage(err, "ERROR");
return false;
......@@ -828,7 +840,7 @@ bool PcbCamJob::readMiscAttrlist()
{
Q_D(PcbCamJob);
QString err;
QVariantMap data = PcbCamParserHelper::parseOdbStructuredText(readJobFile("misc/attrlist"), &err);
QVariantMap data = PcbCamParserHelper::parseOdbStructuredText(readJobFile("misc/attrlist"));
if (!err.isEmpty()) {
notifyMessage(err, "ERROR");
return false;
......@@ -848,7 +860,7 @@ bool PcbCamJob::readMiscUserattr()
sysattrfile.open(QFile::ReadOnly | QFile::Text);
auto sysattrdata = sysattrfile.readAll();
sysattrfile.close();
QVariantMap sysdata = PcbCamParserHelper::parseOdbStructuredText(sysattrdata, &err);
QVariantMap sysdata = PcbCamParserHelper::parseOdbStructuredText(sysattrdata);
if (!err.isEmpty()) {
notifyMessage(err, "ERROR");
}
......@@ -870,7 +882,7 @@ bool PcbCamJob::readMiscUserattr()
}
}
QVariantMap userdata = PcbCamParserHelper::parseOdbStructuredText(readJobFile("misc/userattr"), &err);
QVariantMap userdata = PcbCamParserHelper::parseOdbStructuredText(readJobFile("misc/userattr"));
if (!err.isEmpty()) {
notifyMessage(err, "ERROR");
return false;
......@@ -901,7 +913,7 @@ bool PcbCamJob::readMatrix()
{
Q_D(PcbCamJob);
QString err;
QVariantMap data = PcbCamParserHelper::parseOdbStructuredText(readJobFile("matrix/matrix"), &err);
QVariantMap data = PcbCamParserHelper::parseOdbStructuredText(readJobFile("matrix/matrix"));
if (!err.isEmpty()) {
notifyMessage(err, "ERROR");
return false;
......@@ -962,7 +974,7 @@ bool PcbCamJob::readSteps()
QStringList steps = d->matrixSteps.keys();
for (auto stepname : steps) {
QString err;
QVariantMap data = PcbCamParserHelper::parseOdbStructuredText(readJobFile("steps/" + stepname + "/stephdr"), &err);
QVariantMap data = PcbCamParserHelper::parseOdbStructuredText(readJobFile("steps/" + stepname + "/stephdr"));
if (!err.isEmpty()) {
notifyMessage(err, "ERROR");
}
......@@ -993,7 +1005,7 @@ bool PcbCamJob::readSteps()
QPainterPath profile = PcbCamParserHelper::parseOdbProfile(readJobFile("steps/" + stepname + "/profile"));
step->setProfile(profile);
QVariantMap stepattr = PcbCamParserHelper::parseOdbStructuredText(readJobFile("steps/" + stepname + "/attrlist"), &err);
QVariantMap stepattr = PcbCamParserHelper::parseOdbStructuredText(readJobFile("steps/" + stepname + "/attrlist"));
step->initAttr(stepattr);
d->stepsMap.insert(stepname, step);
}
......@@ -1076,7 +1088,7 @@ bool PcbCamJob::importGerber274X(const QString &iGerberFile, const QString &iSte
auto apertures = parser.apertures();
QHash<int, QString> dcodeSymbolMap;
auto sym_num = d->getMaxConstructSymbolNum();
for (auto ap : apertures.values()) {
for (auto ap : apertures) {
auto sym_name = ap.name;
if (!ap.isStandard) {
sym_name = QString("construct+%1").arg(++sym_num);
......@@ -1142,23 +1154,19 @@ bool PcbCamJob::importDrill(const QString &iDrlFile, const QString &iStep, const
return true;
}
QByteArray PcbCamJob::readJobFile(const QString &iRelPath, QString *oErrStr) const
QByteArray PcbCamJob::readJobFile(const QString &iRelPath) const
{
Q_D(const PcbCamJob);
QString filepath = d->logJobPath + "/" + iRelPath;
notifyMessage(QString("read file - %1").arg(filepath), "INFO");
QString err;
auto result = PcbCamCore::instance()->dataIo()->readJobData(this->jobPath(), iRelPath, &err);
auto result = PcbCamCore::instance()->dataIo()->readJobData(this->jobPath(), iRelPath);
if (!err.isEmpty()) {
notifyMessage(QString("read file -%1 failed! %2").arg(filepath).arg(err), "ERROR");
}
if (oErrStr != nullptr) {
*oErrStr = err;
}
return result;
}
PcbCamFeature *PcbCamJob::createFeature(const PcbCamOdbFeatureInfo &iFeat)
{
Q_D(const PcbCamJob);
......@@ -1246,6 +1254,3 @@ PcbCamFeature *PcbCamJob::createFeature(const PcbCamOdbFeatureInfo &iFeat)
}
return nullptr;
}
TITAN_END_NAMESPACE
......@@ -12,19 +12,18 @@
#include "./symbol.h"
#include "../parser/odbfeatureparser.h"
TITAN_BEGIN_NAMESPACE
class PcbCamJobPrivate;
class TITAN_PCBCAM_EXPORT PcbCamJob : public QObject
{
Q_OBJECT
public:
explicit PcbCamJob(QObject *parent = 0);
explicit PcbCamJob(QObject *parent = nullptr);
~PcbCamJob();
signals:
void messageNotified(const QString &iMessage, const QString &iType, const QVariant &iUserData) const;
void actionNotified(const QString &iActionName, const QVariantMap &iUserData) const;
void actionNotified(const QString &iActionName, const QVariant &iUserData) const;
public slots:
QString jobname() const;
......@@ -53,7 +52,8 @@ public slots:
void setJobAttr(const QString &iName, const QVariant &iValue);
PcbCamAttrDefine userAttrDefine(const QString &iName) const;
QHash<QString, PcbCamAttrDefine> userAttrDefine() const;
QStringList userAttrDefineKeys() const;
QList<PcbCamAttrDefine> userAttrDefineValues() const;
void addUserAttrDefine(const PcbCamAttrDefine &iAttrDefine);
PcbCamStep *step(const QString &iStepName) const;
......@@ -112,7 +112,7 @@ public slots:
void notifyMessage(const QString &iText, const QString &iType, const QVariant &iUserData = QVariant()) const;
QByteArray readJobFile(const QString &iRelPath, QString *oErrStr = nullptr) const;
QByteArray readJobFile(const QString &iRelPath) const;
bool importGerber274X(const QString &iGerberFile, const QString &iStep, const QString &iLayer);
bool importDrill(const QString &iDrlFile, const QString &iStep, const QString &iLayer, const QVariantMap &iStatement);
......@@ -140,6 +140,4 @@ private:
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_JOB_H
......@@ -6,9 +6,6 @@
#include <QDebug>
#include <QHash>
TITAN_BEGIN_NAMESPACE
class PcbCamLayerPrivate
{
......@@ -425,4 +422,3 @@ QRectF PcbCamLayer::boundingRect() const
return d->boundingRect;
}
TITAN_END_NAMESPACE
......@@ -6,7 +6,6 @@
#include <QPainterPath>
#include "./common.h"
TITAN_BEGIN_NAMESPACE
class PcbCamJob;
class PcbCamFeature;
......@@ -99,6 +98,4 @@ private:
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_LAYER_H
......@@ -6,7 +6,6 @@
#include <QPolygonF>
#include <cmath>
TITAN_BEGIN_NAMESPACE
class TITAN_PCBCAM_EXPORT PcbCamMath
{
......@@ -102,6 +101,5 @@ public:
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_MATH_H
#include "matrixlayer.h"
TITAN_BEGIN_NAMESPACE
class PcbCamMatrixLayerData : public QSharedData
{
......@@ -141,5 +140,3 @@ void PcbCamMatrixLayer::setEndName(const QString &iName)
{
d->endName = iName;
}
TITAN_END_NAMESPACE
......@@ -4,7 +4,6 @@
#include <QSharedDataPointer>
#include "./common.h"
TITAN_BEGIN_NAMESPACE
class PcbCamMatrixLayerData;
class TITAN_PCBCAM_EXPORT PcbCamMatrixLayer
......@@ -46,6 +45,5 @@ private:
QSharedDataPointer<PcbCamMatrixLayerData> d;
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_MATRIXLAYER_H
#include "step.h"
#include <QDebug>
TITAN_BEGIN_NAMESPACE
class PcbCamStepData : public QSharedData
{
......@@ -195,4 +194,3 @@ QList<PcbCamSymbolUser *> PcbCamStep::edaPackageSymbols() const
return d->edaPackageSymbols;
}
TITAN_END_NAMESPACE
......@@ -10,7 +10,6 @@
#include "./steprepeat.h"
#include "./symbol.h"
TITAN_BEGIN_NAMESPACE
class PcbCamStepData;
......@@ -56,6 +55,4 @@ private:
QSharedDataPointer<PcbCamStepData> d;
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_STEP_H
#include "steprepeat.h"
TITAN_BEGIN_NAMESPACE
class PcbCamStepRepeatData : public QSharedData
{
......@@ -166,4 +165,3 @@ void PcbCamStepRepeat::setSelected(bool iSelected)
d->selected = iSelected;
}
TITAN_END_NAMESPACE
......@@ -3,7 +3,6 @@
#include "../titanpcbcamglobal.h"
#include <QSharedDataPointer>
TITAN_BEGIN_NAMESPACE
class PcbCamStepRepeatData;
class TITAN_PCBCAM_EXPORT PcbCamStepRepeat
......@@ -52,6 +51,5 @@ private:
QSharedDataPointer<PcbCamStepRepeatData> d;
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_STEPREPEAT_H
......@@ -3,7 +3,6 @@
#include <QtMath>
#include <QTransform>
TITAN_BEGIN_NAMESPACE
class PcbCamSymbolPrivate
{
......@@ -2040,7 +2039,3 @@ void PcbCamSymbolUser::deleteFeature(int iIndex)
}
}
}
TITAN_END_NAMESPACE
......@@ -5,7 +5,6 @@
#include "./feature.h"
#include "./common.h"
TITAN_BEGIN_NAMESPACE
class PcbCamSymbolPrivate;
class TITAN_PCBCAM_EXPORT PcbCamSymbol
......@@ -503,6 +502,5 @@ private:
Q_DISABLE_COPY(PcbCamSymbolUser)
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_SYMBOL_H
......@@ -2,7 +2,6 @@
#include <QDebug>
#include "./symbol.h"
TITAN_BEGIN_NAMESPACE
static QString formatNumber(double iNumber, int iPercision = 6)
{
......@@ -401,6 +400,3 @@ QString PcbCamSymbolFactory::symbolScaledName(const QString &iName, double iScal
return iName;
}
TITAN_END_NAMESPACE
......@@ -2,7 +2,6 @@
#define TITAN_PCBCAM_SYMBOLFACTORY_H
#include "../titanpcbcamglobal.h"
TITAN_BEGIN_NAMESPACE
class PcbCamSymbol;
class TITAN_PCBCAM_EXPORT PcbCamSymbolFactory
......@@ -12,6 +11,5 @@ public:
static QString symbolScaledName(const QString &iName, double iScale, int iPercision=6);
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_SYMBOLFACTORY_H
......@@ -11,7 +11,6 @@
#include "./common.h"
#include "./feature.h"
TITAN_BEGIN_NAMESPACE
static QMap<int, QString> WEEK_DAY_STRING {
{1, "MONDAY"},
......@@ -43,7 +42,7 @@ QString PcbCamUtil::formatNumber(double iNumber, int iPercision)
}
QRectF PcbCamUtil::calcPathArc(const QPointF &iPs, const QPointF &iPe, const QPointF &iPc, bool iCw, double *oStartAngle, double *oSweepLength)
QVariantMap PcbCamUtil::calcPathArc(const QPointF &iPs, const QPointF &iPe, const QPointF &iPc, bool iCw)
{
qreal xs = iPs.x();
qreal ys = iPs.y();
......@@ -71,18 +70,20 @@ QRectF PcbCamUtil::calcPathArc(const QPointF &iPs, const QPointF &iPe, const QPo
}
}
*oStartAngle = sa * (180.0 / M_PI) ;
*oSweepLength = (ea - sa) * (180.0 / M_PI);
return QRectF(xc - r, yc - r, r * 2.0, r * 2.0);
QVariantMap retData;
retData.insert("start_angle", sa * (180.0 / M_PI));
retData.insert("sweep_length", (ea - sa) * (180.0 / M_PI));
retData.insert("rect", QRectF(xc - r, yc - r, r * 2.0, r * 2.0));
return retData;
}
QPainterPath PcbCamUtil::arc2path(const QPointF &iPs, const QPointF &iPe, const QPointF &iPc, bool iCw)
{
QPainterPath path;
double startAngle;
double sweepLength;
auto rect = calcPathArc(iPs, iPe, iPc, iCw, &startAngle, &sweepLength);
QVariantMap calcData = calcPathArc(iPs, iPe, iPc, iCw);
double startAngle = calcData.value("start_angle").toDouble();
double sweepLength = calcData.value("sweep_length").toDouble();
QRectF rect = calcData.value("rect").toRectF();
path.arcMoveTo(rect, startAngle);
path.arcTo(rect, startAngle, sweepLength);
return path;
......@@ -648,9 +649,10 @@ QList<QPainterPath> PcbCamUtil::findPolyline(const QList<PcbCamFeature *> &iFeat
auto pe = iInvert ? feat->ps() : feat->pe();
auto pc = feat->pc();
bool cw = iInvert ? !feat->cw() : feat->cw();
double startAngle;
double sweepLength;
auto rect = calcPathArc(ps, pe, pc, cw, &startAngle, &sweepLength);
QVariantMap calcData = calcPathArc(ps, pe, pc, cw);
double startAngle = calcData.value("start_angle").toDouble();
double sweepLength = calcData.value("sweep_length").toDouble();
QRectF rect = calcData.value("rect").toRectF();
if (iPath->isEmpty()) {
iPath->arcMoveTo(rect, startAngle);
iPath->arcTo(rect, startAngle, sweepLength);
......@@ -715,10 +717,3 @@ QList<QPainterPath> PcbCamUtil::findPolyline(const QList<PcbCamFeature *> &iFeat
return allpaths;
}
TITAN_END_NAMESPACE
......@@ -11,13 +11,12 @@
#include <QPainterPath>
#include <QPen>
TITAN_BEGIN_NAMESPACE
class TITAN_PCBCAM_EXPORT PcbCamUtil
{
public:
static QString formatNumber(double iNumber, int iPercision = 6);
static QRectF calcPathArc(const QPointF &iPs, const QPointF &iPe, const QPointF &iPc, bool iCw, double *oStartAngle, double *oSweepLength);
static QVariantMap calcPathArc(const QPointF &iPs, const QPointF &iPe, const QPointF &iPc, bool iCw);
static QPainterPath arc2path(const QPointF &iPs, const QPointF &iPe, const QPointF &iPc, bool iCw);
static QPainterPath line2path(const QLineF &iLine);
......@@ -59,10 +58,10 @@ public:
PcbCam::LogicOperator iExcludeAttrLogic);
//点到线段的最短距离
static double point2segDist(double x, double y, double x1, double y1, double x2, double y2);
// static double point2segDist(double x, double y, double x1, double y1, double x2, double y2);
//点到多段线最短距离
static double point2polylineDist(const QPointF &p, const QPolygonF &polyline);
// static double point2polylineDist(const QPointF &p, const QPolygonF &polyline);
//查找封闭的painterpath
static QPainterPath findClosedPath(const QList<PcbCamFeature*> &iFeatures, double iTol = 0.0001);
......@@ -72,6 +71,4 @@ public:
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_UTIL_H
#----------------项目设置----------------------------------------------------
PROJECT_NAME = titan_pcbcam
ROOT_DIR = $$PWD/../../
ROOT_DIR = $$PWD/../
HEADER_DIR = titan/pcbcam
DLL_LIBS =
STATIC_LIBS =
VERSION = 2.0.2
VERSION = 2.0.3
#----------------编译设置---------------------------------------------------
TEMPLATE = lib
##CONFIG += staticlib
### Library Export
CONFIG(staticlib) : DEFINES += $$upper($${PROJECT_NAME})_STATIC
else : DEFINES += $$upper($${PROJECT_NAME})_SHARED
#CONFIG(staticlib) : DEFINES += $$upper($${PROJECT_NAME})_STATIC
#else : DEFINES += $$upper($${PROJECT_NAME})_SHARED
DEFINES += BINDINGS_BUILD
TARGET = $$qtLibraryTarget($${PROJECT_NAME})
......@@ -40,7 +41,7 @@ include(pcbcam.pri)
#----------------其它编译设定----------------------------------------------
SRC_PWD = $$PWD
include($${ROOT_DIR}/shared/shared.pri)
include(shared.pri)
### 导出头文件 ###
......
......@@ -7,7 +7,6 @@
#include <functional>
#include "../core/util.h"
TITAN_BEGIN_NAMESPACE
class PcbCamDrillToolData: public QSharedData
{
......@@ -1125,7 +1124,7 @@ bool PcbCamDrillParser::parser()
drlfile.close();
d->walkDrillRows(drillrows, d->statement, [this](const PcbCamDrillParserPrivate::RowData &rowdata){
return d->walkDrillRows(drillrows, d->statement, [this](const PcbCamDrillParserPrivate::RowData &rowdata){
if (rowdata.section == PcbCamDrillParserPrivate::Section::Head ) {
if (rowdata.cmd == PcbCamDrillParserPrivate::Cmd::TCODE) {
auto tool = rowdata.tool;
......@@ -1341,6 +1340,3 @@ QVariantMap PcbCamDrillParser::DrillStatement::toMap() const
{"decimalDigits", this->decimalDigits},
};
}
TITAN_END_NAMESPACE
......@@ -3,7 +3,6 @@
#include "../titanpcbcamglobal.h"
#include "odbfeatureparser.h"
TITAN_BEGIN_NAMESPACE
class PcbCamDrillParserPrivate;
class TITAN_PCBCAM_EXPORT PcbCamDrillParser
......@@ -56,6 +55,5 @@ private:
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_DRILLPARSER_H
......@@ -11,9 +11,6 @@
#include <QtMath>
#include "../core/util.h"
TITAN_BEGIN_NAMESPACE
class PcbCamGerber274XParserPrivate
{
......@@ -94,7 +91,7 @@ public:
// 以下为旧版格式命令
{ PcbCamGerber274XParser::Cmd::IN, QRegularExpression("^(?<cmd>IN)(?<name>.*)")},
{ PcbCamGerber274XParser::Cmd::INN, QRegularExpression("^(?<cmd>IN)(?<name>.*)")},
{ PcbCamGerber274XParser::Cmd::IP, QRegularExpression("^(?<cmd>IP)(?<mode>(POS|NEG))")},
{ PcbCamGerber274XParser::Cmd::IR, QRegularExpression("^(?<cmd>IR)(?<angle>[\\+\\-]?\\d+>)")},
{ PcbCamGerber274XParser::Cmd::OF, QRegularExpression("^(?<cmd>IO)(A(?<a>[\\+\\-]?\\d+(\\.?\\d+)?))?(B(?<b>[\\+\\-]?\\d+(\\.?\\d+)?))?")},
......@@ -790,9 +787,10 @@ void PcbCamGerber274XParser::parse(QIODevice *iIODevice)
auto ps = d->graphicsState.currentPoint;
bool cw = d->graphicsState.interpolationMode == PcbCamGerber274XParserPrivate::ClockwiseCircularMode;
auto pc = d->calcArcCenter(ps, pos, d->coord2inch(coordparam.value("i", "0")), d->coord2inch(coordparam.value("j", "0")), cw, d->graphicsState.quadrantMode);
double startAngle;
double sweepLength;
auto arcrect = PcbCamUtil::calcPathArc(ps, pos, pc, cw, &startAngle, &sweepLength);
QVariantMap calcData = PcbCamUtil::calcPathArc(ps, pos, pc, cw);
double startAngle = calcData.value("start_angle").toDouble();
double sweepLength = calcData.value("sweep_length").toDouble();
QRectF arcrect = calcData.value("rect").toRectF();
d->curRegionPath.arcTo(arcrect, startAngle, sweepLength);
}
}
......@@ -970,7 +968,7 @@ void PcbCamGerber274XParser::parse(QIODevice *iIODevice)
// Include File
// TODO
}
else if (cmd == Cmd::IN) {
else if (cmd == Cmd::INN) {
// Image Name, just a comment
}
else if (cmd == Cmd::LN) {
......@@ -1011,14 +1009,8 @@ QList<PcbCamOdbFeatureInfo> PcbCamGerber274XParser::features() const
return d->featureList;
}
QMap<int, PcbCamGerber274XParser::ApertureInfo> PcbCamGerber274XParser::apertures() const
QList<PcbCamGerber274XParser::ApertureInfo> PcbCamGerber274XParser::apertures() const
{
Q_D(const PcbCamGerber274XParser);
return d->apertures;
return d->apertures.values();
}
TITAN_END_NAMESPACE
......@@ -3,7 +3,7 @@
#include "../titanpcbcamglobal.h"
#include "odbfeatureparser.h"
TITAN_BEGIN_NAMESPACE
class QIODevice;
class PcbCamGerber274XParserPrivate;
class TITAN_PCBCAM_EXPORT PcbCamGerber274XParser
......@@ -11,6 +11,7 @@ class TITAN_PCBCAM_EXPORT PcbCamGerber274XParser
public:
struct ApertureInfo {
explicit ApertureInfo(){}
int dcode {0};
QString name;
bool isStandard {true};
......@@ -37,7 +38,7 @@ public:
// 以下为旧版格式命令
AS,
IN,
INN,
IP,
IR,
IO,
......@@ -49,20 +50,18 @@ public:
DEPRECATED_FORMAT,
UNKNOW ,
EMPTY,
EMPTY
};
PcbCamGerber274XParser();
explicit PcbCamGerber274XParser();
~PcbCamGerber274XParser();
void parse(QIODevice *iIODevice);
QStringList errors();
QList<PcbCamOdbFeatureInfo> features() const;
QMap<int, ApertureInfo> apertures() const;
QList<ApertureInfo> apertures() const;
protected:
const QScopedPointer<PcbCamGerber274XParserPrivate> d_ptr;
......@@ -72,6 +71,5 @@ private:
Q_DISABLE_COPY(PcbCamGerber274XParser)
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_GERBER274XPARSER_H
......@@ -3,7 +3,6 @@
#include <QStringList>
#include <QtMath>
TITAN_BEGIN_NAMESPACE
class PcbCamOdbComponentParserPrivate
{
......@@ -155,5 +154,3 @@ void PcbCamOdbComponentParser::parseAttributes(const QString &iLine, QStringList
}
}
TITAN_END_NAMESPACE
......@@ -3,7 +3,6 @@
#include "../titanpcbcamglobal.h"
#include "odbfeatureparser.h"
TITAN_BEGIN_NAMESPACE
class PcbCamOdbComponentParserPrivate;
class TITAN_PCBCAM_EXPORT PcbCamOdbComponentParser
......@@ -31,6 +30,5 @@ private:
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_ODBCOMPONENTPARSER_H
......@@ -2,7 +2,6 @@
#include <QTextStream>
#include <QtMath>
TITAN_BEGIN_NAMESPACE
class PcbCamOdbEdaDataParserPrivate
{
......@@ -154,8 +153,6 @@ QStringList PcbCamOdbEdaDataParser::errors()
return d->errorList;
}
void PcbCamOdbEdaDataParser::parseSurfaceLine(const QString &iLine)
{
Q_D(PcbCamOdbEdaDataParser);
......@@ -203,4 +200,3 @@ void PcbCamOdbEdaDataParser::parseSurfaceLine(const QString &iLine)
}
}
TITAN_END_NAMESPACE
......@@ -3,7 +3,6 @@
#include "../titanpcbcamglobal.h"
#include "odbfeatureparser.h"
TITAN_BEGIN_NAMESPACE
class PcbCamOdbEdaDataParserPrivate;
class TITAN_PCBCAM_EXPORT PcbCamOdbEdaDataParser
......@@ -26,6 +25,5 @@ private:
Q_DISABLE_COPY(PcbCamOdbEdaDataParser)
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_ODBEDAPACKAGEPARSER_H
......@@ -4,7 +4,6 @@
#include <QtMath>
#include "../core/util.h"
TITAN_BEGIN_NAMESPACE
class PcbCamOdbFeatureParserPrivate
{
......@@ -285,9 +284,10 @@ void PcbCamOdbFeatureParser::parseSurfaceLine(const QString &iLine)
qreal ex = param.value(1).toDouble(), ey = param.value(2).toDouble();
qreal cx = param.value(3).toDouble(), cy = param.value(4).toDouble();
bool cw = param.value(5) == "Y" ? true : false;
double startAngle;
double sweepLength;
auto arcrect = PcbCamUtil::calcPathArc(QPointF(sx, sy), QPointF(ex, ey), QPointF(cx, cy), cw, &startAngle, &sweepLength);
QVariantMap calcData = PcbCamUtil::calcPathArc(QPointF(sx, sy), QPointF(ex, ey), QPointF(cx, cy), cw);
double startAngle = calcData.value("start_angle").toDouble();
double sweepLength = calcData.value("sweep_length").toDouble();
QRectF arcrect = calcData.value("rect").toRectF();
d->lastPath.arcTo(arcrect, startAngle, sweepLength);
......@@ -347,4 +347,3 @@ void PcbCamOdbFeatureParser::parseAttributes(const QString &iLine, QStringList *
}
}
TITAN_END_NAMESPACE
......@@ -8,7 +8,6 @@
#include <QSizeF>
#include "../core/common.h"
TITAN_BEGIN_NAMESPACE
struct PcbCamOdbFeatureInfo {
PcbCam::FeatureType type {PcbCam::PadFeature};
......@@ -73,6 +72,5 @@ private:
Q_DISABLE_COPY(PcbCamOdbFeatureParser)
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_ODBFEATUREPARSERV2_H
......@@ -2,7 +2,6 @@
#include <QFile>
#include <QTextStream>
TITAN_BEGIN_NAMESPACE
class PcbCamOdbMatrixParserPrivate
{
......@@ -148,4 +147,3 @@ QStringList PcbCamOdbMatrixParser::errors() const
return d->errors;
}
TITAN_END_NAMESPACE
......@@ -5,7 +5,6 @@
#include <QMap>
#include "../core/matrixlayer.h"
TITAN_BEGIN_NAMESPACE
class PcbCamOdbMatrixParserPrivate;
class TITAN_PCBCAM_EXPORT PcbCamOdbMatrixParser : public QObject
......@@ -32,6 +31,5 @@ private:
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_ODBMATRIXPARSER_H
......@@ -6,11 +6,9 @@
#include <QDebug>
#include "../core/font.h"
TITAN_BEGIN_NAMESPACE
QVariantMap PcbCamParserHelper::parseOdbStructuredText(const QByteArray &iData, QString *oErrStr)
QVariantMap PcbCamParserHelper::parseOdbStructuredText(const QByteArray &iData)
{
if (oErrStr != nullptr) oErrStr->clear();
QByteArray data = iData;
QVariantMap res;
......@@ -59,9 +57,8 @@ QVariantMap PcbCamParserHelper::parseOdbStructuredText(const QByteArray &iData,
return res;
}
QPainterPath PcbCamParserHelper::parseOdbProfile(const QByteArray &iData, QString *oErrStr)
QPainterPath PcbCamParserHelper::parseOdbProfile(const QByteArray &iData)
{
if (oErrStr != nullptr) oErrStr->clear();
QByteArray data = iData;
QTextStream stream(&data);
QString line;
......@@ -121,10 +118,9 @@ QPainterPath PcbCamParserHelper::parseOdbProfile(const QByteArray &iData, QStrin
return res;
}
bool PcbCamParserHelper::parseOdbFont(const QByteArray &iData, PcbCamFont *oFont, QString *oErrStr)
bool PcbCamParserHelper::parseOdbFont(const QByteArray &iData, PcbCamFont *oFont)
{
if (oFont == nullptr) return false;
if (oErrStr != nullptr) oErrStr->clear();
QList<PcbCamFontCharLine> currentCharLines;
QChar currentChar;
......@@ -186,4 +182,3 @@ PcbCamParserHelper::PcbCamParserHelper()
}
TITAN_END_NAMESPACE
......@@ -4,20 +4,18 @@
#include <QVariantMap>
#include <QPainterPath>
TITAN_BEGIN_NAMESPACE
class PcbCamFont;
class TITAN_PCBCAM_EXPORT PcbCamParserHelper
{
public:
static QVariantMap parseOdbStructuredText(const QByteArray &iData, QString *oErrStr = nullptr);
static QPainterPath parseOdbProfile(const QByteArray &iData, QString *oErrStr = nullptr);
static bool parseOdbFont(const QByteArray &iData, PcbCamFont *oFont, QString *oErrStr = nullptr);
static QVariantMap parseOdbStructuredText(const QByteArray &iData);
static QPainterPath parseOdbProfile(const QByteArray &iData);
static bool parseOdbFont(const QByteArray &iData, PcbCamFont *oFont);
private:
PcbCamParserHelper();
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_PARSERHELPER_H
#-------------------------------------------------------------------------------
# 此工程是titanframework下所有工程文件共用的部分,主要包含系统判定,编译目录设置等
#
# Author: Tony Guo
#-------------------------------------------------------------------------------
### 默认的编译目标目录 ###
isEmpty(DIST_DIR){
DIST_DIR = $${ROOT_DIR}/dist
}
DEFINES += APP_VERSION=\\\"$${VERSION}\\\"
### 为了防止在windows下编译出的dll带版本数字的问题 ###
win32:VERSION=
DEFINES += QT_NO_FOREACH
win32-msvc* {
### Window XP支持 ###
QMAKE_LFLAGS_WINDOWS = /SUBSYSTEM:WINDOWS,5.01
### generating pdb in release mode ###
QMAKE_CXXFLAGS_RELEASE += /Zi
QMAKE_LFLAGS_RELEASE += /DEBUG
}
### 获取系统平台名称(platform) ###
TANCC=$$section(QMAKESPEC, /, -3, -3)
TANOS=$$(TANPM_OSNAME)
isEmpty(TANOS){
TANOS=unknowos
win32 {
TANOS=windows
}
linux {
TANOS=linux
}
macx {
TANOS=macx
}
}
TANPLATFORM=$${TANOS}-$${TANCC}-qt$$[QT_VERSION]
### 定义DIST_PLATFORM ###
DIST_PLATFORM=$${DIST_DIR}/$${TANPLATFORM}
DEFINES += APP_PLATFORM=\\\"$${TANPLATFORM}\\\"
### C++11支持 ###
CONFIG += c++11
### 设置DEBUG模式后缀 ###
CONFIG += debug_and_release
CONFIG(debug, debug | release) {
win32 {
DEBUG_SUFFIX = d
}
macx {
DEBUG_SUFFIX = _debug
}
} else {
DEBUG_SUFFIX =
}
### 设置编译目标目录 ###
DIST_BIN = $$system_path($${DIST_PLATFORM}/bin)
DIST_LIB = $$system_path($${DIST_PLATFORM}/lib)
DIST_STATICLIB = $$system_path($${DIST_PLATFORM}/static)
DESTDIR = $${DIST_BIN}
equals(TEMPLATE, "lib") {
CONFIG(staticlib) {
CONFIG(debug, debug | release) {
DESTDIR = $${DIST_STATICLIB}/debug
} else {
DESTDIR = $${DIST_STATICLIB}/release
}
}
else {
CONFIG(debug, debug | release) {
DESTDIR = $${DIST_LIB}/debug
} else {
DESTDIR = $${DIST_LIB}/release
}
}
}
### 定义TOPSIN_SDK头文件目录 ###
INCLUDEPATH += $${DIST_PLATFORM}/include
### 编译link设置 ###
for (lib, DLL_LIBS) {
tanpmlibpath = $${DIST_PLATFORM}/tanpm/$${lib}
exists($${tanpmlibpath}) {
INCLUDEPATH += $${tanpmlibpath}/include
CONFIG(debug, debug | release) {
exists($${tanpmlibpath}/lib/debug) {
LIBS += -L$${tanpmlibpath}/lib/debug -l$${lib}$${DEBUG_SUFFIX}
} else {
LIBS += -L$${tanpmlibpath}/lib/release -l$${lib}
}
} else {
LIBS += -L$${tanpmlibpath}/lib/release -l$${lib}
}
}
else {
CONFIG(debug, debug | release) {
exists($${DIST_LIB}/debug) {
LIBS += -L$${DIST_LIB}/debug -l$${lib}$${DEBUG_SUFFIX}
} else {
LIBS += -L$${DIST_LIB}/release -l$${lib}
}
} else {
LIBS += -L$${DIST_LIB}/release -l$${lib}
}
}
}
for (lib, STATIC_LIBS) {
tanpmlibpath = $${DIST_PLATFORM}/tanpm/$${lib}
exists($${tanpmlibpath}) {
INCLUDEPATH += $${tanpmlibpath}/include
exists($${tanpmlibpath}/static) {
DEFINES += $$upper($${lib})_STATIC
CONFIG(debug, debug | release) {
exists($${tanpmlibpath}/static/debug) {
LIBS += -L$${tanpmlibpath}/static/debug -l$${lib}$${DEBUG_SUFFIX}
} else {
LIBS += -L$${tanpmlibpath}/static/release -l$${lib}
}
} else {
LIBS += -L$${tanpmlibpath}/static/release -l$${lib}
}
}
}
else {
CONFIG(debug, debug | release) {
exists($${DIST_STATICLIB}/debug) {
LIBS += -L$${DIST_STATICLIB}/debug -l$${lib}$${DEBUG_SUFFIX}
} else {
LIBS += -L$${DIST_STATICLIB}/release -l$${lib}
}
} else {
LIBS += -L$${DIST_STATICLIB}/release -l$${lib}
}
}
}
### 导出头文件 ###
equals(TEMPLATE, "lib") {
### 查看SDK头文件目标路径是否存在,不存在则创建 ###
DIST_HEADER = $$system_path($${DIST_PLATFORM}/include/$${HEADER_DIR})
!exists($${DIST_HEADER}) {
mkpath($${DIST_HEADER})
}
### 导出header ###
win32 {
system(copy $$system_path($${SRC_PWD}/*.h) $${DIST_HEADER})
} else {
system(cp $$system_path($${SRC_PWD}/*.h) $${DIST_HEADER})
}
}
### 复制语言包.qm ###
!isEmpty(QM_LIST) {
DIST_LANGUAGE = $$system_path($${DIST_PLATFORM}/lang)
!exists($${DIST_LANGUAGE}) {
mkpath($${DIST_LANGUAGE})
}
for(qm, QM_LIST) {
win32{
system(copy $$system_path($${qm}) $${DIST_LANGUAGE})
}
else{
system(cp $$system_path($${qm}) $${DIST_LANGUAGE})
}
}
}
### 设置Macx rpath ###
macx {
QMAKE_LFLAGS += -Wl,-rpath,@loader_path,-rpath,@executable_path
QMAKE_LFLAGS += -Wl,-rpath,@executable_path/../lib
QMAKE_SONAME_PREFIX = @rpath
}
### 设置Linux rpath ###
linux {
QMAKE_RPATHDIR += .
QMAKE_RPATHDIR += ../lib
}
################################# COPYRIGHT ###################################
# #
# Copyright (c) 2009-2020 TopLinker Co.,Ltd. (http://www.toplinker.net) #
# ALL RIGHTS RESERVED #
# #
# The entire contents of this file is protected by copyright law and #
# international treaties. Unauthorized reproduction, reverse-engineering #
# and distribution of all or any portion of the code contained in this #
# file is strictly prohibited and may result in severe civil and #
# criminal penalties and will be prosecuted to the maximum extent #
# possible under the law. #
# #
# RESTRICTIONS #
# #
# THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED #
# FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE #
# COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE #
# AVAILABLE TO OTHER INDIVIDUALS WITHOUT WRITTEN CONSENT #
# AND PERMISSION FROM DEVELOPER MACHINES #
# #
# CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON #
# ADDITIONAL RESTRICTIONS. #
# #
################################################################################
#ifndef TITAN_PCBCAM_GLOBAL_H
#define TITAN_PCBCAM_GLOBAL_H
#include <QtCore/qglobal.h>
#if !defined(TITAN_PCBCAM_STATIC)
# if defined(TITAN_PCBCAM_SHARED)
#if BINDINGS_BUILD
# define TITAN_PCBCAM_EXPORT Q_DECL_EXPORT
# else
# define TITAN_PCBCAM_EXPORT Q_DECL_IMPORT
# endif
#else
# define TITAN_PCBCAM_EXPORT
# define TITAN_PCBCAM_EXPORT Q_DECL_IMPORT
#endif
#define TITAN_BEGIN_NAMESPACE namespace titan {
#define TITAN_END_NAMESPACE }
#endif // TITAN_PCBCAM_GLOBAL_H
......@@ -6,14 +6,12 @@
#include <QWheelEvent>
#include <QMenu>
#include <QStack>
#include "../core/arcpainterinfo.h"
#include "../core/util.h"
#include "../core/math.h"
#include "../core/symbol.h"
#include "../core/feature.h"
#include "./popviewwindow.h"
TITAN_BEGIN_NAMESPACE
struct PopViewInfo {
QRectF canvasRect;
......@@ -240,7 +238,7 @@ void PcbCamCanvas::viewLeft(qreal iRate)
{
Q_D(PcbCamCanvas);
QRectF rect = d->orientMatrix.mapRect(d->currentDisplayRect).normalized();
rect.moveLeft(rect.left() - rect.width()*iRate);
rect.moveRight(rect.right() + rect.width()*iRate);
rect = d->orientMatrix.inverted().mapRect(rect).normalized();
fitInView(rect);
}
......@@ -249,7 +247,7 @@ void PcbCamCanvas::viewRight(qreal iRate)
{
Q_D(PcbCamCanvas);
QRectF rect = d->orientMatrix.mapRect(d->currentDisplayRect).normalized();
rect.moveRight(rect.right() + rect.width()*iRate);
rect.moveLeft(rect.left() - rect.width()*iRate);
rect = d->orientMatrix.inverted().mapRect(rect).normalized();
fitInView(rect);
}
......@@ -277,7 +275,7 @@ void PcbCamCanvas::setOrientMatrix(const QTransform &iMatrix)
Q_D(PcbCamCanvas);
d->orientMatrix = iMatrix;
auto rect = d->currentDisplayRect.normalized();
qreal size = qMin(rect.width(), rect.height());
qreal size = qMax(rect.width(), rect.height());
this->fitInView(QRectF(rect.center().x() - size/2.0, rect.center().y() - size/2.0, size, size), false);
}
......@@ -606,7 +604,7 @@ QVariantMap PcbCamCanvas::snapFeatInfo(const QPoint &iPoint, int iTolPix)
res.insert("angle", PcbCamUtil::orient2angle(feat->orient()));
res.insert("mirror", PcbCamUtil::orient2mirror(feat->orient()));
}
emit snapFeatChanged(res);
emit snapFeatChanged(QVariant::fromValue(res));
}
return res;
}
......@@ -1454,14 +1452,21 @@ QPixmap PcbCamCanvas::renderChkMeans(const QTransform &iMatrix, const QSize &iSi
return pixmap;
}
QPointF PcbCamCanvas::getSnapPoint(const QPoint &iCursorPos, int iSnapRange, bool *oSnaped)
QVariantMap PcbCamCanvas::getSnapPoint(const QPoint &iCursorPos, int iSnapRange)
{
Q_D(PcbCamCanvas);
QVariantMap retData;
d->isSnapPointValid = false;
if (oSnaped != nullptr) *oSnaped = false;
if (d->jobData == nullptr) return QPointF();
retData.insert("snaped", false);
if (d->jobData == nullptr) {
retData.insert("point", QPointF());
return retData;
}
QPointF curpos = mapToScene(iCursorPos);
if (d->snapMode == PcbCam::SnapOff) return curpos;
if (d->snapMode == PcbCam::SnapOff) {
retData.insert("point", curpos);
return retData;
}
QRectF range = mapToScene(QRect(iCursorPos.x() - iSnapRange, iCursorPos.y() - iSnapRange, iSnapRange*2, iSnapRange *2));
......@@ -1503,13 +1508,15 @@ QPointF PcbCamCanvas::getSnapPoint(const QPoint &iCursorPos, int iSnapRange, boo
}
if (snapExists && scaledRange.contains(snapPoint)) {
if (oSnaped != nullptr) *oSnaped = true;
retData.insert("snaped", true);
d->isSnapPointValid = true;
d->snapPoint = mat.inverted().map(snapPoint);
return d->snapPoint;
retData.insert("point", d->snapPoint);
return retData;
}
else {
return curpos;
retData.insert("point", curpos);
return retData;
}
}
......@@ -2013,7 +2020,7 @@ bool PcbCamCanvas::event(QEvent *iEvent)
if (d->mouseClickTimes == 0 && iEvent->type() == QEvent::MouseButtonPress ) {
QMouseEvent *evt = static_cast<QMouseEvent*>(iEvent);
if (evt->button() == Qt::LeftButton) {
QPointF sp = getSnapPoint(evt->pos());
QPointF sp = getSnapPoint(evt->pos()).value("point").toPointF();
d->measureLine.setP1(sp);
d->measureLine.setP2(d->measureLine.p1());
d->rubberBandRect.setTopLeft(sp);
......@@ -2024,12 +2031,12 @@ bool PcbCamCanvas::event(QEvent *iEvent)
}
else if (d->mouseClickTimes == 0 && iEvent->type() == QEvent::MouseMove) {
QMouseEvent *evt = static_cast<QMouseEvent*>(iEvent);
getSnapPoint(evt->pos());
getSnapPoint(evt->pos()).value("point").toPointF();
update();
}
else if (d->mouseClickTimes == 1 && iEvent->type() == QEvent::MouseMove) {
QMouseEvent *evt = static_cast<QMouseEvent*>(iEvent);
QPointF sp = getSnapPoint(evt->pos());
QPointF sp = getSnapPoint(evt->pos()).value("point").toPointF();
d->measureLine.setP2(sp);
d->rubberBandRect.setBottomRight(sp);
update();
......@@ -2242,7 +2249,7 @@ void PcbCamCanvas::paintEvent(QPaintEvent */*iEvent*/)
auto dispopt = d->displayOptions;
dispopt |= PcbCam::DisplayNegative;
QRectF srect;
for (auto hinfo : d->highlightBuffer) {
for (auto &hinfo : d->highlightBuffer) {
auto mat = hinfo.matrix * d->currentMatrix;
srect = mat.inverted().mapRect(QRectF(this->rect()));
PcbCamUtil::drawFeatures(&painter,
......@@ -2539,5 +2546,3 @@ void PcbCamCanvas::contextMenuEvent(QContextMenuEvent *event)
// }
}
TITAN_END_NAMESPACE
......@@ -7,7 +7,6 @@
#include <QEvent>
#include "../core/job.h"
TITAN_BEGIN_NAMESPACE
class PcbCamPopViewWindow;
......@@ -57,7 +56,7 @@ signals:
void displayUpdated();
void selectionChanged();
void keyPressed(const QString &iKey);
void snapFeatChanged(const QVariantMap &iInfo);
void snapFeatChanged(const QVariant &iInfo);
public slots:
void setJobData(PcbCamJob *iJob);
......@@ -148,7 +147,7 @@ public slots:
void setSnapFeatureType(PcbCam::FeatureTypes iType);
PcbCam::FeatureTypes snapFeatureType() const;
QPointF getSnapPoint(const QPoint &iCursorPos, int iSnapRange = 20, bool *oSnaped = nullptr);
QVariantMap getSnapPoint(const QPoint &iCursorPos, int iSnapRange = 20);
void getSnapPathsInRect(const QString &iStep, const QRectF &iRange, bool iIncludeStepRepeat, const QTransform &iMatrix, QPainterPath &oSnapFeatPaths, QPolygonF &oSnapFeatPoints) const;
void setDisplayOption(PcbCam::DisplayOptions iDispOption);
......@@ -197,6 +196,5 @@ private:
Q_DISABLE_COPY(PcbCamCanvas)
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_GRAPHVIEW_H
......@@ -4,14 +4,12 @@
#include <QHBoxLayout>
#include <QToolBar>
#include <QPushButton>
#include <QCloseEvent>
#include <QGraphicsDropShadowEffect>
#include <QPainter>
#include <QApplication>
#include "canvas.h"
#include <QDebug>
TITAN_BEGIN_NAMESPACE
static QIcon coloredIcon(const QIcon &iIcon, const QColor &iColor)
{
......@@ -99,7 +97,7 @@ protected:
};
PcbCamPopViewWindow::PcbCamPopViewWindow(const QRectF &iSourceRect, const QRect &iTargetRect, titan::PcbCamCanvas *iCanvas): QFrame(iCanvas),
PcbCamPopViewWindow::PcbCamPopViewWindow(const QRectF &iSourceRect, const QRect &iTargetRect, PcbCamCanvas *iCanvas): QFrame(iCanvas),
d_ptr(new PcbCamPopViewWindowPrivate(this))
{
Q_D(PcbCamPopViewWindow);
......@@ -411,8 +409,3 @@ void PcbCamPopViewWindow::onZoomOutClicked()
emit geometryChanged();
this->refresh();
}
TITAN_END_NAMESPACE
......@@ -2,18 +2,20 @@
#define TITAN_PCBCAM_POPVIEWWINDOW_H
#include "../titanpcbcamglobal.h"
#include <QFrame>
#include <QResizeEvent>
#include <QCloseEvent>
#include <QMoveEvent>
#include <QMouseEvent>
TITAN_BEGIN_NAMESPACE
class PcbCamCanvas;
class PcbCamPopViewWindowPrivate;
class PcbCamPopViewWindow : public QFrame
class TITAN_PCBCAM_EXPORT PcbCamPopViewWindow : public QFrame
{
Q_OBJECT
friend class PcbCamCanvas;
public:
explicit PcbCamPopViewWindow(const QRectF &iSourceRect, const QRect &iTargetRect, titan::PcbCamCanvas *iCanvas);
explicit PcbCamPopViewWindow(const QRectF &iSourceRect, const QRect &iTargetRect, PcbCamCanvas *iCanvas);
~PcbCamPopViewWindow();
void setSourceRect(const QRectF &iSourceRect);
QRectF sourceRect() const;
......@@ -54,6 +56,5 @@ private:
};
TITAN_END_NAMESPACE
#endif // TITAN_PCBCAM_POPVIEWWINDOW_H
#############################################################################
##
## Copyright (C) 2019 The Qt Company Ltd.
## Contact: http://www.qt.io/licensing/
##
## This file is part of the Qt for Python examples of the Qt Toolkit.
##
## $QT_BEGIN_LICENSE:BSD$
## You may use this file under the terms of the BSD license as follows:
##
## "Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions are
## met:
## * Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimer.
## * Redistributions in binary form must reproduce the above copyright
## notice, this list of conditions and the following disclaimer in
## the documentation and/or other materials provided with the
## distribution.
## * Neither the name of The Qt Company Ltd nor the names of its
## contributors may be used to endorse or promote products derived
## from this software without specific prior written permission.
##
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
##
## $QT_END_LICENSE$
##
#############################################################################
import os, glob, re, sys
from distutils import sysconfig
from enum import Enum
import glob
import os
import re
import sys
generic_error = (' Did you forget to activate your virtualenv? Or perhaps'
' you forgot to build / install PySide2 into your currently active Python'
PYSIDE = 'pyside6'
PYSIDE_MODULE = 'PySide6'
SHIBOKEN = 'shiboken6'
class Package(Enum):
SHIBOKEN_MODULE = 1
SHIBOKEN_GENERATOR = 2
PYSIDE_MODULE = 3
generic_error = ('Did you forget to activate your virtualenv? Or perhaps'
f' you forgot to build / install {PYSIDE_MODULE} into your currently active Python'
' environment?')
pyside2_error = 'Unable to locate PySide2.' + generic_error
shiboken2_module_error = 'Unable to locate shiboken2-module.' + generic_error
shiboken2_generator_error = 'Unable to locate shiboken2-generator.' + generic_error
pyside2_libs_error = 'Unable to locate the PySide2 shared libraries.' + generic_error
pyside_error = f'Unable to locate {PYSIDE_MODULE}. {generic_error}'
shiboken_module_error = f'Unable to locate {SHIBOKEN}-module. {generic_error}'
shiboken_generator_error = f'Unable to locate shiboken-generator. {generic_error}'
pyside_libs_error = f'Unable to locate the PySide shared libraries. {generic_error}'
python_link_error = 'Unable to locate the Python library for linking.'
python_include_error = 'Unable to locate the Python include headers directory.'
options = []
# option, function, error, description
options.append(("--shiboken2-module-path",
lambda: find_shiboken2_module(),
shiboken2_module_error,
"Print shiboken2 module location"))
options.append(("--shiboken2-generator-path",
lambda: find_shiboken2_generator(),
shiboken2_generator_error,
"Print shiboken2 generator location"))
options.append(("--pyside2-path", lambda: find_pyside2(), pyside2_error,
"Print PySide2 location"))
options.append(("--shiboken-module-path",
lambda: find_shiboken_module(),
shiboken_module_error,
"Print shiboken module location"))
options.append(("--shiboken-generator-path",
lambda: find_shiboken_generator(),
shiboken_generator_error,
"Print shiboken generator location"))
options.append(("--pyside-path", lambda: find_pyside(), pyside_error,
f"Print {PYSIDE_MODULE} location"))
options.append(("--python-include-path",
lambda: get_python_include_path(),
python_include_error,
"Print Python include path"))
options.append(("--shiboken2-generator-include-path",
lambda: get_package_include_path(Package.shiboken2_generator),
pyside2_error,
"Print shiboken2 generator include paths"))
options.append(("--pyside2-include-path",
lambda: get_package_include_path(Package.pyside2),
pyside2_error,
"Print PySide2 include paths"))
options.append(("--shiboken-generator-include-path",
lambda: get_package_include_path(Package.SHIBOKEN_GENERATOR),
pyside_error,
"Print shiboken generator include paths"))
options.append(("--pyside-include-path",
lambda: get_package_include_path(Package.PYSIDE_MODULE),
pyside_error,
"Print PySide6 include paths"))
options.append(("--python-link-flags-qmake", lambda: python_link_flags_qmake(), python_link_error,
"Print python link flags for qmake"))
options.append(("--python-link-flags-cmake", lambda: python_link_flags_cmake(), python_link_error,
"Print python link flags for cmake"))
options.append(("--shiboken2-module-qmake-lflags",
lambda: get_package_qmake_lflags(Package.shiboken2_module), pyside2_error,
"Print shiboken2 shared library link flags for qmake"))
options.append(("--pyside2-qmake-lflags",
lambda: get_package_qmake_lflags(Package.pyside2), pyside2_error,
"Print PySide2 shared library link flags for qmake"))
options.append(("--shiboken2-module-shared-libraries-qmake",
lambda: get_shared_libraries_qmake(Package.shiboken2_module), pyside2_libs_error,
"Print paths of shiboken2 shared libraries (.so's, .dylib's, .dll's) for qmake"))
options.append(("--shiboken2-module-shared-libraries-cmake",
lambda: get_shared_libraries_cmake(Package.shiboken2_module), pyside2_libs_error,
"Print paths of shiboken2 shared libraries (.so's, .dylib's, .dll's) for cmake"))
options.append(("--pyside2-shared-libraries-qmake",
lambda: get_shared_libraries_qmake(Package.pyside2), pyside2_libs_error,
"Print paths of PySide2 shared libraries (.so's, .dylib's, .dll's) for qmake"))
options.append(("--pyside2-shared-libraries-cmake",
lambda: get_shared_libraries_cmake(Package.pyside2), pyside2_libs_error,
"Print paths of PySide2 shared libraries (.so's, .dylib's, .dll's) for cmake"))
options.append(("--shiboken-module-qmake-lflags",
lambda: get_package_qmake_lflags(Package.SHIBOKEN_MODULE), pyside_error,
"Print shiboken6 shared library link flags for qmake"))
options.append(("--pyside-qmake-lflags",
lambda: get_package_qmake_lflags(Package.PYSIDE_MODULE), pyside_error,
"Print PySide6 shared library link flags for qmake"))
options.append(("--shiboken-module-shared-libraries-qmake",
lambda: get_shared_libraries_qmake(Package.SHIBOKEN_MODULE), pyside_libs_error,
"Print paths of shiboken shared libraries (.so's, .dylib's, .dll's) for qmake"))
options.append(("--shiboken-module-shared-libraries-cmake",
lambda: get_shared_libraries_cmake(Package.SHIBOKEN_MODULE), pyside_libs_error,
"Print paths of shiboken shared libraries (.so's, .dylib's, .dll's) for cmake"))
options.append(("--pyside-shared-libraries-qmake",
lambda: get_shared_libraries_qmake(Package.PYSIDE_MODULE), pyside_libs_error,
"Print paths of f{PYSIDE_MODULE} shared libraries (.so's, .dylib's, .dll's) for qmake"))
options.append(("--pyside-shared-libraries-cmake",
lambda: get_shared_libraries_cmake(Package.PYSIDE_MODULE), pyside_libs_error,
f"Print paths of {PYSIDE_MODULE} shared libraries (.so's, .dylib's, .dll's) for cmake"))
options_usage = ''
for i, (flag, _, _, description) in enumerate(options):
options_usage += ' {:<45} {}'.format(flag, description)
options_usage += f' {flag:<45} {description}'
if i < len(options) - 1:
options_usage += '\n'
usage = """
Utility to determine include/link options of shiboken2/PySide2 and Python for qmake/CMake projects
that would like to embed or build custom shiboken2/PySide2 bindings.
usage = f"""
Utility to determine include/link options of shiboken/PySide and Python for qmake/CMake projects
that would like to embed or build custom shiboken/PySide bindings.
Usage: pyside2_config.py [option]
Usage: pyside_config.py [option]
Options:
{}
{options_usage}
-a Print all options and their values
--help/-h Print this help
""".format(options_usage)
"""
option = sys.argv[1] if len(sys.argv) == 2 else '-a'
if option == '-h' or option == '--help':
......@@ -127,12 +102,6 @@ if option == '-h' or option == '--help':
sys.exit(0)
class Package(object):
shiboken2_module = 1
shiboken2_generator = 2
pyside2 = 3
def clean_path(path):
return path if sys.platform != 'win32' else path.replace('\\', '/')
......@@ -148,15 +117,8 @@ def shared_library_suffix():
def import_suffixes():
if (sys.version_info >= (3, 4)):
import importlib.machinery
return importlib.machinery.EXTENSION_SUFFIXES
else:
import imp
result = []
for t in imp.get_suffixes():
result.append(t[0])
return result
def is_debug():
......@@ -172,7 +134,7 @@ def shared_library_glob_pattern():
def filter_shared_libraries(libs_list):
def predicate(lib_name):
basename = os.path.basename(lib_name)
if 'shiboken' in basename or 'pyside2' in basename:
if 'shiboken' in basename or 'pyside6' in basename:
return True
return False
result = [lib for lib in libs_list if predicate(lib)]
......@@ -196,26 +158,26 @@ def link_option(lib):
return link
# Locate PySide2 via sys.path package path.
def find_pyside2():
return find_package_path("PySide2")
# Locate PySide6 via sys.path package path.
def find_pyside():
return find_package_path(PYSIDE_MODULE)
def find_shiboken2_module():
return find_package_path("shiboken2")
def find_shiboken_module():
return find_package_path(SHIBOKEN)
def find_shiboken2_generator():
return find_package_path("shiboken2_generator")
def find_shiboken_generator():
return find_package_path(f"{SHIBOKEN}_generator")
def find_package(which_package):
if which_package == Package.shiboken2_module:
return find_shiboken2_module()
if which_package == Package.shiboken2_generator:
return find_shiboken2_generator()
if which_package == Package.pyside2:
return find_pyside2()
if which_package == Package.SHIBOKEN_MODULE:
return find_shiboken_module()
if which_package == Package.SHIBOKEN_GENERATOR:
return find_shiboken_generator()
if which_package == Package.PYSIDE_MODULE:
return find_pyside()
return None
......@@ -228,7 +190,7 @@ def find_package_path(dir_name):
return None
# Return version as "3.5"
# Return version as "3.6"
def python_version():
return str(sys.version_info[0]) + '.' + str(sys.version_info[1])
......@@ -247,20 +209,24 @@ def python_link_flags_qmake():
for d in libdir.split("\\"):
if " " in d:
libdir = libdir.replace(d, d.split(" ")[0][:-1]+"~1")
return '-L{} -l{}'.format(libdir, flags['lib'])
lib_flags = flags['lib']
return f'-L{libdir} -l{lib_flags}'
elif sys.platform == 'darwin':
return '-L{} -l{}'.format(flags['libdir'], flags['lib'])
libdir = flags['libdir']
lib_flags = flags['lib']
return f'-L{libdir} -l{lib_flags}'
else:
# Linux and anything else
return '-L{} -l{}'.format(flags['libdir'], flags['lib'])
libdir = flags['libdir']
lib_flags = flags['lib']
return f'-L{libdir} -l{lib_flags}'
def python_link_flags_cmake():
flags = python_link_data()
libdir = flags['libdir']
lib = re.sub(r'.dll$', '.lib', flags['lib'])
return '{};{}'.format(libdir, lib)
return f'{libdir};{lib}'
def python_link_data():
......@@ -276,18 +242,14 @@ def python_link_data():
flags['libdir'] = libdir
if sys.platform == 'win32':
suffix = '_d' if is_debug() else ''
flags['lib'] = 'python{}{}'.format(version_no_dots, suffix)
flags['lib'] = f'python{version_no_dots}{suffix}'
elif sys.platform == 'darwin':
flags['lib'] = 'python{}'.format(version)
flags['lib'] = f'python{version}'
# Linux and anything else
else:
if sys.version_info[0] < 3:
suffix = '_d' if is_debug() else ''
flags['lib'] = 'python{}{}'.format(version, suffix)
else:
flags['lib'] = 'python{}{}'.format(version, sys.abiflags)
flags['lib'] = f'python{version}{sys.abiflags}'
return flags
......@@ -297,7 +259,7 @@ def get_package_include_path(which_package):
if package_path is None:
return None
includes = "{0}/include".format(package_path)
includes = f"{package_path}/include"
return includes
......@@ -307,7 +269,7 @@ def get_package_qmake_lflags(which_package):
if package_path is None:
return None
link = "-L{}".format(package_path)
link = f"-L{package_path}"
glob_result = glob.glob(os.path.join(package_path, shared_library_glob_pattern()))
for lib in filter_shared_libraries(glob_result):
link += ' '
......@@ -368,5 +330,5 @@ for argument, handler, error, _ in options:
line = handler_result
if print_all:
line = "{:<40}: ".format(argument) + line
line = f"{argument:<40}: {line}"
print(line)
import os
import platform
import subprocess
import shutil
from pathlib import Path
from setuptools import setup, Extension, find_namespace_packages
from setuptools.command.build_ext import build_ext
from PySide6.support.generate_pyi import generate_all_pyi
# ---- PROJECT SETTING ---------- #
NAMESPACE = "timp"
PROJECT = "pcbcam"
VERSION = "1.0.0"
DESCRIPTION = "pcbcam lib"
# ---- END OF PROJECT SETTING ----#
class CMakeExtension(Extension):
""" CMake编译扩展类 """
def __init__(self, name: str, namespace: str = "", sourcedir: str = ""):
Extension.__init__(self, name, sources=[])
self.namespace = namespace
self.sourcedir = os.path.abspath(sourcedir)
class CMakeBuild(build_ext):
""" CMake编译方法类 """
def build_extension(self, ext):
# setuptools 打包文件时创建的临时路径
py_build_dir = Path(os.path.abspath(self.build_lib))
if ext.namespace:
py_build_dir = py_build_dir.joinpath(ext.namespace)
py_build_dir = py_build_dir.joinpath(ext.name)
# c++源码所在路径,在不同系统下使用不同的编译目录
build_temp = Path(ext.sourcedir).joinpath('../build')
if not build_temp.exists():
os.makedirs(build_temp)
# 追加QT路径至PATH环境变中, 以便CMake的FindPackage能够找到Qt相关依赖
qt_dir = self.get_qt_dir()
qt_bin = os.path.join(qt_dir, "bin")
path_sep = ';' if platform.system() == "Windows" else ':'
env_path = qt_bin + path_sep + os.environ.get("PATH")
os.environ.update(PATH=env_path)
# Windows下初始化Visual Studio C++编译环境
self.init_msvc_env()
# 执行CMake进行编译
subprocess.check_call('cmake .. -B. -G Ninja -D CMAKE_BUILD_TYPE=Release', cwd=build_temp)
subprocess.check_call(['ninja'], cwd=build_temp)
subprocess.check_call(['ninja', 'install'], cwd=build_temp)
# 拷贝动态库至打包目录
# libray_files = []
# if platform.system() == "Windows":
# libray_files.append("{}.pyd".format(ext.name))
# libray_files.append("lib{}.dll".format(ext.name))
# elif platform.system() == "Darwin":
# libray_files.append("{}.so".format(ext.name))
# libray_files.append("lib{}.dylib".format(ext.name))
# else:
# libray_files.append("{}.so".format(ext.name))
# libray_files.append("lib{}.so".format(ext.name))
# print('copying dynamic library file')
# pak_dir = Path(ext.sourcedir).parent.joinpath(ext.namespace, ext.name)
# for lib in libray_files:
# src_file = pak_dir.joinpath(lib)
# print(f'copying {src_file} -> {py_build_dir}')
# shutil.copy(src_file, py_build_dir)
def get_qt_dir(self) -> str:
""" 获取QT路径 """
timp_qt_dir = ''
if 'TIMP_QT_DIR' in os.environ:
timp_qt_dir = os.environ.get('TIMP_QT_DIR')
elif 'QT6_DIR' in os.environ:
timp_qt_dir = os.environ.get('QT6_DIR')
elif 'QT_DIR' in os.environ:
timp_qt_dir = os.environ.get('QT_DIR')
if not timp_qt_dir:
raise Exception('Please set TIMP_QT_DIR into environment')
return timp_qt_dir
def init_msvc_env(self) -> None:
""" 初始化Visual Studio C++ 编译环境"""
if platform.system() != "Windows":
return
vcvar = ''
qt_dir = self.get_qt_dir()
if 'msvc2015' in qt_dir:
vcvar = '"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat" amd64'
elif 'msvc2019' in qt_dir:
vcvar = '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat"'
pipe = os.popen("{0} && {1}".format(vcvar, 'set'))
output = pipe.read()
pipe.close()
env = dict((e[0].upper(), e[1]) for e in [p.rstrip().split("=", 1) for p in output.split('\n')] if len(e) == 2)
os.environ.update(env)
setup(
name="{}.{}".format(NAMESPACE, PROJECT),
version=VERSION,
author="toplinker",
author_email="service@topibd.com",
description=DESCRIPTION,
long_description=DESCRIPTION,
ext_modules=[CMakeExtension(name=PROJECT, namespace=NAMESPACE, sourcedir="lib")],
cmdclass={"build_ext": CMakeBuild},
package_dir={'': 'build'},
packages=find_namespace_packages(where='build', include=["{}.{}".format(NAMESPACE, PROJECT)]),
python_requires='>=3.8',
install_requires=[
'PySide6',
'shiboken6',
],
setup_requires=[
'PySide6',
'shiboken6',
'shiboken6_generator',
],
tests_require=[],
extras_require={},
dependency_links=["http://nexus.topibd.net/repository/pypi-public/simple"],
zip_safe=False,
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment