From: nds Date: Sun, 18 Mar 2018 12:34:17 +0000 (+0300) Subject: 0029571: Samples: build qt samples together with OCCT X-Git-Tag: V7_3_0_beta~45 X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=1fa1615244319b1e0ede0aba9b86f0dc1d3672a9;p=occt-copy.git 0029571: Samples: build qt samples together with OCCT Extending CMake procedure by 'BUILD_MODULE_QtSamples' variable to switch on qt samples build. Implementation required: - union of occt_toolkit_tool.cmake and occt_toolkit.cmake files; - correction of qt samples sources by adding path to Qt 'plugins' folder. It helps to avoid definition of additional variable (QT_QPA_PLATFORM_PLUGIN_PATH) when staring sample.bat for qt samples; - executable processing is extended in cmake procedure by providing 'EXECUTABLE_PROJECT' variable. Now we need not specify custom processing for DRAWEXE in occt_toolkit.cmake --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 2dbe95ff2c..beee192894 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -346,6 +346,7 @@ separate_arguments (BUILD_ADDITIONAL_TOOLKITS) if (MSVC) set (BUILD_MODULE_MfcSamples OFF CACHE BOOL "${BUILD_MODULE_MfcSamples_DESCR}") endif() +set (BUILD_MODULE_QtSamples OFF CACHE BOOL "${BUILD_MODULE_QtSamples_DESCR}") set (BUILD_Inspector OFF CACHE BOOL "${BUILD_Inspector_DESCR}") @@ -381,7 +382,7 @@ endif() # include the patched or original list of modules # list _TOOLKITS is created foreach module and contains its toolkits # list will contain all modules -OCCT_MODULES_AND_TOOLKITS (OCCT_MODULES) +OCCT_MODULES_AND_TOOLKITS (MODULES "TOOLKITS" OCCT_MODULES) foreach (OCCT_MODULE ${OCCT_MODULES}) BUILD_MODULE (${OCCT_MODULE}) @@ -775,30 +776,31 @@ else() set (SCRIPT_EXT sh) endif() +if (BUILD_Inspector OR BUILD_MODULE_QtSamples) + # check qt 3rdparty path + add_definitions (-DHAVE_QT) + OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/qt") + message (STATUS "Info: Qt is used by OCCT") +else() + OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_QT") + OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TQTMALLOC") + OCCT_CHECK_AND_UNSET ("INSTALL_QT") +endif() + # OCCT tools # include the patched or original list of tools # list _TOOLKITS is created foreach tool and contains its toolkits # list will contain all tools -if (NOT BUILD_Inspector) - OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_QT") - OCCT_CHECK_AND_UNSET_GROUP ("3RDPARTY_TQTMALLOC") - OCCT_CHECK_AND_UNSET ("INSTALL_QT") -else() - OCCT_TOOLS_AND_TOOLKITS (OCCT_TOOLS) +if (BUILD_Inspector) + OCCT_MODULES_AND_TOOLKITS (TOOLS "TOOL_TOOLKITS" OCCT_TOOLS) foreach (OCCT_TOOL ${OCCT_TOOLS}) list (APPEND BUILD_TOOL_TOOLKITS ${${OCCT_TOOL}_TOOL_TOOLKITS}) endforeach() - # collect all the headers to /inc folder + # collect all the headers to /inc/inspector folder string(TIMESTAMP CURRENT_TIME "%H:%M:%S") - message (STATUS "\nInfo: \(${CURRENT_TIME}\) Start collecting all OCCT tool header files into ${CMAKE_BINARY_DIR}/tools/inc ...") + message (STATUS "\nInfo: \(${CURRENT_TIME}\) Start collecting all OCCT tool header files into ${CMAKE_BINARY_DIR}/inc/inspector ...") COLLECT_AND_INSTALL_OCCT_HEADER_FILES ("${CMAKE_BINARY_DIR}" "${BUILD_TOOL_TOOLKITS}" "${CMAKE_SOURCE_DIR}/tools" "${INSTALL_DIR_INCLUDE}/inspector") - - - # check qt 3rdparty path - add_definitions (-DHAVE_QT) - OCCT_INCLUDE_CMAKE_FILE ("adm/cmake/qt") - message (STATUS "Info: Qt is used by OCCT") endif() # OCCT samples @@ -896,7 +898,7 @@ OCCT_CONFIGURE_AND_INSTALL ("adm/templates/custom.install.${SCRIPT_EXT}.in" "${S # write current custom.bat/sh (for build directory) OCCT_CONFIGURE ("adm/templates/custom.build.${SCRIPT_EXT}.in" "${SUB_CUSTOM_NAME}") -if (BUILD_MODULE_MfcSamples) +if (BUILD_MODULE_MfcSamples OR BUILD_MODULE_QtSamples) OCCT_INSTALL_FILE_OR_DIR ("adm/templates/sample.bat" "${INSTALL_DIR_SCRIPT}") OCCT_COPY_FILE_OR_DIR ("adm/templates/sample.bat" "${CMAKE_BINARY_DIR}") endif() @@ -924,6 +926,15 @@ foreach(RESOURCE ${RESOURCES}) endif() endforeach() +if (BUILD_MODULE_QtSamples) + FILE_TO_LIST ("adm/SAMPLES_RESOURCES" SAMPLES_RESOURCES) + foreach(RESOURCE ${SAMPLES_RESOURCES}) + OCCT_INSTALL_FILE_OR_DIR ("samples/${RESOURCE}" "${INSTALL_DIR_RESOURCE}/samples") + #message("Copy Sample resources: samples/${RESOURCE} into ${INSTALL_DIR_RESOURCE}/samples") + endforeach() +endif() + + # patch installed DrawDefault file if BUILD_SHARED_LIBRARY_NAME_POSTFIX is changed if (NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "") OCCT_UPDATE_DRAW_DEFAULT_FILE() @@ -968,9 +979,11 @@ endif() message (STATUS "Info: \(${CURRENT_TIME}\) OCCT toolkits processed") # samples do not support patch usage -if (BUILD_MODULE_MfcSamples) +if (BUILD_MODULE_MfcSamples OR BUILD_MODULE_QtSamples) set (OCCT_ROOT ${CMAKE_SOURCE_DIR}) +endif() +if (BUILD_MODULE_MfcSamples) set (MFC_STANDARD_SAMPLES_DIR ${OCCT_ROOT}/samples/mfc/standard) set (COMMON_WINMAIN_FILE ${MFC_STANDARD_SAMPLES_DIR}/Common/Winmain.cpp) @@ -989,6 +1002,33 @@ if (BUILD_MODULE_MfcSamples) message (STATUS "Info: \(${CURRENT_TIME}\) MFC Sample projects added") endif() +OCCT_MODULES_AND_TOOLKITS (SAMPLES "SAMPLES_TOOLKITS" OCCT_SAMPLES) + +if (BUILD_MODULE_QtSamples) + if (NOT Qt5_FOUND OR NOT USE_GLES2) + list (REMOVE_ITEM qt_SAMPLES_TOOLKITS AndroidQt) + message (STATUS "Info: AndroidQt sample excluded due to Qt5 or GLES2 usage are disabled") + endif() + + if (NOT BUILD_Inspector) + list (REMOVE_ITEM tools_SAMPLES_TOOLKITS TInspectorEXE) + message (STATUS "Info: TInspectorEXE sample excluded due to BUILD_Inspector is disabled") + endif() + + foreach (OCCT_SAMPLE ${OCCT_SAMPLES}) + list (APPEND BUILD_SAMPLE_TOOLKITS ${${OCCT_SAMPLE}_SAMPLES_TOOLKITS}) + + # collect all the headers to /inc/samples folder + string(TIMESTAMP CURRENT_TIME "%H:%M:%S") + message (STATUS "Info: \(${CURRENT_TIME}\) ${OCCT_SAMPLE} Sample projects added") + + # include patched toolkit projects or original ones + foreach (BUILD_SAMPLE_TOOLKIT ${${OCCT_SAMPLE}_SAMPLES_TOOLKITS}) + OCCT_ADD_SUBDIRECTORY ("samples/${OCCT_SAMPLE}/${BUILD_SAMPLE_TOOLKIT}") + endforeach() + endforeach() +endif() + if (BUILD_MODULE_UwpSample) add_subdirectory(samples/xaml) endif() @@ -1003,11 +1043,6 @@ if (BUILD_TOOL_TOOLKITS) PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE GROUP_EXECUTE WORLD_READ WORLD_WRITE WORLD_EXECUTE) endif() - set (BUILD_SAMPLE_TOOLKITS TInspectorEXE) - foreach (BUILD_SAMPLE_TOOL_TOOLKIT ${BUILD_SAMPLE_TOOLKITS}) - OCCT_ADD_SUBDIRECTORY ("samples/tools/${BUILD_SAMPLE_TOOL_TOOLKIT}") - endforeach() - # patch TInspectorEXE OCCT_CONFIGURE ("adm/templates/TInspectorEXE.vcxproj.user.in" "${CMAKE_BINARY_DIR}/samples/tools/TInspectorEXE/TInspectorEXE.vcxproj.user") endif() diff --git a/adm/SAMPLES b/adm/SAMPLES new file mode 100644 index 0000000000..d9f7257e5c --- /dev/null +++ b/adm/SAMPLES @@ -0,0 +1,2 @@ +qt AndroidQt FuncDemo IESample Tutorial +tools TInspectorEXE \ No newline at end of file diff --git a/adm/SAMPLES_RESOURCES b/adm/SAMPLES_RESOURCES new file mode 100644 index 0000000000..a353f3f6e6 --- /dev/null +++ b/adm/SAMPLES_RESOURCES @@ -0,0 +1,2 @@ +qt/Common/res/ +qt/Tutorial/res/ \ No newline at end of file diff --git a/adm/cmake/occt_macros.cmake b/adm/cmake/occt_macros.cmake index faea1709d0..1ba4f798bc 100644 --- a/adm/cmake/occt_macros.cmake +++ b/adm/cmake/occt_macros.cmake @@ -502,11 +502,11 @@ function (OCCT_TOOLKIT_FULL_DEP TOOLKIT_NAME TOOLKIT_FULL_DEPS) set (${TOOLKIT_FULL_DEPS} ${LOCAL_TOOLKIT_FULL_DEPS} PARENT_SCOPE) endfunction() -# Function to get list of modules and toolkits from file adm/MODULES. +# Function to get list of modules/toolkits/samples from file adm/${FILE_NAME}. # Creates list <$MODULE_LIST> to store list of MODULES and -# _TOOLKITS foreach module to store its toolkits. -function (OCCT_MODULES_AND_TOOLKITS MODULE_LIST) - FILE_TO_LIST ("adm/MODULES" FILE_CONTENT) +# _TOOLKITS foreach module to store its toolkits, where "TOOLKITS" is defined by TOOLKITS_NAME_SUFFIX. +function (OCCT_MODULES_AND_TOOLKITS FILE_NAME TOOLKITS_NAME_SUFFIX MODULE_LIST) + FILE_TO_LIST ("adm/${FILE_NAME}" FILE_CONTENT) foreach (CONTENT_LINE ${FILE_CONTENT}) string (REPLACE " " ";" CONTENT_LINE ${CONTENT_LINE}) @@ -514,30 +514,12 @@ function (OCCT_MODULES_AND_TOOLKITS MODULE_LIST) list (REMOVE_AT CONTENT_LINE 0) list (APPEND ${MODULE_LIST} ${MODULE_NAME}) # (!) REMOVE THE LINE BELOW (implicit variables) - set (${MODULE_NAME}_TOOLKITS ${CONTENT_LINE} PARENT_SCOPE) + set (${MODULE_NAME}_${TOOLKITS_NAME_SUFFIX} ${CONTENT_LINE} PARENT_SCOPE) endforeach() set (${MODULE_LIST} ${${MODULE_LIST}} PARENT_SCOPE) endfunction() -# Function to get list of tools and toolkits from file adm/TOOLS. -# Creates list <$TOOL_LIST> to store list of TOOLS and -# _TOOLKITS foreach tool to store its toolkits. -function (OCCT_TOOLS_AND_TOOLKITS TOOL_LIST) - FILE_TO_LIST ("adm/TOOLS" FILE_CONTENT) - - foreach (CONTENT_LINE ${FILE_CONTENT}) - string (REPLACE " " ";" CONTENT_LINE ${CONTENT_LINE}) - list (GET CONTENT_LINE 0 TOOL_NAME) - list (REMOVE_AT CONTENT_LINE 0) - list (APPEND ${TOOL_LIST} ${TOOL_NAME}) - # (!) REMOVE THE LINE BELOW (implicit variables) - set (${TOOL_NAME}_TOOL_TOOLKITS ${CONTENT_LINE} PARENT_SCOPE) - endforeach() - - set (${TOOL_LIST} ${${TOOL_LIST}} PARENT_SCOPE) -endfunction() - # Returns OCC version string from file Standard_Version.hxx (if available) function (OCC_VERSION OCC_VERSION_MAJOR OCC_VERSION_MINOR OCC_VERSION_MAINTENANCE OCC_VERSION_DEVELOPMENT OCC_VERSION_STRING_EXT) diff --git a/adm/cmake/occt_toolkit.cmake b/adm/cmake/occt_toolkit.cmake index 45107551c7..689ed40a21 100644 --- a/adm/cmake/occt_toolkit.cmake +++ b/adm/cmake/occt_toolkit.cmake @@ -1,12 +1,40 @@ # script for each OCCT toolkit +# filling some variables by default values(src) or using custom(tools, samples) +set (RELATIVE_SOURCES_DIR "${RELATIVE_DIR}") +if ("${RELATIVE_SOURCES_DIR}" STREQUAL "") + #if it is not defined, use default directory + set (RELATIVE_SOURCES_DIR "src") +endif() + +set (OCC_MODULES_LIST "${MODULES_LIST}") +if ("${OCC_MODULES_LIST}" STREQUAL "") + set (OCC_MODULES_LIST ${OCCT_MODULES}) +endif() + +set (OCC_TARGET_FOLDER "${TARGET_FOLDER}") +if ("${OCC_TARGET_FOLDER}" STREQUAL "") + set (OCC_TARGET_FOLDER "Modules") +endif() + +set (OCCT_TOOLKITS_NAME_SUFFIX "${TOOLKITS_NAME_SUFFIX}") +if ("${OCCT_TOOLKITS_NAME_SUFFIX}" STREQUAL "") + set (OCCT_TOOLKITS_NAME_SUFFIX "TOOLKITS") +endif() + # parce PACKAGES file -if ("${PROJECT_NAME}" STREQUAL DRAWEXE) - set (USED_PACKAGES DRAWEXE) -else() - FILE_TO_LIST ("src/${PROJECT_NAME}/PACKAGES" USED_PACKAGES) +FILE_TO_LIST ("${RELATIVE_SOURCES_DIR}/${PROJECT_NAME}/PACKAGES" USED_PACKAGES) +if ("${USED_PACKAGES}" STREQUAL "") + set (USED_PACKAGES ${PROJECT_NAME}) endif() +if (USE_QT) + # Qt dependencies + OCCT_INCLUDE_CMAKE_FILE (adm/cmake/qt_macro) + FIND_QT_PACKAGE(PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT_INCLUDES) + include_directories("${PROJECT_INCLUDES}") +endif(USE_QT) + set (PRECOMPILED_DEFS) if (NOT BUILD_SHARED_LIBS) @@ -17,16 +45,26 @@ if (NOT BUILD_SHARED_LIBS) endif() # Get all used packages from toolkit +UNSET(RESOURCE_FILES) foreach (OCCT_PACKAGE ${USED_PACKAGES}) - + + #remove part after "/" in the OCCT_PACKAGE variable if exists + string (FIND "${OCCT_PACKAGE}" "/" _index) + if (_index GREATER -1) + math (EXPR _index "${_index}") + string (SUBSTRING "${OCCT_PACKAGE}" 0 ${_index} OCCT_PACKAGE_NAME) + else() + set (OCCT_PACKAGE_NAME "${OCCT_PACKAGE}") + endif() + # TKService contains platform-dependent packages: Xw and WNT if ((WIN32 AND "${OCCT_PACKAGE}" STREQUAL "Xw") OR (NOT WIN32 AND "${OCCT_PACKAGE}" STREQUAL "WNT")) # do nothing else() -# if (WIN32) -# list (APPEND PRECOMPILED_DEFS "-D__${OCCT_PACKAGE}_DLL") -# endif() + if (WIN32) + list (APPEND PRECOMPILED_DEFS "-D__${OCCT_PACKAGE_NAME}_DLL") + endif() set (SOURCE_FILES) set (HEADER_FILES) @@ -35,11 +73,11 @@ foreach (OCCT_PACKAGE ${USED_PACKAGES}) if (${BUILD_YACCLEX}) # flex files - OCCT_ORIGIN_AND_PATCHED_FILES ("src/${OCCT_PACKAGE}" "*[.]lex" SOURCE_FILES_FLEX) + OCCT_ORIGIN_AND_PATCHED_FILES ("${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}" "*[.]lex" SOURCE_FILES_FLEX) list (LENGTH SOURCE_FILES_FLEX SOURCE_FILES_FLEX_LEN) # bison files - OCCT_ORIGIN_AND_PATCHED_FILES ("src/${OCCT_PACKAGE}" "*[.]yacc" SOURCE_FILES_BISON) + OCCT_ORIGIN_AND_PATCHED_FILES ("${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}" "*[.]yacc" SOURCE_FILES_BISON) list (LENGTH SOURCE_FILES_BISON SOURCE_FILES_BISON_LEN) if (${SOURCE_FILES_FLEX_LEN} EQUAL ${SOURCE_FILES_BISON_LEN} AND NOT ${SOURCE_FILES_FLEX_LEN} EQUAL 0) @@ -61,8 +99,8 @@ foreach (OCCT_PACKAGE ${USED_PACKAGES}) if (EXISTS "${CURRENT_FLEX_FILE}" AND EXISTS "${CURRENT_BISON_FILE}" AND ${ARE_FILES_EQUAL}) set (BISON_OUTPUT_FILE ${CURRENT_BISON_FILE_NAME}.tab.c) set (FLEX_OUTPUT_FILE lex.${CURRENT_FLEX_FILE_NAME}.c) - BISON_TARGET (Parser_${CURRENT_BISON_FILE_NAME} ${CURRENT_BISON_FILE} ${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${BISON_OUTPUT_FILE} COMPILE_FLAGS "-p ${CURRENT_BISON_FILE_NAME}") - FLEX_TARGET (Scanner_${CURRENT_FLEX_FILE_NAME} ${CURRENT_FLEX_FILE} ${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${FLEX_OUTPUT_FILE} COMPILE_FLAGS "-P${CURRENT_FLEX_FILE_NAME}") + BISON_TARGET (Parser_${CURRENT_BISON_FILE_NAME} ${CURRENT_BISON_FILE} ${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${BISON_OUTPUT_FILE} COMPILE_FLAGS "-p ${CURRENT_BISON_FILE_NAME}") + FLEX_TARGET (Scanner_${CURRENT_FLEX_FILE_NAME} ${CURRENT_FLEX_FILE} ${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${FLEX_OUTPUT_FILE} COMPILE_FLAGS "-P${CURRENT_FLEX_FILE_NAME}") ADD_FLEX_BISON_DEPENDENCY (Scanner_${CURRENT_FLEX_FILE_NAME} Parser_${CURRENT_BISON_FILE_NAME}) list (APPEND SOURCE_FILES ${BISON_OUTPUT_FILE} ${FLEX_OUTPUT_FILE}) @@ -72,23 +110,23 @@ foreach (OCCT_PACKAGE ${USED_PACKAGES}) endif() # header files - if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES") - file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h") - file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx") - file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx") + if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES") + file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h") + file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx") + file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx") - file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c") + file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c") if(APPLE) - file (STRINGS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm") + file (STRINGS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm") endif() else() - file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h") - file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx") - file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx") + file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h") + file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx") + file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx") - file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c") + file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c") if(APPLE) - file (STRINGS "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm") + file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm") endif() endif() @@ -99,26 +137,36 @@ foreach (OCCT_PACKAGE ${USED_PACKAGES}) endif() foreach(HEADER_FILE ${HEADER_FILES}) - if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}") - message (STATUS "Info: consider patched file: ${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}") - list (APPEND USED_INCFILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}") - SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${HEADER_FILE}") + if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}") + message (STATUS "Info: consider patched file: ${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}") + list (APPEND USED_INCFILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}") + SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE_NAME}" FILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}") else() - list (APPEND USED_INCFILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}") - SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${HEADER_FILE}") + list (APPEND USED_INCFILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}") + SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE_NAME}" FILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}") endif() endforeach() foreach(SOURCE_FILE ${SOURCE_FILES}) - if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}") - message (STATUS "Info: consider patched file: ${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}") - list (APPEND USED_SRCFILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}") - SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${BUILD_PATCH}/src/${OCCT_PACKAGE}/${SOURCE_FILE}") + if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}") + message (STATUS "Info: consider patched file: ${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}") + list (APPEND USED_SRCFILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}") + SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE_NAME}" FILES "${BUILD_PATCH}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}") else() - list (APPEND USED_SRCFILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}") - SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/src/${OCCT_PACKAGE}/${SOURCE_FILE}") + list (APPEND USED_SRCFILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}") + SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE_NAME}" FILES "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}") endif() endforeach() + + if (USE_QT) + FIND_AND_INSTALL_QT_RESOURCES (${OCCT_PACKAGE} RESOURCE_FILES) + #message("Qt Resource files are: ${QT_RESOURCE_FILES} in ${OCCT_PACKAGE}") + endif(USE_QT) + + #message("Resource files are: ${RESOURCE_FILES} in ${OCCT_PACKAGE}") + foreach(RESOURCE_FILE ${RESOURCE_FILES}) + SOURCE_GROUP ("Resource Files\\${OCCT_PACKAGE_NAME}" FILES "${RESOURCE_FILE}") + endforeach() endif() endforeach() string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}") @@ -135,8 +183,9 @@ if (MSVC) endif() set (CURRENT_MODULE) -foreach (OCCT_MODULE ${OCCT_MODULES}) - list (FIND ${OCCT_MODULE}_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT) +foreach (OCCT_MODULE ${OCC_MODULES_LIST}) + list (FIND ${OCCT_MODULE}_${OCCT_TOOLKITS_NAME_SUFFIX} ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT) + if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1) set (CURRENT_MODULE ${OCCT_MODULE}) endif() @@ -146,13 +195,18 @@ if (WIN32) OCCT_INSERT_CODE_FOR_TARGET () endif() -if ("${PROJECT_NAME}" STREQUAL "DRAWEXE") - add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE}) +if (USE_QT) + FIND_AND_WRAP_MOC_FILES("${USED_INCFILES}" "${PROJECT_NAME}_MOC_FILES") + #message("MOC files: ${${PROJECT_NAME}_MOC_FILES}") +endif (USE_QT) + +if (EXECUTABLE_PROJECT) + add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RESOURCE_FILES} ${${PROJECT_NAME}_MOC_FILES}) install (TARGETS ${PROJECT_NAME} DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}") else() - add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE}) + add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RESOURCE_FILES} ${${PROJECT_NAME}_MOC_FILES}) if (MSVC) install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb @@ -181,7 +235,7 @@ else() endif() if (CURRENT_MODULE) - set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "Modules/${CURRENT_MODULE}") + set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "${OCC_TARGET_FOLDER}/${CURRENT_MODULE}") set_target_properties (${PROJECT_NAME} PROPERTIES MODULE "${CURRENT_MODULE}") if (APPLE) if (NOT "${INSTALL_NAME_DIR}" STREQUAL "") @@ -207,7 +261,7 @@ set (USED_TOOLKITS_BY_CURRENT_PROJECT) set (USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT) # parce EXTERNLIB file -FILE_TO_LIST ("src/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS) +FILE_TO_LIST ("${RELATIVE_SOURCES_DIR}/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS) foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS}) string (REGEX MATCH "^ *#" COMMENT_FOUND ${USED_ITEM}) if (NOT COMMENT_FOUND) @@ -303,6 +357,15 @@ if (BUILD_SHARED_LIBS) target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT}) endif() +if (USE_QT) + foreach (PROJECT_LIBRARY_DEBUG ${PROJECT_LIBRARIES_DEBUG}) + target_link_libraries (${PROJECT_NAME} debug ${PROJECT_LIBRARY_DEBUG}) + endforeach() + foreach (PROJECT_LIBRARY_RELEASE ${PROJECT_LIBRARIES_RELEASE}) + target_link_libraries (${PROJECT_NAME} optimized ${PROJECT_LIBRARY_RELEASE}) + endforeach() +endif() + # suppress deprecation warnings inside OCCT itself for old gcc versions with unavailable Standard_DISABLE_DEPRECATION_WARNINGS if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.6.0) diff --git a/adm/cmake/occt_toolkit_prepare_sample.cmake b/adm/cmake/occt_toolkit_prepare_sample.cmake new file mode 100644 index 0000000000..ecc5ba0683 --- /dev/null +++ b/adm/cmake/occt_toolkit_prepare_sample.cmake @@ -0,0 +1,18 @@ +if ("${TARGET_FOLDER}" STREQUAL "") + set (EXECUTABLE_PROJECT ON) + set (USE_QT ON) + + set (RELATIVE_DIR "samples/qt") + set (MODULES_LIST ${OCCT_SAMPLES}) + set (TARGET_FOLDER "Samples") + set (TOOLKITS_NAME_SUFFIX "SAMPLES_TOOLKITS") + + include_directories("${CMAKE_BINARY_DIR}/${INSTALL_DIR_INCLUDE}/${RELATIVE_DIR}") +else() + unset (USE_QT) + unset (RELATIVE_DIR) + unset (EXECUTABLE_PROJECT) + unset (MODULES_LIST) + unset (TARGET_FOLDER) + unset (TOOLKITS_NAME_SUFFIX) +endif("${TARGET_FOLDER}" STREQUAL "") diff --git a/adm/cmake/occt_toolkit_prepare_tool.cmake b/adm/cmake/occt_toolkit_prepare_tool.cmake new file mode 100644 index 0000000000..eed173ae63 --- /dev/null +++ b/adm/cmake/occt_toolkit_prepare_tool.cmake @@ -0,0 +1,13 @@ +if ("${TARGET_FOLDER}" STREQUAL "") + set (USE_QT ON) + set (RELATIVE_DIR "tools") + set (MODULES_LIST ${OCCT_TOOLS}) + set (TARGET_FOLDER "Tools") + set (TOOLKITS_NAME_SUFFIX "TOOL_TOOLKITS") +else() + unset (USE_QT) + unset (RELATIVE_DIR) + unset (MODULES_LIST) + unset (TARGET_FOLDER) + unset (TOOLKITS_NAME_SUFFIX) +endif("${TARGET_FOLDER}" STREQUAL "") diff --git a/adm/cmake/occt_toolkit_tool.cmake b/adm/cmake/occt_toolkit_tool.cmake deleted file mode 100644 index d934de6d54..0000000000 --- a/adm/cmake/occt_toolkit_tool.cmake +++ /dev/null @@ -1,302 +0,0 @@ -# script for each OCCT tool toolkit - -# Qt dependencies -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/qt_macro) - -FIND_QT_PACKAGE(PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT_INCLUDES) -include_directories("${PROJECT_INCLUDES}" - "${CMAKE_BINARY_DIR}/${INSTALL_DIR_INCLUDE}/tools") - -FILE_TO_LIST ("tools/${PROJECT_NAME}/PACKAGES" USED_PACKAGES) -# parce PACKAGES file - -if ("${PROJECT_NAME}" STREQUAL TInspectorEXE) - set (USED_PACKAGES ${PROJECT_NAME}) - set (PACKAGE_PREFIX_DIR "samples/tools") - include_directories("${PROJECT_INCLUDES}" - "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${PROJECT_NAME}") -else() - FILE_TO_LIST ("tools/${PROJECT_NAME}/PACKAGES" USED_PACKAGES) - set (PACKAGE_PREFIX_DIR "tools") -endif() - - -SET (RCC_FILES) -foreach (OCCT_PACKAGE ${USED_PACKAGES}) - #message("Dir is ${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${OCCT_PACKAGE}.qrc") - FIND_AND_WRAP_RESOURCE_FILE("${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${OCCT_PACKAGE}.qrc" RCC_FILES) -endforeach() -#message("RCC_FILES for ${PROJECT_NAME} are ${RCC_FILES}") - -set (PRECOMPILED_DEFS) - -if (NOT BUILD_SHARED_LIBS) - list (APPEND PRECOMPILED_DEFS "-DOCCT_NO_PLUGINS") - if (WIN32) - list (APPEND PRECOMPILED_DEFS "-DOCCT_STATIC_BUILD") - endif() -endif() - -# Get all used packages from toolkit -foreach (OCCT_PACKAGE ${USED_PACKAGES}) - - ADD_DEFINITIONS(-D${OCCT_PACKAGE}_EXPORTS) - - # TKService contains platform-dependent packages: Xw and WNT - if ((WIN32 AND "${OCCT_PACKAGE}" STREQUAL "Xw") OR (NOT WIN32 AND "${OCCT_PACKAGE}" STREQUAL "WNT")) - # do nothing - else() - -# if (WIN32) -# list (APPEND PRECOMPILED_DEFS "-D__${OCCT_PACKAGE}_DLL") -# endif() - - set (SOURCE_FILES) - set (HEADER_FILES) - - # Generate Flex and Bison files - if (${BUILD_YACCLEX}) - - # flex files - OCCT_ORIGIN_AND_PATCHED_FILES ("tools/${OCCT_PACKAGE}" "*[.]lex" SOURCE_FILES_FLEX) - list (LENGTH SOURCE_FILES_FLEX SOURCE_FILES_FLEX_LEN) - - # bison files - OCCT_ORIGIN_AND_PATCHED_FILES ("tools/${OCCT_PACKAGE}" "*[.]yacc" SOURCE_FILES_BISON) - list (LENGTH SOURCE_FILES_BISON SOURCE_FILES_BISON_LEN) - - if (${SOURCE_FILES_FLEX_LEN} EQUAL ${SOURCE_FILES_BISON_LEN} AND NOT ${SOURCE_FILES_FLEX_LEN} EQUAL 0) - - list (SORT SOURCE_FILES_FLEX) - list (SORT SOURCE_FILES_BISON) - - math (EXPR SOURCE_FILES_FLEX_LEN "${SOURCE_FILES_FLEX_LEN} - 1") - foreach (FLEX_FILE_INDEX RANGE ${SOURCE_FILES_FLEX_LEN}) - - list (GET SOURCE_FILES_FLEX ${FLEX_FILE_INDEX} CURRENT_FLEX_FILE) - get_filename_component (CURRENT_FLEX_FILE_NAME ${CURRENT_FLEX_FILE} NAME_WE) - - list (GET SOURCE_FILES_BISON ${FLEX_FILE_INDEX} CURRENT_BISON_FILE) - get_filename_component (CURRENT_BISON_FILE_NAME ${CURRENT_BISON_FILE} NAME_WE) - - string (COMPARE EQUAL ${CURRENT_FLEX_FILE_NAME} ${CURRENT_BISON_FILE_NAME} ARE_FILES_EQUAL) - - if (EXISTS "${CURRENT_FLEX_FILE}" AND EXISTS "${CURRENT_BISON_FILE}" AND ${ARE_FILES_EQUAL}) - set (BISON_OUTPUT_FILE ${CURRENT_BISON_FILE_NAME}.tab.c) - set (FLEX_OUTPUT_FILE lex.${CURRENT_FLEX_FILE_NAME}.c) - BISON_TARGET (Parser_${CURRENT_BISON_FILE_NAME} ${CURRENT_BISON_FILE} ${CMAKE_SOURCE_DIR}/tools/${OCCT_PACKAGE}/${BISON_OUTPUT_FILE} COMPILE_FLAGS "-p ${CURRENT_BISON_FILE_NAME}") - FLEX_TARGET (Scanner_${CURRENT_FLEX_FILE_NAME} ${CURRENT_FLEX_FILE} ${CMAKE_SOURCE_DIR}/tools/${OCCT_PACKAGE}/${FLEX_OUTPUT_FILE} COMPILE_FLAGS "-P${CURRENT_FLEX_FILE_NAME}") - ADD_FLEX_BISON_DEPENDENCY (Scanner_${CURRENT_FLEX_FILE_NAME} Parser_${CURRENT_BISON_FILE_NAME}) - - list (APPEND SOURCE_FILES ${BISON_OUTPUT_FILE} ${FLEX_OUTPUT_FILE}) - endif() - endforeach() - endif() - endif() - - # header files - if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES") - file (STRINGS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h") - file (STRINGS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx") - file (STRINGS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx") - - file (STRINGS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c") - if(APPLE) - file (STRINGS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm") - endif() - else() - file (STRINGS "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_M REGEX ".+[.]h") - file (STRINGS "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_LXX REGEX ".+[.]lxx") - file (STRINGS "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/FILES" HEADER_FILES_GXX REGEX ".+[.]gxx") - - file (STRINGS "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_C REGEX ".+[.]c") - if(APPLE) - file (STRINGS "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/FILES" SOURCE_FILES_M REGEX ".+[.]mm") - endif() - endif() - - - - list (APPEND HEADER_FILES ${HEADER_FILES_M} ${HEADER_FILES_LXX} ${SOURCE_FILES_GXX}) - list (APPEND SOURCE_FILES ${SOURCE_FILES_C}) - if(APPLE) - list (APPEND SOURCE_FILES ${SOURCE_FILES_M}) - endif() - - foreach(HEADER_FILE ${HEADER_FILES}) - if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${HEADER_FILE}") - message (STATUS "Info: consider patched file: ${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${HEADER_FILE}") - list (APPEND USED_INCFILES "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${HEADER_FILE}") - SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${HEADER_FILE}") - else() - list (APPEND USED_INCFILES "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}") - SOURCE_GROUP ("Header Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${HEADER_FILE}") - endif() - endforeach() - - - foreach(SOURCE_FILE ${SOURCE_FILES}) - if (BUILD_PATCH AND EXISTS "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${SOURCE_FILE}") - message (STATUS "Info: consider patched file: ${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${SOURCE_FILE}") - list (APPEND USED_SRCFILES "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${SOURCE_FILE}") - SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${BUILD_PATCH}/tools/${OCCT_PACKAGE}/${SOURCE_FILE}") - else() - list (APPEND USED_SRCFILES "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}") - SOURCE_GROUP ("Source Files\\${OCCT_PACKAGE}" FILES "${CMAKE_SOURCE_DIR}/${PACKAGE_PREFIX_DIR}/${OCCT_PACKAGE}/${SOURCE_FILE}") - endif() - endforeach() - endif() -endforeach() -string (REGEX REPLACE ";" " " PRECOMPILED_DEFS "${PRECOMPILED_DEFS}") - -set (USED_RCFILE "") -if (MSVC) - set (USED_RCFILE "${CMAKE_BINARY_DIR}/resources/${PROJECT_NAME}.rc") - - if (APPLY_OCCT_PATCH_DIR AND EXISTS "${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in") - configure_file("${APPLY_OCCT_PATCH_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY) - else() - configure_file("${CMAKE_SOURCE_DIR}/adm/templates/occt_toolkit.rc.in" "${USED_RCFILE}" @ONLY) - endif() -endif() - -set (CURRENT_MODULE) -foreach (OCCT_MODULE ${OCCT_TOOLS}) - list (FIND ${OCCT_MODULE}_TOOL_TOOLKITS ${PROJECT_NAME} CURRENT_PROJECT_IS_BUILT) - if (NOT ${CURRENT_PROJECT_IS_BUILT} EQUAL -1) - set (CURRENT_MODULE ${OCCT_MODULE}) - endif() -endforeach() - -if (WIN32) - OCCT_INSERT_CODE_FOR_TARGET () -endif() - -FIND_AND_WRAP_MOC_FILES("${USED_INCFILES}" "${PROJECT_NAME}_MOC_FILES") -#message("MOC files: ${${PROJECT_NAME}_MOC_FILES}") - -if ("${PROJECT_NAME}" STREQUAL TInspectorEXE) - add_executable (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RCC_FILES} ${${PROJECT_NAME}_MOC_FILES}) - - install (TARGETS ${PROJECT_NAME} - DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}") -else() - add_library (${PROJECT_NAME} ${USED_SRCFILES} ${USED_INCFILES} ${USED_RCFILE} ${RCC_FILES} ${${PROJECT_NAME}_MOC_FILES}) - - if (MSVC) - install (FILES ${CMAKE_BINARY_DIR}/${OS_WITH_BIT}/${COMPILER}/bin\${OCCT_INSTALL_BIN_LETTER}/${PROJECT_NAME}.pdb - CONFIGURATIONS Debug RelWithDebInfo - DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}") - endif() - - if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "") - set (CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT ${CMAKE_SHARED_LIBRARY_SUFFIX}) - set (CMAKE_SHARED_LIBRARY_SUFFIX "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}") - endif() - - install (TARGETS ${PROJECT_NAME} - EXPORT OpenCASCADE${CURRENT_MODULE}Targets - RUNTIME DESTINATION "${INSTALL_DIR_BIN}\${OCCT_INSTALL_BIN_LETTER}" - ARCHIVE DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}" - LIBRARY DESTINATION "${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}") - - - if (NOT WIN32) - if (BUILD_SHARED_LIBS AND NOT "${BUILD_SHARED_LIBRARY_NAME_POSTFIX}" STREQUAL "") - set (LINK_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX_DEFAULT}/tools") - set (LIBRARY_NAME "${INSTALL_DIR}/${INSTALL_DIR_LIB}\${OCCT_INSTALL_BIN_LETTER}/lib${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}/tools") - OCCT_CREATE_SYMLINK_TO_FILE (${LIBRARY_NAME} ${LINK_NAME}) - endif() - endif() -endif() - -if (CURRENT_MODULE) - set_target_properties (${PROJECT_NAME} PROPERTIES FOLDER "Tools/${CURRENT_MODULE}") - set_target_properties (${PROJECT_NAME} PROPERTIES MODULE "${CURRENT_MODULE}") - if (APPLE) - if (NOT "${INSTALL_NAME_DIR}" STREQUAL "") - set_target_properties (${PROJECT_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH 1 INSTALL_NAME_DIR "${INSTALL_NAME_DIR}") - endif() - endif() -endif() - -get_property (OCC_VERSION_MAJOR GLOBAL PROPERTY OCC_VERSION_MAJOR) -get_property (OCC_VERSION_MINOR GLOBAL PROPERTY OCC_VERSION_MINOR) -get_property (OCC_VERSION_MAINTENANCE GLOBAL PROPERTY OCC_VERSION_MAINTENANCE) - -if (ANDROID) - # do not append version to the filename - set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}") -else() - set_target_properties (${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${PRECOMPILED_DEFS}" - SOVERSION "${OCC_VERSION_MAJOR}" - VERSION "${OCC_VERSION_MAJOR}.${OCC_VERSION_MINOR}.${OCC_VERSION_MAINTENANCE}") -endif() - -set (USED_TOOLKITS_BY_CURRENT_PROJECT) -set (USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT) - -# parce EXTERNLIB file -FILE_TO_LIST ("${PACKAGE_PREFIX_DIR}/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS) -foreach (USED_ITEM ${USED_EXTERNLIB_AND_TOOLKITS}) - string (REGEX MATCH "^ *#" COMMENT_FOUND ${USED_ITEM}) - if (NOT COMMENT_FOUND) - string (REGEX MATCH "^TK" TK_FOUND ${USED_ITEM}) - string (REGEX MATCH "^vtk" VTK_FOUND ${USED_ITEM}) - - if (NOT "${TK_FOUND}" STREQUAL "" OR NOT "${VTK_FOUND}" STREQUAL "") - list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT ${USED_ITEM}) - if (NOT "${VTK_FOUND}" STREQUAL "" AND BUILD_SHARED_LIBS AND INSTALL_VTK AND COMMAND OCCT_INSTALL_VTK) - OCCT_INSTALL_VTK(${USED_ITEM}) - endif() - else() - string (REGEX MATCH "^CSF_" CSF_FOUND ${USED_ITEM}) - if ("${CSF_FOUND}" STREQUAL "") - message (STATUS "Info: ${USED_ITEM} from ${PROJECT_NAME} skipped due to it is empty") - else() # get CSF_ value - set (CURRENT_CSF ${${USED_ITEM}}) - if (NOT "x${CURRENT_CSF}" STREQUAL "x") - # prepare a list from a string with whitespaces - separate_arguments (CURRENT_CSF) - list (APPEND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT ${CURRENT_CSF}) - endif() - endif() - endif() - endif() -endforeach() - -if (APPLE) - list (FIND USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT X11 IS_X11_FOUND) - if (NOT ${IS_X11_FOUND} EQUAL -1) - find_package (X11 COMPONENTS X11 Xext Xmu Xi) - if (NOT X11_FOUND) - message (STATUS "Warning: X11 is not found. It's required to install The XQuartz project: http://www.xquartz.org") - endif() - endif() -endif() - -# Update list of used VTK libraries if OpenGL2 Rendering BackEnd is used. -# Add VTK_OPENGL2_BACKEND definition. -if("${VTK_RENDERING_BACKEND}" STREQUAL "OpenGL2") - add_definitions(-DVTK_OPENGL2_BACKEND) - foreach (VTK_EXCLUDE_LIBRARY vtkRenderingOpenGL vtkRenderingFreeTypeOpenGL) - list (FIND USED_TOOLKITS_BY_CURRENT_PROJECT "${VTK_EXCLUDE_LIBRARY}" IS_VTK_OPENGL_FOUND) - if (NOT ${IS_VTK_OPENGL_FOUND} EQUAL -1) - list (REMOVE_ITEM USED_TOOLKITS_BY_CURRENT_PROJECT ${VTK_EXCLUDE_LIBRARY}) - if (${VTK_EXCLUDE_LIBRARY} STREQUAL vtkRenderingOpenGL) - list (APPEND USED_TOOLKITS_BY_CURRENT_PROJECT vtkRenderingOpenGL2) - endif() - endif() - endforeach() -endif() - -if (BUILD_SHARED_LIBS) - target_link_libraries (${PROJECT_NAME} ${USED_TOOLKITS_BY_CURRENT_PROJECT} ${USED_EXTERNAL_LIBS_BY_CURRENT_PROJECT}) -endif() - -# Set Qt dependencies -target_link_libraries(${PROJECT_NAME} "${PROJECT_LIBRARIES}") - -target_link_libraries(${PROJECT_NAME} debug "${PROJECT_LIBRARIES_DEBUG}") -target_link_libraries(${PROJECT_NAME} optimized "${PROJECT_LIBRARIES_RELEASE}") - diff --git a/adm/cmake/qt_macro.cmake b/adm/cmake/qt_macro.cmake index 5cdbe9cf26..c535772c2e 100644 --- a/adm/cmake/qt_macro.cmake +++ b/adm/cmake/qt_macro.cmake @@ -12,13 +12,21 @@ macro (FIND_QT_PACKAGE PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT # Now we can apply standard CMake finder for Qt5. We do this mostly # to have qt5_wrap_cpp() function available - find_package(Qt5 QUIET COMPONENTS Widgets PATHS ${3RDPARTY_QT_DIR} NO_DEFAULT_PATH) + find_package(Qt5 QUIET COMPONENTS Widgets Quick PATHS ${3RDPARTY_QT_DIR} NO_DEFAULT_PATH) if (${Qt5_FOUND}) #message (STATUS "Qt5 cmake configuration") - set(PROJECT_INCLUDES "${Qt5Widgets_INCLUDE_DIRS}") - set(PROJECT_LIBRARIES_DEBUG "${Qt5Widgets_LIBRARIES}") - set(PROJECT_LIBRARIES_RELEASE "${Qt5Widgets_LIBRARIES}") + set(PROJECT_INCLUDES "${Qt5Widgets_INCLUDE_DIRS}" "${Qt5Quick_INCLUDE_DIRS}") + set(PROJECT_LIBRARIES_DEBUG "${Qt5Widgets_LIBRARIES}" "${Qt5Quick_LIBRARIES}") + set(PROJECT_LIBRARIES_RELEASE "${Qt5Widgets_LIBRARIES}" "${Qt5Quick_LIBRARIES}") + + # processing *.ts files to generate *.qm + find_package(Qt5LinguistTools) + get_target_property(QT_LRELEASE_EXECUTABLE Qt5::lrelease LOCATION) + mark_as_advanced(QT_LRELEASE_EXECUTABLE) + + GET_FILENAME_COMPONENT(QT_BINARY_DIR ${QT_LRELEASE_EXECUTABLE} DIRECTORY) + MARK_AS_ADVANCED(QT_BINARY_DIR) else() # Now we can apply standard CMake finder for Qt. We do this mostly # to have qt4_wrap_cpp() function available @@ -33,6 +41,7 @@ macro (FIND_QT_PACKAGE PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT set(PROJECT_LIBRARIES_DEBUG "${3RDPARTY_QT_DIR}/lib/libQtCore.so;${3RDPARTY_QT_DIR}/lib/libQtGui.so") set(PROJECT_LIBRARIES_RELEASE "${3RDPARTY_QT_DIR}/lib/libQtCore.so;${3RDPARTY_QT_DIR}/lib/libQtGui.so") endif(WIN32) + find_program(QT_LRELEASE_EXECUTABLE lrelease) endif() endmacro() @@ -69,3 +78,57 @@ macro (FIND_AND_WRAP_RESOURCE_FILE RESOURCE_FILE_NAME RCC_FILES) endif() endif() endmacro() + +macro (FIND_AND_INSTALL_TS_FILE RESOURCE_FILE_NAME TARGET_FOLDER QM_FILES) + if(EXISTS "${RESOURCE_FILE_NAME}") + GET_FILENAME_COMPONENT(_name ${RESOURCE_FILE_NAME} NAME_WE) + SET(_output ${CMAKE_CURRENT_BINARY_DIR}/${_name}.qm) + SET(_cmd_${_name} ${QT_LRELEASE_EXECUTABLE} ${RESOURCE_FILE_NAME} -qm ${_output}) + + set(TARGET_NAME ${_name}_resources) + + if (NOT TARGET "${TARGET_NAME}") + add_custom_target(${TARGET_NAME} ALL COMMAND ${_cmd_${_name}} DEPENDS ${RESOURCE_FILE_NAME}) + set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "${TARGET_FOLDER}") + + list (APPEND ${QM_FILES} "${_output}") + endif() + endif() +endmacro() + +macro (FIND_AND_INSTALL_QT_RESOURCES OCCT_PACKAGE RESOURCE_FILES) + file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" TS_FILES REGEX ".+[.]ts") + file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" QRC_FILES REGEX ".+[.]qrc") + + string (FIND "${OCCT_PACKAGE}" "/" _index) + if (_index GREATER -1) + math (EXPR _index "${_index}") + string (SUBSTRING "${OCCT_PACKAGE}" 0 ${_index} OCCT_PACKAGE_NAME) + else() + set (OCCT_PACKAGE_NAME "${OCCT_PACKAGE}") + endif(_index GREATER -1) + + #message("QRC files are: ${QRC_FILES} in ${OCCT_PACKAGE}") + foreach (QRC_FILE ${QRC_FILES}) + set (QRC_FILE_RELATIVE "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${QRC_FILE}") + if (EXISTS ${QRC_FILE_RELATIVE}) + FIND_AND_WRAP_RESOURCE_FILE(${QRC_FILE_RELATIVE} RCC_FILES) + list (APPEND ${RESOURCE_FILES} "${RCC_FILES}") + endif() + endforeach() + + #message("TS files are: ${TS_FILES} in ${OCCT_PACKAGE}") + foreach (TS_FILE ${TS_FILES}) + set (TS_FILE_RELATIVE "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${TS_FILE}") + FIND_AND_INSTALL_TS_FILE(${TS_FILE_RELATIVE} "${TARGET_FOLDER}/${CURRENT_MODULE}" QM_FILES) + if (EXISTS ${TS_FILE_RELATIVE}) + list (APPEND ${RESOURCE_FILES} "${TS_FILE_RELATIVE}") + endif() + endforeach() + + foreach (QM_FILE ${QM_FILES}) + INSTALL(FILES ${QM_FILE} DESTINATION "${INSTALL_DIR_RESOURCE}/samples") + #message("install *.qm files (${QM_FILE}) to: ${INSTALL_DIR_RESOURCE}/samples") + endforeach (QM_FILE ${QM_FILES}) +endmacro() + diff --git a/adm/cmake/vardescr.cmake b/adm/cmake/vardescr.cmake index c2327622a5..f5c7d2b375 100644 --- a/adm/cmake/vardescr.cmake +++ b/adm/cmake/vardescr.cmake @@ -122,6 +122,11 @@ set (BUILD_MODULE_MfcSamples_DESCR These samples show some possibilities of using OCCT and they can be executed with script samples.bat from the installation directory (INSTALL_DIR)") +set (BUILD_MODULE_QtSamples_DESCR +"Indicates whether OCCT Qt samples should be built together with OCCT. +These samples show some possibilities of using OCCT and they can be executed +with script samples.bat from the installation directory (INSTALL_DIR)") + set (BUILD_Inspector_DESCR "Indicates whether OCCT inspector should be built together with OCCT. This inspector provides functionality to interactively inspect low-level content diff --git a/adm/templates/sample.bat b/adm/templates/sample.bat index 89b0fdbb9d..023346648d 100644 --- a/adm/templates/sample.bat +++ b/adm/templates/sample.bat @@ -16,6 +16,10 @@ if ["%1"] == [""] ( echo HLR echo Animation echo Convert + echo AndroidQt + echo FuncDemo + echo IESample + echo Tutorial PAUSE exit /B ) diff --git a/samples/qt/AndroidQt/AndroidQt.cxx b/samples/qt/AndroidQt/AndroidQt.cxx deleted file mode 100644 index 70026c13ca..0000000000 --- a/samples/qt/AndroidQt/AndroidQt.cxx +++ /dev/null @@ -1,291 +0,0 @@ -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -// ======================================================================= -// function : AndroidQt -// purpose : -// ======================================================================= -AndroidQt::AndroidQt() -: myFitAllAction (false) -{ - connect (this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*))); - - // set shaders location variable - QByteArray aDataRoot = "/data/data/org.qtproject.example.AndroidQt/files/opencascade/shared"; - qputenv ("CSF_ShadersDirectory", aDataRoot + "/Shaders"); -} - -// ======================================================================= -// function : ReadShapeFromFile -// purpose : -// ======================================================================= -bool AndroidQt::ReadShapeFromFile (QString theFilePath) -{ - QUrl aFileUrl (theFilePath); - QString aFilePath = theFilePath; - if (aFileUrl.isLocalFile()) - { - aFilePath = QUrl (theFilePath).toLocalFile(); - } - - if (!QFile (aFilePath).exists()) - { - return false; - } - - TopoDS_Shape aShape; - BRep_Builder aBuildTool; - try - { - OCC_CATCH_SIGNALS - - if (!BRepTools::Read (aShape, aFilePath.toStdString().c_str(), aBuildTool)) - { - return false; - } - - if (!myContext.IsNull()) - { - myContext->EraseAll (Standard_False); - - Handle(AIS_Shape) aShapePrs = new AIS_Shape (aShape); - aShapePrs->SetColor (Quantity_Color(1.0, 0.73, 0.2, Quantity_TOC_RGB)); - - myContext->Display (aShapePrs, Standard_False); - myContext->SetDisplayMode (aShapePrs, AIS_Shaded, Standard_False); - } - - myMutex.lock(); - myFitAllAction = true; - myMutex.unlock(); - - if (window()) - { - window()->update(); - } - } - catch (Standard_Failure) - { - return false; - } - - return true; -} - -// ======================================================================= -// function : InitTouch -// purpose : -// ======================================================================= -void AndroidQt::InitTouch (const double theX, - const double theY) -{ - myMutex.lock(); - myTouchPoint.SetStarts (theX, theY); - myMutex.unlock(); -} - -// ======================================================================= -// function : UpdateTouch -// purpose : -// ======================================================================= -void AndroidQt::UpdateTouch (const double theX, - const double theY) -{ - myMutex.lock(); - myTouchPoint.SetEnds (theX, theY); - myMutex.unlock(); - - if (window()) - window()->update(); -} - -// ======================================================================= -// function : handleWindowChanged -// purpose : -// ======================================================================= -void AndroidQt::handleWindowChanged (QQuickWindow* theWin) -{ - if (theWin == NULL) - { - return; - } - - connect(theWin, SIGNAL(beforeSynchronizing()), this, SLOT(sync()), Qt::DirectConnection); - - theWin->setClearBeforeRendering (false); -} - -// ======================================================================= -// function : sync -// purpose : -// ======================================================================= -void AndroidQt::sync() -{ - myViewportSize = window()->size() * window()->devicePixelRatio(); - - if (myViewer.IsNull()) - { - initViewer(); - connect (window(), SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection); - } - else - { - Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myViewer->Driver()); - if (aDriver->getRawGlContext() != eglGetCurrentContext()) - { - initViewer(); - } - else - { - Handle(AndroidQt_Window) aWindow = Handle(AndroidQt_Window)::DownCast (myView->Window()); - aWindow->SetSize (myViewportSize.width(), myViewportSize.height()); - //myView->MustBeResized(); // can be used instead of SetWindow() when EGLsurface has not been changed - - EGLContext anEglContext = eglGetCurrentContext(); - myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext); - } - } -} - -// ======================================================================= -// function : paint -// purpose : -// ======================================================================= -void AndroidQt::paint() -{ - myMutex.lock(); - - if (Abs(myTouchPoint.DevX()) + Abs(myTouchPoint.DevY()) > 1) - { - myView->StartRotation (myTouchPoint.X().first, myTouchPoint.Y().first); - myView->Rotation (myTouchPoint.X().second, myTouchPoint.Y().second); - - myTouchPoint.ClearDev(); - } - - if (myFitAllAction) - { - myView->FitAll(); - myFitAllAction = false; - } - - myMutex.unlock(); - - myView->Redraw(); -} - -// ======================================================================= -// function : initViewer -// purpose : -// ======================================================================= -bool AndroidQt::initViewer() -{ - EGLint aCfgId = 0; - int aWidth = 0, aHeight = 0; - EGLDisplay anEglDisplay = eglGetCurrentDisplay(); - EGLContext anEglContext = eglGetCurrentContext(); - EGLSurface anEglSurf = eglGetCurrentSurface (EGL_DRAW); - - if (anEglDisplay == EGL_NO_DISPLAY - || anEglContext == EGL_NO_CONTEXT - || anEglSurf == EGL_NO_SURFACE) - { - release(); - return false; - } - - eglQuerySurface (anEglDisplay, anEglSurf, EGL_WIDTH, &aWidth); - eglQuerySurface (anEglDisplay, anEglSurf, EGL_HEIGHT, &aHeight); - eglQuerySurface (anEglDisplay, anEglSurf, EGL_CONFIG_ID, &aCfgId); - - const EGLint aConfigAttribs[] = { EGL_CONFIG_ID, aCfgId, EGL_NONE }; - EGLint aNbConfigs = 0; - void* anEglConfig = NULL; - - if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) != EGL_TRUE) - { - release(); - return false; - } - - if (!myViewer.IsNull()) - { - Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myViewer->Driver()); - Handle(AndroidQt_Window) aWindow = Handle(AndroidQt_Window)::DownCast (myView->Window()); - if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig)) - { - release(); - return false; - } - - aWindow->SetSize (aWidth, aHeight); - myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext); - } - - Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver (NULL, Standard_False); - aDriver->ChangeOptions().buffersNoSwap = Standard_True; - //aDriver->ChangeOptions().glslWarnings = Standard_True; // for GLSL shaders debug - - if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig)) - { - release(); - return false; - } - - // create viewer - myViewer = new V3d_Viewer (aDriver); - myViewer->SetDefaultBackgroundColor (AndroidQt_UserInteractionParameters::BgColor.Name()); - myViewer->SetDefaultLights(); - myViewer->SetLightOn(); - - // create AIS context - myContext = new AIS_InteractiveContext (myViewer); - myContext->SetDisplayMode (AIS_Shaded, false); - - Handle(AndroidQt_Window) aWindow = new AndroidQt_Window (aWidth, aHeight); - myView = myViewer->CreateView(); - - myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext); - myView->TriedronDisplay (Aspect_TOTP_RIGHT_LOWER, Quantity_NOC_WHITE, 0.08, V3d_ZBUFFER); - - return true; -} - -// ======================================================================= -// function : release -// purpose : -// ======================================================================= -void AndroidQt::release() -{ - myContext.Nullify(); - myView.Nullify(); - myViewer.Nullify(); -} diff --git a/samples/qt/AndroidQt/AndroidQt.h b/samples/qt/AndroidQt/AndroidQt.h deleted file mode 100644 index 9bc0e57b78..0000000000 --- a/samples/qt/AndroidQt/AndroidQt.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef ANDROIDQT_H -#define ANDROIDQT_H - -#include - -// workaround broken definitions in Qt -#define GLdouble GLdouble - -#include -#include - -#undef GLdouble - -#include -#include - -#include - -#include - -//! QML item with embedded OCCT viewer. -class AndroidQt : public QQuickItem -{ - Q_OBJECT - -public: - //! Default constructor. - AndroidQt(); - - //! Display shape from file. - Q_INVOKABLE bool ReadShapeFromFile (QString theFilePath); - - //! Handle touch event. - Q_INVOKABLE void InitTouch (const double theX, - const double theY); - - //! Handle touch event. - Q_INVOKABLE void UpdateTouch (const double theX, - const double theY); - -public slots: - - //! Handle OpenGL context creation and window resize events. - void sync(); - - //! Redraw OCCT viewer and handle pending viewer events in rendering thread. - void paint(); - -private slots: - - //! Handle window change event. - void handleWindowChanged (QQuickWindow* theWin); - -private: - - //! (Re-)initialize viewer on OpenGL context change. - bool initViewer(); - - //! Close viewer - void release(); - -private: - - Handle(V3d_Viewer) myViewer; //!< 3D viewer - Handle(V3d_View) myView; //!< 3D view - Handle(AIS_InteractiveContext) myContext; //!< interactive context - - QMutex myMutex; //!< mutex for interconnection with rendering thread - QSize myViewportSize; //!< QML item size - AndroidQt_TouchParameters myTouchPoint; //!< cached state of touch event - bool myFitAllAction; //!< queued viewer FitALL event - -}; - -#endif // ANDROIDQT_H diff --git a/samples/qt/AndroidQt/AndroidQt.pro b/samples/qt/AndroidQt/AndroidQt.pro index 7ddc34b91d..0b1527fc51 100644 --- a/samples/qt/AndroidQt/AndroidQt.pro +++ b/samples/qt/AndroidQt/AndroidQt.pro @@ -2,12 +2,12 @@ TEMPLATE = app QT += qml quick widgets -SOURCES += Main.cxx \ - AndroidQt.cxx \ - AndroidQt_Window.cxx \ - AndroidQt_TouchParameters.cxx +SOURCES += src/Main.cxx \ + src/AndroidQt.cxx \ + src/AndroidQt_Window.cxx \ + src/AndroidQt_TouchParameters.cxx -RESOURCES += AndroidQt.qrc +RESOURCES += ./src/AndroidQt.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = @@ -19,10 +19,13 @@ include(OCCT.pri) include(Deployment.pri) HEADERS += \ - AndroidQt.h \ - AndroidQt_Window.h \ - AndroidQt_TouchParameters.h \ - AndroidQt_UserInteractionParameters.h + src/AndroidQt.h \ + src/AndroidQt_Window.h \ + src/AndroidQt_TouchParameters.h \ + src/AndroidQt_UserInteractionParameters.h + +INCLUDEPATH += $$_PRO_FILE_PWD_/src +DEPENDPATH += $$_PRO_FILE_PWD_/src OTHER_FILES += \ android/src/org/qtproject/example/AndroidQt/AndroidQt.java \ diff --git a/samples/qt/AndroidQt/AndroidQt.qrc b/samples/qt/AndroidQt/AndroidQt.qrc deleted file mode 100644 index bcead84dcb..0000000000 --- a/samples/qt/AndroidQt/AndroidQt.qrc +++ /dev/null @@ -1,8 +0,0 @@ - - - res/qml/main.qml - - - res/icons/ic_action_collection.png - - diff --git a/samples/qt/AndroidQt/AndroidQt_TouchParameters.cxx b/samples/qt/AndroidQt/AndroidQt_TouchParameters.cxx deleted file mode 100644 index c844e26175..0000000000 --- a/samples/qt/AndroidQt/AndroidQt_TouchParameters.cxx +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -// ======================================================================= -// function : AndroidQt_TouchParameters -// purpose : -// ======================================================================= -AndroidQt_TouchParameters::AndroidQt_TouchParameters() -: myXStart (0.0), - myXEnd (0.0), - myYStart (0.0), - myYEnd (0.0) -{ -} - -// ======================================================================= -// function : AndroidQt_TouchParameters -// purpose : -// ======================================================================= -AndroidQt_TouchParameters::AndroidQt_TouchParameters (const double theX, - const double theY) -: myXStart (theX), - myXEnd (theX), - myYStart (theY), - myYEnd (theY) -{ -} - -// ======================================================================= -// function : X -// purpose : -// ======================================================================= -QPair AndroidQt_TouchParameters::X() const -{ - return qMakePair(myXStart, myXEnd); -} - -// ======================================================================= -// function : DevX -// purpose : -// ======================================================================= -double AndroidQt_TouchParameters::DevX() const -{ - return myXEnd - myXStart; -} - -// ======================================================================= -// function : Y -// purpose : -// ======================================================================= -QPair AndroidQt_TouchParameters::Y() const -{ - return qMakePair(myYStart, myYEnd); -} - -// ======================================================================= -// function : DevY -// purpose : -// ======================================================================= -double AndroidQt_TouchParameters::DevY() const -{ - return myYEnd - myYStart; -} - -// ======================================================================= -// function : SetStarts -// purpose : -// ======================================================================= -void AndroidQt_TouchParameters::SetStarts (const double theXStart, - const double theYStart) -{ - myXStart = theXStart; - myYStart = theYStart; -} - -// ======================================================================= -// function : SetEnds -// purpose : -// ======================================================================= -void AndroidQt_TouchParameters::SetEnds (const double theXEnd, - const double theYEnd) -{ - myXEnd = theXEnd; - myYEnd = theYEnd; -} - -// ======================================================================= -// function : ClearDev -// purpose : -// ======================================================================= -void AndroidQt_TouchParameters::ClearDev() -{ - myXStart = myXEnd; - myYStart = myYEnd; -} diff --git a/samples/qt/AndroidQt/AndroidQt_TouchParameters.h b/samples/qt/AndroidQt/AndroidQt_TouchParameters.h deleted file mode 100644 index 1debd06167..0000000000 --- a/samples/qt/AndroidQt/AndroidQt_TouchParameters.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef ANDROIDQT_TOUCHPARAMETERS_H -#define ANDROIDQT_TOUCHPARAMETERS_H - -#include - -//! Class holding touch event state. -class AndroidQt_TouchParameters -{ - -public: - - //! Empty constructor. - AndroidQt_TouchParameters(); - - //! Default constructor. - AndroidQt_TouchParameters (const double theX, - const double theY); - - //! x coord - QPair X() const; - double DevX() const; - - //! y coord - QPair Y() const; - double DevY() const; - - //! Start coords - void SetStarts (const double theXStart, - const double theYStart); - - //! End coords - void SetEnds (const double theXEnd, - const double theYEnd); - - void ClearDev(); - -private: - - double myXStart; - double myXEnd; - - double myYStart; - double myYEnd; - -}; - -#endif // ANDROIDQT_TOUCHPARAMETERS_H diff --git a/samples/qt/AndroidQt/AndroidQt_UserInteractionParameters.h b/samples/qt/AndroidQt/AndroidQt_UserInteractionParameters.h deleted file mode 100644 index 2010046397..0000000000 --- a/samples/qt/AndroidQt/AndroidQt_UserInteractionParameters.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef ANDROIDQT_USERINTERACTIONPARAMETERS_H -#define ANDROIDQT_USERINTERACTIONPARAMETERS_H - -#include - -namespace AndroidQt_UserInteractionParameters -{ - const double RotationThreshold = 2; // [pixel] - const double PanThreshold = 4; // [pixel] - const double ZoomThreshold = 6; // [pixel] - const double ZoomRatio = 0.13; // distance ratio - const Quantity_Color BgColor = Quantity_Color(0.145, 0.145, 0.145, Quantity_TOC_RGB); // color of viewer's background -} - -#endif // USERINTERACTIONPARAMETERS_H diff --git a/samples/qt/AndroidQt/AndroidQt_Window.cxx b/samples/qt/AndroidQt/AndroidQt_Window.cxx deleted file mode 100644 index 024b74dc75..0000000000 --- a/samples/qt/AndroidQt/AndroidQt_Window.cxx +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -IMPLEMENT_STANDARD_RTTIEXT(AndroidQt_Window, Aspect_Window) - -// ======================================================================= -// function : AndroidQt_Window -// purpose : -// ======================================================================= -AndroidQt_Window::AndroidQt_Window (const int theWidth, const int theHeight, - const int theX1, const int theX2, - const int theY1, const int theY2) -: myWidth (theWidth), myHeight(theHeight), - myX1 (theX1), myX2 (theX2), - myY1 (theY1), myY2 (theY2) -{ - if (myX1 == -1) myX1 = 0; - if (myX2 == -1) myX2 = myWidth; - - if (myY1 == -1) myY1 = 0; - if (myY2 == -1) myY2 = myHeight; -} - -// ======================================================================= -// function : Position -// purpose : -// ======================================================================= -void AndroidQt_Window::Position (Standard_Integer& theX1, - Standard_Integer& theY1, - Standard_Integer& theX2, - Standard_Integer& theY2) const -{ - theX1 = myX1; - theX2 = myX2; - theY1 = myY1; - theY2 = myY2; -} - -// ======================================================================= -// function : SetPosition -// purpose : -// ======================================================================= -void AndroidQt_Window::SetPosition (const Standard_Integer theX1, - const Standard_Integer theY1, - const Standard_Integer theX2, - const Standard_Integer theY2) -{ - myX1 = theX1; - myX2 = theX2; - myY1 = theY1; - myY2 = theY2; -} - -// ======================================================================= -// function : Size -// purpose : -// ======================================================================= -void AndroidQt_Window::Size (Standard_Integer& theWidth, - Standard_Integer& theHeight) const -{ - theWidth = myWidth; - theHeight = myHeight; -} - -// ======================================================================= -// function : SetSize -// purpose : -// ======================================================================= -void AndroidQt_Window::SetSize (const Standard_Integer theWidth, - const Standard_Integer theHeight) -{ - myWidth = theWidth; - myHeight = theHeight; -} diff --git a/samples/qt/AndroidQt/AndroidQt_Window.h b/samples/qt/AndroidQt/AndroidQt_Window.h deleted file mode 100644 index f0a0c0ec63..0000000000 --- a/samples/qt/AndroidQt/AndroidQt_Window.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef ANDROIDQT_WINDOW_H -#define ANDROIDQT_WINDOW_H - -#include - -//! This class defines dummy window. -//! The main functionality is viewport dimensions. -class AndroidQt_Window : public Aspect_Window -{ - DEFINE_STANDARD_RTTIEXT(AndroidQt_Window, Aspect_Window) -public: - - //! Creates a wrapper over existing Window handle - AndroidQt_Window(const int theWidth, const int theHeight, - const int theX1 = -1, const int theX2 = -1, - const int theY1 = -1, const int theY2 = -1); - - //! Returns native Window handle - virtual Aspect_Drawable NativeHandle() const { return 0; } - - //! Returns parent of native Window handle. - virtual Aspect_Drawable NativeParentHandle() const { return 0; } - - //! Returns native Window FB config (GLXFBConfig on Xlib) - virtual Aspect_FBConfig NativeFBConfig() const { return 0; } - - //! Opens the window - virtual void Map() const {} - - //! Closes the window - virtual void Unmap() const {} - - //! Applies the resizing to the window - virtual Aspect_TypeOfResize DoResize() const { return Aspect_TOR_UNKNOWN; } - - //! Apply the mapping change to the window - virtual Standard_Boolean DoMapping() const { return Standard_True; } - - //! Returns True if the window is opened - virtual Standard_Boolean IsMapped() const { return Standard_True; } - - //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions - virtual Standard_Real Ratio() const { return 1.0; } - - //! Returns The Window POSITION in PIXEL - virtual void Position (Standard_Integer& theX1, - Standard_Integer& theY1, - Standard_Integer& theX2, - Standard_Integer& theY2) const; - - //! Set The Window POSITION in PIXEL - virtual void SetPosition (const Standard_Integer theX1, - const Standard_Integer theY1, - const Standard_Integer theX2, - const Standard_Integer theY2); - - //! Returns The Window SIZE in PIXEL - virtual void Size (Standard_Integer& theWidth, - Standard_Integer& theHeight) const; - - //! Set The Window SIZE in PIXEL - virtual void SetSize (const Standard_Integer theWidth, - const Standard_Integer theHeight); - -private: - - int myWidth; - int myHeight; - - int myX1; - int myX2; - int myY1; - int myY2; - -}; - -#endif // ANDROIDQT_WINDOW_H diff --git a/samples/qt/AndroidQt/CMakeLists.txt b/samples/qt/AndroidQt/CMakeLists.txt new file mode 100644 index 0000000000..126582e8e2 --- /dev/null +++ b/samples/qt/AndroidQt/CMakeLists.txt @@ -0,0 +1,9 @@ +project(AndroidQt) + +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) + +ADD_DEFINITIONS(-DNO_Common_EXPORTS) + + diff --git a/samples/qt/AndroidQt/EXTERNLIB b/samples/qt/AndroidQt/EXTERNLIB new file mode 100644 index 0000000000..fb5edc8d1d --- /dev/null +++ b/samples/qt/AndroidQt/EXTERNLIB @@ -0,0 +1,17 @@ +TKernel +TKMath +TKG2d +TKG3d +TKGeomBase +TKBRep +TKGeomAlgo +TKTopAlgo +TKShHealing +TKService +TKMesh +TKHLR +TKV3d +TKOpenGl +CSF_FreeImagePlus +CSF_FREETYPE +CSF_OpenGlLibs diff --git a/samples/qt/AndroidQt/FILES b/samples/qt/AndroidQt/FILES new file mode 100644 index 0000000000..ca4f0e567b --- /dev/null +++ b/samples/qt/AndroidQt/FILES @@ -0,0 +1,2 @@ +EXTERNLIB +PACKAGES diff --git a/samples/qt/AndroidQt/Main.cxx b/samples/qt/AndroidQt/Main.cxx deleted file mode 100644 index 48102a5902..0000000000 --- a/samples/qt/AndroidQt/Main.cxx +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -#include - -int main(int argc, char *argv[]) -{ - QApplication app(argc, argv); - - qmlRegisterType("AndroidQt", 1, 0, "AndroidQt"); - - QQmlApplicationEngine engine; - engine.load (QUrl (QStringLiteral ("qrc:///res/qml/main.qml"))); - - return app.exec(); -} diff --git a/samples/qt/AndroidQt/PACKAGES b/samples/qt/AndroidQt/PACKAGES new file mode 100644 index 0000000000..089247b96e --- /dev/null +++ b/samples/qt/AndroidQt/PACKAGES @@ -0,0 +1 @@ +AndroidQt/src diff --git a/samples/qt/AndroidQt/ReadMe.md b/samples/qt/AndroidQt/ReadMe.md index 080f5cbfb3..d39dafbc42 100644 --- a/samples/qt/AndroidQt/ReadMe.md +++ b/samples/qt/AndroidQt/ReadMe.md @@ -13,8 +13,17 @@ Requirements for building sample: * Android SDK from 2014.07.02 or newer * Android NDK r9d or newer * Apache Ant 1.9.4 or higher - -Configure project for building sample: +* OCCT compiled under Android platform and placed in directories: + * occt\libs\armeabi-v7a\*.so and occt\inc\*.hxx (libraries and include files of OCCT install) + * android\assets\opencascade\shared\Shaders\* (Shaders folder of OCCT install: \share\opencascade\resources\Shaders) + * 3rdparty\include\freetype2\*, 3rdparty\include\FreeImage.h and 3rdparty\libs\armeabi-v7a\libFreeImage.so and 3rdparty\libs\armeabi-v7a\libfreetype.so + +It is also possible to to correct OCCT.pri file an get resources from another tree of directories. + +When AndroidQt will be started, it may be helpful to have some default data files(BRep) on Device for opening in AndroidQt. +Copy these files into "android\assets\opencascade\shared" and it will be installed to device during compilation procedure. + +Having prepared all these products, configure AndroidQt project for building sample: In QtCreator, open AndroidQt.pro project-file: ~~~~ @@ -28,27 +37,52 @@ Tools->Options->Android * In JDK location specify path to Java Development Kit * In Android SDK location specify path to Android SDK * In Android NDK location specify path to Android NDK +(During this location definition, warning is possible and OK: + "Qt version for architecture mips is missing. To add the Qt version, select Options > Build & Run > Qt Versins.") * In Ant executable specify path to ant.bat file located in Apache Ant bin directory -Make sure that "Android for armeabi-v7a" kit has been detected +Make sure that "Android for armeabi-v7a" kit has been detected (present in the list). ~~~~ Tools->Options->Build & Run ~~~~ -The paths to OCCT and 3rdparty libraries are specified in "OCCT.pri" file: +also or it can be checked or corrected in: +~~~~ +Projects->Android for armeabi-v7a option should be checked +~~~~ + +Switch On device, connect it to PC and define it in Qt Creator: +~~~~ +Projects->Manage Kits...->Devices->Device: Run on Android +~~~~ +Check that "Current state" is "Ready to use" on this page. + +~~~~ +Projects->Build Settings->General: Shadow build is switched OFF +~~~~ + +Start configuration: + +~~~~ +Call Build -> Run qmake +~~~~ +Check content of "Compile Output" view. -the paths to the headers: +In order to perform qmake correctly, for example if you have the following error: ~~~~ -INCLUDEPATH += /occt/inc /3rdparty/include -DEPENDPATH += /occt/inc /3rdparty/include +Running steps for project AndroidQt... +Could not start process "\android_armv7\bin\qmake.exe" \samples\qt\AndroidQt\AndroidQt.pro -r -spec android-g++ "CONFIG+=debug" "CONFIG+=declarative_debug" "CONFIG+=qml_debug" +Error while building/deploying project AndroidQt (kit: Android for armeabi-v7a (GCC 4.9, Qt 5.3.2)) +When executing step "qmake" ~~~~ -the libraries location: ~~~~ -LIBS += -L/occt/libs/armeabi-v7a +Projects->Build Settings->General: switch OFF Shadow build +Build->Build Project "Android Qt" +Build->Run ~~~~ -OCCT resources (Shaders, SHMessage, StdResource, TObj, UnitsAPI and XSMessage folder) should be copied to androidqt_dir/android/assets/opencascade/shared/ directory. Current sample requires at least Shaders folder. +Dialog to "Select Android Device" is shown. Select Compatible Device, Ok. +In case of any error, see log in "Application Output" view. -Select build configuration: Debug or Release and click Build->Build Project "AndroidQt" or (Ctrl + B). After successful build the application can be deployed to device or emulator. diff --git a/samples/qt/AndroidQt/res/qml/main.qml b/samples/qt/AndroidQt/res/qml/main.qml index c80be25fcc..2566fb29cd 100644 --- a/samples/qt/AndroidQt/res/qml/main.qml +++ b/samples/qt/AndroidQt/res/qml/main.qml @@ -62,7 +62,7 @@ Window { anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter - source: "qrc:///icons/res/icons/ic_action_collection.png" + source: "qrc:/ic_action_collection.png" } MouseArea { diff --git a/samples/qt/AndroidQt/src/AndroidQt.cxx b/samples/qt/AndroidQt/src/AndroidQt.cxx new file mode 100644 index 0000000000..70026c13ca --- /dev/null +++ b/samples/qt/AndroidQt/src/AndroidQt.cxx @@ -0,0 +1,291 @@ +// Copyright (c) 2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +// ======================================================================= +// function : AndroidQt +// purpose : +// ======================================================================= +AndroidQt::AndroidQt() +: myFitAllAction (false) +{ + connect (this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*))); + + // set shaders location variable + QByteArray aDataRoot = "/data/data/org.qtproject.example.AndroidQt/files/opencascade/shared"; + qputenv ("CSF_ShadersDirectory", aDataRoot + "/Shaders"); +} + +// ======================================================================= +// function : ReadShapeFromFile +// purpose : +// ======================================================================= +bool AndroidQt::ReadShapeFromFile (QString theFilePath) +{ + QUrl aFileUrl (theFilePath); + QString aFilePath = theFilePath; + if (aFileUrl.isLocalFile()) + { + aFilePath = QUrl (theFilePath).toLocalFile(); + } + + if (!QFile (aFilePath).exists()) + { + return false; + } + + TopoDS_Shape aShape; + BRep_Builder aBuildTool; + try + { + OCC_CATCH_SIGNALS + + if (!BRepTools::Read (aShape, aFilePath.toStdString().c_str(), aBuildTool)) + { + return false; + } + + if (!myContext.IsNull()) + { + myContext->EraseAll (Standard_False); + + Handle(AIS_Shape) aShapePrs = new AIS_Shape (aShape); + aShapePrs->SetColor (Quantity_Color(1.0, 0.73, 0.2, Quantity_TOC_RGB)); + + myContext->Display (aShapePrs, Standard_False); + myContext->SetDisplayMode (aShapePrs, AIS_Shaded, Standard_False); + } + + myMutex.lock(); + myFitAllAction = true; + myMutex.unlock(); + + if (window()) + { + window()->update(); + } + } + catch (Standard_Failure) + { + return false; + } + + return true; +} + +// ======================================================================= +// function : InitTouch +// purpose : +// ======================================================================= +void AndroidQt::InitTouch (const double theX, + const double theY) +{ + myMutex.lock(); + myTouchPoint.SetStarts (theX, theY); + myMutex.unlock(); +} + +// ======================================================================= +// function : UpdateTouch +// purpose : +// ======================================================================= +void AndroidQt::UpdateTouch (const double theX, + const double theY) +{ + myMutex.lock(); + myTouchPoint.SetEnds (theX, theY); + myMutex.unlock(); + + if (window()) + window()->update(); +} + +// ======================================================================= +// function : handleWindowChanged +// purpose : +// ======================================================================= +void AndroidQt::handleWindowChanged (QQuickWindow* theWin) +{ + if (theWin == NULL) + { + return; + } + + connect(theWin, SIGNAL(beforeSynchronizing()), this, SLOT(sync()), Qt::DirectConnection); + + theWin->setClearBeforeRendering (false); +} + +// ======================================================================= +// function : sync +// purpose : +// ======================================================================= +void AndroidQt::sync() +{ + myViewportSize = window()->size() * window()->devicePixelRatio(); + + if (myViewer.IsNull()) + { + initViewer(); + connect (window(), SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection); + } + else + { + Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myViewer->Driver()); + if (aDriver->getRawGlContext() != eglGetCurrentContext()) + { + initViewer(); + } + else + { + Handle(AndroidQt_Window) aWindow = Handle(AndroidQt_Window)::DownCast (myView->Window()); + aWindow->SetSize (myViewportSize.width(), myViewportSize.height()); + //myView->MustBeResized(); // can be used instead of SetWindow() when EGLsurface has not been changed + + EGLContext anEglContext = eglGetCurrentContext(); + myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext); + } + } +} + +// ======================================================================= +// function : paint +// purpose : +// ======================================================================= +void AndroidQt::paint() +{ + myMutex.lock(); + + if (Abs(myTouchPoint.DevX()) + Abs(myTouchPoint.DevY()) > 1) + { + myView->StartRotation (myTouchPoint.X().first, myTouchPoint.Y().first); + myView->Rotation (myTouchPoint.X().second, myTouchPoint.Y().second); + + myTouchPoint.ClearDev(); + } + + if (myFitAllAction) + { + myView->FitAll(); + myFitAllAction = false; + } + + myMutex.unlock(); + + myView->Redraw(); +} + +// ======================================================================= +// function : initViewer +// purpose : +// ======================================================================= +bool AndroidQt::initViewer() +{ + EGLint aCfgId = 0; + int aWidth = 0, aHeight = 0; + EGLDisplay anEglDisplay = eglGetCurrentDisplay(); + EGLContext anEglContext = eglGetCurrentContext(); + EGLSurface anEglSurf = eglGetCurrentSurface (EGL_DRAW); + + if (anEglDisplay == EGL_NO_DISPLAY + || anEglContext == EGL_NO_CONTEXT + || anEglSurf == EGL_NO_SURFACE) + { + release(); + return false; + } + + eglQuerySurface (anEglDisplay, anEglSurf, EGL_WIDTH, &aWidth); + eglQuerySurface (anEglDisplay, anEglSurf, EGL_HEIGHT, &aHeight); + eglQuerySurface (anEglDisplay, anEglSurf, EGL_CONFIG_ID, &aCfgId); + + const EGLint aConfigAttribs[] = { EGL_CONFIG_ID, aCfgId, EGL_NONE }; + EGLint aNbConfigs = 0; + void* anEglConfig = NULL; + + if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) != EGL_TRUE) + { + release(); + return false; + } + + if (!myViewer.IsNull()) + { + Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myViewer->Driver()); + Handle(AndroidQt_Window) aWindow = Handle(AndroidQt_Window)::DownCast (myView->Window()); + if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig)) + { + release(); + return false; + } + + aWindow->SetSize (aWidth, aHeight); + myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext); + } + + Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver (NULL, Standard_False); + aDriver->ChangeOptions().buffersNoSwap = Standard_True; + //aDriver->ChangeOptions().glslWarnings = Standard_True; // for GLSL shaders debug + + if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig)) + { + release(); + return false; + } + + // create viewer + myViewer = new V3d_Viewer (aDriver); + myViewer->SetDefaultBackgroundColor (AndroidQt_UserInteractionParameters::BgColor.Name()); + myViewer->SetDefaultLights(); + myViewer->SetLightOn(); + + // create AIS context + myContext = new AIS_InteractiveContext (myViewer); + myContext->SetDisplayMode (AIS_Shaded, false); + + Handle(AndroidQt_Window) aWindow = new AndroidQt_Window (aWidth, aHeight); + myView = myViewer->CreateView(); + + myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext); + myView->TriedronDisplay (Aspect_TOTP_RIGHT_LOWER, Quantity_NOC_WHITE, 0.08, V3d_ZBUFFER); + + return true; +} + +// ======================================================================= +// function : release +// purpose : +// ======================================================================= +void AndroidQt::release() +{ + myContext.Nullify(); + myView.Nullify(); + myViewer.Nullify(); +} diff --git a/samples/qt/AndroidQt/src/AndroidQt.h b/samples/qt/AndroidQt/src/AndroidQt.h new file mode 100644 index 0000000000..9bc0e57b78 --- /dev/null +++ b/samples/qt/AndroidQt/src/AndroidQt.h @@ -0,0 +1,88 @@ +// Copyright (c) 2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef ANDROIDQT_H +#define ANDROIDQT_H + +#include + +// workaround broken definitions in Qt +#define GLdouble GLdouble + +#include +#include + +#undef GLdouble + +#include +#include + +#include + +#include + +//! QML item with embedded OCCT viewer. +class AndroidQt : public QQuickItem +{ + Q_OBJECT + +public: + //! Default constructor. + AndroidQt(); + + //! Display shape from file. + Q_INVOKABLE bool ReadShapeFromFile (QString theFilePath); + + //! Handle touch event. + Q_INVOKABLE void InitTouch (const double theX, + const double theY); + + //! Handle touch event. + Q_INVOKABLE void UpdateTouch (const double theX, + const double theY); + +public slots: + + //! Handle OpenGL context creation and window resize events. + void sync(); + + //! Redraw OCCT viewer and handle pending viewer events in rendering thread. + void paint(); + +private slots: + + //! Handle window change event. + void handleWindowChanged (QQuickWindow* theWin); + +private: + + //! (Re-)initialize viewer on OpenGL context change. + bool initViewer(); + + //! Close viewer + void release(); + +private: + + Handle(V3d_Viewer) myViewer; //!< 3D viewer + Handle(V3d_View) myView; //!< 3D view + Handle(AIS_InteractiveContext) myContext; //!< interactive context + + QMutex myMutex; //!< mutex for interconnection with rendering thread + QSize myViewportSize; //!< QML item size + AndroidQt_TouchParameters myTouchPoint; //!< cached state of touch event + bool myFitAllAction; //!< queued viewer FitALL event + +}; + +#endif // ANDROIDQT_H diff --git a/samples/qt/AndroidQt/src/AndroidQt.qrc b/samples/qt/AndroidQt/src/AndroidQt.qrc new file mode 100644 index 0000000000..fbc4b4a719 --- /dev/null +++ b/samples/qt/AndroidQt/src/AndroidQt.qrc @@ -0,0 +1,8 @@ + + + ../res/qml/main.qml + + + ../res/icons/ic_action_collection.png + + diff --git a/samples/qt/AndroidQt/src/AndroidQt_TouchParameters.cxx b/samples/qt/AndroidQt/src/AndroidQt_TouchParameters.cxx new file mode 100644 index 0000000000..c844e26175 --- /dev/null +++ b/samples/qt/AndroidQt/src/AndroidQt_TouchParameters.cxx @@ -0,0 +1,107 @@ +// Copyright (c) 2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +// ======================================================================= +// function : AndroidQt_TouchParameters +// purpose : +// ======================================================================= +AndroidQt_TouchParameters::AndroidQt_TouchParameters() +: myXStart (0.0), + myXEnd (0.0), + myYStart (0.0), + myYEnd (0.0) +{ +} + +// ======================================================================= +// function : AndroidQt_TouchParameters +// purpose : +// ======================================================================= +AndroidQt_TouchParameters::AndroidQt_TouchParameters (const double theX, + const double theY) +: myXStart (theX), + myXEnd (theX), + myYStart (theY), + myYEnd (theY) +{ +} + +// ======================================================================= +// function : X +// purpose : +// ======================================================================= +QPair AndroidQt_TouchParameters::X() const +{ + return qMakePair(myXStart, myXEnd); +} + +// ======================================================================= +// function : DevX +// purpose : +// ======================================================================= +double AndroidQt_TouchParameters::DevX() const +{ + return myXEnd - myXStart; +} + +// ======================================================================= +// function : Y +// purpose : +// ======================================================================= +QPair AndroidQt_TouchParameters::Y() const +{ + return qMakePair(myYStart, myYEnd); +} + +// ======================================================================= +// function : DevY +// purpose : +// ======================================================================= +double AndroidQt_TouchParameters::DevY() const +{ + return myYEnd - myYStart; +} + +// ======================================================================= +// function : SetStarts +// purpose : +// ======================================================================= +void AndroidQt_TouchParameters::SetStarts (const double theXStart, + const double theYStart) +{ + myXStart = theXStart; + myYStart = theYStart; +} + +// ======================================================================= +// function : SetEnds +// purpose : +// ======================================================================= +void AndroidQt_TouchParameters::SetEnds (const double theXEnd, + const double theYEnd) +{ + myXEnd = theXEnd; + myYEnd = theYEnd; +} + +// ======================================================================= +// function : ClearDev +// purpose : +// ======================================================================= +void AndroidQt_TouchParameters::ClearDev() +{ + myXStart = myXEnd; + myYStart = myYEnd; +} diff --git a/samples/qt/AndroidQt/src/AndroidQt_TouchParameters.h b/samples/qt/AndroidQt/src/AndroidQt_TouchParameters.h new file mode 100644 index 0000000000..1debd06167 --- /dev/null +++ b/samples/qt/AndroidQt/src/AndroidQt_TouchParameters.h @@ -0,0 +1,60 @@ +// Copyright (c) 2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef ANDROIDQT_TOUCHPARAMETERS_H +#define ANDROIDQT_TOUCHPARAMETERS_H + +#include + +//! Class holding touch event state. +class AndroidQt_TouchParameters +{ + +public: + + //! Empty constructor. + AndroidQt_TouchParameters(); + + //! Default constructor. + AndroidQt_TouchParameters (const double theX, + const double theY); + + //! x coord + QPair X() const; + double DevX() const; + + //! y coord + QPair Y() const; + double DevY() const; + + //! Start coords + void SetStarts (const double theXStart, + const double theYStart); + + //! End coords + void SetEnds (const double theXEnd, + const double theYEnd); + + void ClearDev(); + +private: + + double myXStart; + double myXEnd; + + double myYStart; + double myYEnd; + +}; + +#endif // ANDROIDQT_TOUCHPARAMETERS_H diff --git a/samples/qt/AndroidQt/src/AndroidQt_UserInteractionParameters.h b/samples/qt/AndroidQt/src/AndroidQt_UserInteractionParameters.h new file mode 100644 index 0000000000..2010046397 --- /dev/null +++ b/samples/qt/AndroidQt/src/AndroidQt_UserInteractionParameters.h @@ -0,0 +1,28 @@ +// Copyright (c) 2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef ANDROIDQT_USERINTERACTIONPARAMETERS_H +#define ANDROIDQT_USERINTERACTIONPARAMETERS_H + +#include + +namespace AndroidQt_UserInteractionParameters +{ + const double RotationThreshold = 2; // [pixel] + const double PanThreshold = 4; // [pixel] + const double ZoomThreshold = 6; // [pixel] + const double ZoomRatio = 0.13; // distance ratio + const Quantity_Color BgColor = Quantity_Color(0.145, 0.145, 0.145, Quantity_TOC_RGB); // color of viewer's background +} + +#endif // USERINTERACTIONPARAMETERS_H diff --git a/samples/qt/AndroidQt/src/AndroidQt_Window.cxx b/samples/qt/AndroidQt/src/AndroidQt_Window.cxx new file mode 100644 index 0000000000..024b74dc75 --- /dev/null +++ b/samples/qt/AndroidQt/src/AndroidQt_Window.cxx @@ -0,0 +1,86 @@ +// Copyright (c) 2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include + +IMPLEMENT_STANDARD_RTTIEXT(AndroidQt_Window, Aspect_Window) + +// ======================================================================= +// function : AndroidQt_Window +// purpose : +// ======================================================================= +AndroidQt_Window::AndroidQt_Window (const int theWidth, const int theHeight, + const int theX1, const int theX2, + const int theY1, const int theY2) +: myWidth (theWidth), myHeight(theHeight), + myX1 (theX1), myX2 (theX2), + myY1 (theY1), myY2 (theY2) +{ + if (myX1 == -1) myX1 = 0; + if (myX2 == -1) myX2 = myWidth; + + if (myY1 == -1) myY1 = 0; + if (myY2 == -1) myY2 = myHeight; +} + +// ======================================================================= +// function : Position +// purpose : +// ======================================================================= +void AndroidQt_Window::Position (Standard_Integer& theX1, + Standard_Integer& theY1, + Standard_Integer& theX2, + Standard_Integer& theY2) const +{ + theX1 = myX1; + theX2 = myX2; + theY1 = myY1; + theY2 = myY2; +} + +// ======================================================================= +// function : SetPosition +// purpose : +// ======================================================================= +void AndroidQt_Window::SetPosition (const Standard_Integer theX1, + const Standard_Integer theY1, + const Standard_Integer theX2, + const Standard_Integer theY2) +{ + myX1 = theX1; + myX2 = theX2; + myY1 = theY1; + myY2 = theY2; +} + +// ======================================================================= +// function : Size +// purpose : +// ======================================================================= +void AndroidQt_Window::Size (Standard_Integer& theWidth, + Standard_Integer& theHeight) const +{ + theWidth = myWidth; + theHeight = myHeight; +} + +// ======================================================================= +// function : SetSize +// purpose : +// ======================================================================= +void AndroidQt_Window::SetSize (const Standard_Integer theWidth, + const Standard_Integer theHeight) +{ + myWidth = theWidth; + myHeight = theHeight; +} diff --git a/samples/qt/AndroidQt/src/AndroidQt_Window.h b/samples/qt/AndroidQt/src/AndroidQt_Window.h new file mode 100644 index 0000000000..f0a0c0ec63 --- /dev/null +++ b/samples/qt/AndroidQt/src/AndroidQt_Window.h @@ -0,0 +1,90 @@ +// Copyright (c) 2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef ANDROIDQT_WINDOW_H +#define ANDROIDQT_WINDOW_H + +#include + +//! This class defines dummy window. +//! The main functionality is viewport dimensions. +class AndroidQt_Window : public Aspect_Window +{ + DEFINE_STANDARD_RTTIEXT(AndroidQt_Window, Aspect_Window) +public: + + //! Creates a wrapper over existing Window handle + AndroidQt_Window(const int theWidth, const int theHeight, + const int theX1 = -1, const int theX2 = -1, + const int theY1 = -1, const int theY2 = -1); + + //! Returns native Window handle + virtual Aspect_Drawable NativeHandle() const { return 0; } + + //! Returns parent of native Window handle. + virtual Aspect_Drawable NativeParentHandle() const { return 0; } + + //! Returns native Window FB config (GLXFBConfig on Xlib) + virtual Aspect_FBConfig NativeFBConfig() const { return 0; } + + //! Opens the window + virtual void Map() const {} + + //! Closes the window + virtual void Unmap() const {} + + //! Applies the resizing to the window + virtual Aspect_TypeOfResize DoResize() const { return Aspect_TOR_UNKNOWN; } + + //! Apply the mapping change to the window + virtual Standard_Boolean DoMapping() const { return Standard_True; } + + //! Returns True if the window is opened + virtual Standard_Boolean IsMapped() const { return Standard_True; } + + //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions + virtual Standard_Real Ratio() const { return 1.0; } + + //! Returns The Window POSITION in PIXEL + virtual void Position (Standard_Integer& theX1, + Standard_Integer& theY1, + Standard_Integer& theX2, + Standard_Integer& theY2) const; + + //! Set The Window POSITION in PIXEL + virtual void SetPosition (const Standard_Integer theX1, + const Standard_Integer theY1, + const Standard_Integer theX2, + const Standard_Integer theY2); + + //! Returns The Window SIZE in PIXEL + virtual void Size (Standard_Integer& theWidth, + Standard_Integer& theHeight) const; + + //! Set The Window SIZE in PIXEL + virtual void SetSize (const Standard_Integer theWidth, + const Standard_Integer theHeight); + +private: + + int myWidth; + int myHeight; + + int myX1; + int myX2; + int myY1; + int myY2; + +}; + +#endif // ANDROIDQT_WINDOW_H diff --git a/samples/qt/AndroidQt/src/FILES b/samples/qt/AndroidQt/src/FILES new file mode 100644 index 0000000000..0bb880c9b3 --- /dev/null +++ b/samples/qt/AndroidQt/src/FILES @@ -0,0 +1,9 @@ +AndroidQt.cxx +AndroidQt.h +AndroidQt.qrc +AndroidQt_TouchParameters.cxx +AndroidQt_TouchParameters.h +AndroidQt_UserInteractionParameters.h +AndroidQt_Window.cxx +AndroidQt_Window.h +Main.cxx diff --git a/samples/qt/AndroidQt/src/Main.cxx b/samples/qt/AndroidQt/src/Main.cxx new file mode 100644 index 0000000000..dca2797359 --- /dev/null +++ b/samples/qt/AndroidQt/src/Main.cxx @@ -0,0 +1,29 @@ +// Copyright (c) 2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + qmlRegisterType("AndroidQt", 1, 0, "AndroidQt"); + + QQmlApplicationEngine engine; + engine.load (QUrl (QStringLiteral ("qrc:/main.qml"))); + + return app.exec(); +} diff --git a/samples/qt/Common/src/ApplicationCommon.cxx b/samples/qt/Common/src/ApplicationCommon.cxx index ee65f377ce..a3e94903ab 100755 --- a/samples/qt/Common/src/ApplicationCommon.cxx +++ b/samples/qt/Common/src/ApplicationCommon.cxx @@ -15,6 +15,7 @@ #include #include +#include #include @@ -583,8 +584,10 @@ void ApplicationCommonWindow::onSetMaterial( int theMaterial ) QString ApplicationCommonWindow::getResourceDir() { static QString aResourceDir = - QString::fromUtf8 (qgetenv ("CSF_ResourcesDefaults").constData()); - + QString (OSD_Environment ("CSF_ResourcesDefaults").Value().ToCString()); + if (aResourceDir.isEmpty()) + aResourceDir = QString (OSD_Environment ("CSF_OCCTResourcePath").Value().ToCString()) + "/samples"; + return aResourceDir; } diff --git a/samples/qt/Common/src/DocumentCommon.cxx b/samples/qt/Common/src/DocumentCommon.cxx index 19aaac6b3f..f19194ec2d 100755 --- a/samples/qt/Common/src/DocumentCommon.cxx +++ b/samples/qt/Common/src/DocumentCommon.cxx @@ -13,6 +13,9 @@ #include #include #include +#if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) +#include +#endif #include // ======================================================================= @@ -32,7 +35,7 @@ Handle(V3d_Viewer) DocumentCommon::Viewer (const Standard_ExtString , { Handle(Aspect_DisplayConnection) aDisplayConnection; #if !defined(_WIN32) && !defined(__WIN32__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) - aDisplayConnection = new Aspect_DisplayConnection (qgetenv ("DISPLAY").constData()); + aDisplayConnection = new Aspect_DisplayConnection (OSD_Environment ("DISPLAY").Value()); #endif aGraphicDriver = new OpenGl_GraphicDriver (aDisplayConnection); } diff --git a/samples/qt/Common/src/FILES b/samples/qt/Common/src/FILES new file mode 100644 index 0000000000..12ba2818f3 --- /dev/null +++ b/samples/qt/Common/src/FILES @@ -0,0 +1,17 @@ +ApplicationCommon.cxx +ApplicationCommon.h +Common-icon.ts +Common-string.ts +CommonSample.h +DocumentCommon.cxx +DocumentCommon.h +Material.cxx +Material.h +MDIWindow.cxx +MDIWindow.h +OcctWindow.cxx +OcctWindow.h +Transparency.cxx +Transparency.h +View.cxx +View.h diff --git a/samples/qt/Common/src/MDIWindow.cxx b/samples/qt/Common/src/MDIWindow.cxx index e1315ce6ee..f09bce4064 100755 --- a/samples/qt/Common/src/MDIWindow.cxx +++ b/samples/qt/Common/src/MDIWindow.cxx @@ -105,7 +105,6 @@ void MDIWindow::onWindowActivated () void MDIWindow::dump() { - QString datadir = (QString(qgetenv ("CSF_OCCTDataPath").constData()) + "/images"); QString filter = "Images Files (*.bmp *.ppm *.png *.jpg *.tiff *.tga *.gif *.exr)"; QFileDialog fd ( 0 ); fd.setModal( true ); diff --git a/samples/qt/FuncDemo/CMakeLists.txt b/samples/qt/FuncDemo/CMakeLists.txt new file mode 100644 index 0000000000..92dc1e6281 --- /dev/null +++ b/samples/qt/FuncDemo/CMakeLists.txt @@ -0,0 +1,5 @@ +project(FuncDemo) + +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) diff --git a/samples/qt/FuncDemo/EXTERNLIB b/samples/qt/FuncDemo/EXTERNLIB new file mode 100644 index 0000000000..7ced3fdd54 --- /dev/null +++ b/samples/qt/FuncDemo/EXTERNLIB @@ -0,0 +1,14 @@ +TKBO +TKBRep +TKCAF +TKCDF +TKG2d +TKG3d +TKGeomAlgo +TKGeomBase +TKernel +TKLCAF +TKMath +TKMesh +TKPrim +TKTopAlgo diff --git a/samples/qt/FuncDemo/FILES b/samples/qt/FuncDemo/FILES new file mode 100644 index 0000000000..ca4f0e567b --- /dev/null +++ b/samples/qt/FuncDemo/FILES @@ -0,0 +1,2 @@ +EXTERNLIB +PACKAGES diff --git a/samples/qt/FuncDemo/FuncDemo.pro b/samples/qt/FuncDemo/FuncDemo.pro index 67df58079a..d462720bd4 100644 --- a/samples/qt/FuncDemo/FuncDemo.pro +++ b/samples/qt/FuncDemo/FuncDemo.pro @@ -14,6 +14,8 @@ OCCT_DEFINES = $$(CSF_DEFINES) DEFINES = $$split(OCCT_DEFINES, ;) +RESOURCES += ./src/FuncDemo.qrc + unix { UNAME = $$system(uname -s) LIBLIST = $$(LD_LIBRARY_PATH) diff --git a/samples/qt/FuncDemo/PACKAGES b/samples/qt/FuncDemo/PACKAGES new file mode 100644 index 0000000000..6417933607 --- /dev/null +++ b/samples/qt/FuncDemo/PACKAGES @@ -0,0 +1 @@ +FuncDemo/src \ No newline at end of file diff --git a/samples/qt/FuncDemo/env.bat b/samples/qt/FuncDemo/env.bat index d0450d73cd..78c73fc58a 100644 --- a/samples/qt/FuncDemo/env.bat +++ b/samples/qt/FuncDemo/env.bat @@ -4,5 +4,4 @@ call "%~dp0..\..\..\env.bat" %1 %2 %3 call "custom.bat" %1 %2 %3 -set "PATH=%QTDIR%/bin;%PATH%" -set "QT_QPA_PLATFORM_PLUGIN_PATH=%QTDIR%\plugins\platforms" \ No newline at end of file +set "PATH=%QTDIR%/bin;%PATH%" \ No newline at end of file diff --git a/samples/qt/FuncDemo/src/FILES b/samples/qt/FuncDemo/src/FILES new file mode 100644 index 0000000000..07ace65e6e --- /dev/null +++ b/samples/qt/FuncDemo/src/FILES @@ -0,0 +1,28 @@ +BaseDriver.cpp +BaseDriver.h +CircleDriver.cpp +CircleDriver.h +ConeDriver.cpp +ConeDriver.h +CylinderDriver.cpp +CylinderDriver.h +edge.cpp +edge.h +FILES +FThread.cpp +FThread.h +graphwidget.cpp +graphwidget.h +main.cpp +mainwindow.cpp +mainwindow.h +node.cpp +node.h +PointDriver.cpp +PointDriver.h +PrismDriver.cpp +PrismDriver.h +ShapeSaverDriver.cpp +ShapeSaverDriver.h +SimpleDriver.cpp +SimpleDriver.h diff --git a/samples/qt/FuncDemo/src/FuncDemo.qrc b/samples/qt/FuncDemo/src/FuncDemo.qrc new file mode 100644 index 0000000000..57e284ec48 --- /dev/null +++ b/samples/qt/FuncDemo/src/FuncDemo.qrc @@ -0,0 +1,7 @@ + + + ../images/new.png + ../images/open.png + ../images/save.png + + diff --git a/samples/qt/FuncDemo/src/main.cpp b/samples/qt/FuncDemo/src/main.cpp index 7ddfdf73f3..4f35cca9ea 100644 --- a/samples/qt/FuncDemo/src/main.cpp +++ b/samples/qt/FuncDemo/src/main.cpp @@ -41,8 +41,15 @@ #include #include "mainwindow.h" +#include + int main(int argc, char *argv[]) { +#if QT_VERSION > 0x050000 + TCollection_AsciiString aPlugindsDirName = OSD_Environment ("QTDIR").Value(); + if (!aPlugindsDirName.IsEmpty()) + QApplication::addLibraryPath (QString (aPlugindsDirName.ToCString()) + "/plugins"); +#endif QApplication app(argc, argv); MainWindow mainWin; mainWin.show(); diff --git a/samples/qt/IESample/CMakeLists.txt b/samples/qt/IESample/CMakeLists.txt new file mode 100644 index 0000000000..d29fa8bae0 --- /dev/null +++ b/samples/qt/IESample/CMakeLists.txt @@ -0,0 +1,11 @@ +project(IESample) + +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) +include_directories("${CMAKE_SOURCE_DIR}/${RELATIVE_DIR}/Interface/src") +include_directories("${CMAKE_SOURCE_DIR}/${RELATIVE_DIR}/Common/src") +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) + +ADD_DEFINITIONS(-DNO_COMMONSAMPLE_EXPORTS -DNO_IESAMPLE_EXPORTS) + + diff --git a/samples/qt/IESample/EXTERNLIB b/samples/qt/IESample/EXTERNLIB new file mode 100644 index 0000000000..71631a4b6f --- /dev/null +++ b/samples/qt/IESample/EXTERNLIB @@ -0,0 +1,29 @@ +TKBRep +TKBool +TKBO +TKCDF +TKFillet +TKG2d +TKG3d +TKGeomAlgo +TKGeomBase +TKHLR +TKIGES +TKernel +TKMath +TKMesh +TKOffset +TKOpenGl +TKPrim +TKShHealing +TKService +TKSTEP +TKSTEP209 +TKSTEPAttr +TKSTEPBase +TKSTL +TKTopAlgo +TKV3d +TKVRML +TKXSBase + diff --git a/samples/qt/IESample/FILES b/samples/qt/IESample/FILES new file mode 100644 index 0000000000..ca4f0e567b --- /dev/null +++ b/samples/qt/IESample/FILES @@ -0,0 +1,2 @@ +EXTERNLIB +PACKAGES diff --git a/samples/qt/IESample/PACKAGES b/samples/qt/IESample/PACKAGES new file mode 100644 index 0000000000..aa9aa1a3ca --- /dev/null +++ b/samples/qt/IESample/PACKAGES @@ -0,0 +1,3 @@ +IESample/src +Common/src +Interface/src \ No newline at end of file diff --git a/samples/qt/IESample/env.bat b/samples/qt/IESample/env.bat index 90a5c2cebd..3b7e3e4eb7 100755 --- a/samples/qt/IESample/env.bat +++ b/samples/qt/IESample/env.bat @@ -9,4 +9,3 @@ set "CSF_ResourcesDefaults=%RES_DIR%" set "CSF_IEResourcesDefaults=%RES_DIR%" set "PATH=%QTDIR%/bin;%PATH%" -set "QT_QPA_PLATFORM_PLUGIN_PATH=%QTDIR%\plugins\platforms" \ No newline at end of file diff --git a/samples/qt/IESample/src/FILES b/samples/qt/IESample/src/FILES new file mode 100644 index 0000000000..f9dea79a18 --- /dev/null +++ b/samples/qt/IESample/src/FILES @@ -0,0 +1 @@ +Main.cxx \ No newline at end of file diff --git a/samples/qt/IESample/src/Main.cxx b/samples/qt/IESample/src/Main.cxx index 7baef2703f..87b7924d97 100755 --- a/samples/qt/IESample/src/Main.cxx +++ b/samples/qt/IESample/src/Main.cxx @@ -1,15 +1,20 @@ #include "Application.h" +#include + #include #include #include #include - int main ( int argc, char* argv[] ) { - +#if QT_VERSION > 0x050000 + TCollection_AsciiString aPlugindsDirName = OSD_Environment ("QTDIR").Value(); + if (!aPlugindsDirName.IsEmpty()) + QApplication::addLibraryPath (QString (aPlugindsDirName.ToCString()) + "/plugins"); +#endif QApplication a( argc, argv ); QString resDir = ApplicationCommonWindow::getResourceDir(); diff --git a/samples/qt/Interface/src/Application.cxx b/samples/qt/Interface/src/Application.cxx index b14e7d4bc8..ec3cdca222 100755 --- a/samples/qt/Interface/src/Application.cxx +++ b/samples/qt/Interface/src/Application.cxx @@ -6,6 +6,8 @@ #include #include +#include + ApplicationWindow::ApplicationWindow() : ApplicationCommonWindow( ), myImportPopup( 0 ), @@ -210,8 +212,10 @@ void ApplicationWindow::onSelectionChanged() QString ApplicationWindow::getIEResourceDir() { static QString aResourceDir = - QString::fromUtf8 (qgetenv ("CSF_IEResourcesDefaults").constData()); - + QString (OSD_Environment ("CSF_IEResourcesDefaults").Value().ToCString()); + if (aResourceDir.isEmpty()) + aResourceDir = QString (OSD_Environment ("CSF_OCCTResourcePath").Value().ToCString()) + "/samples"; + return aResourceDir; } diff --git a/samples/qt/Interface/src/FILES b/samples/qt/Interface/src/FILES new file mode 100644 index 0000000000..c338ab41f5 --- /dev/null +++ b/samples/qt/Interface/src/FILES @@ -0,0 +1,6 @@ +Application.cxx +Application.h +IESample.h +Interface-string.ts +Translate.cxx +Translate.h diff --git a/samples/qt/Tutorial/CMakeLists.txt b/samples/qt/Tutorial/CMakeLists.txt new file mode 100644 index 0000000000..c5b08c52ec --- /dev/null +++ b/samples/qt/Tutorial/CMakeLists.txt @@ -0,0 +1,11 @@ +project(Tutorial) + +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) +include_directories("${CMAKE_SOURCE_DIR}/${RELATIVE_DIR}/Interface/src") +include_directories("${CMAKE_SOURCE_DIR}/${RELATIVE_DIR}/Common/src") +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) + +ADD_DEFINITIONS(-DNO_COMMONSAMPLE_EXPORTS -DNO_IESAMPLE_EXPORTS) + + diff --git a/samples/qt/Tutorial/EXTERNLIB b/samples/qt/Tutorial/EXTERNLIB new file mode 100644 index 0000000000..8beff5afee --- /dev/null +++ b/samples/qt/Tutorial/EXTERNLIB @@ -0,0 +1,29 @@ +TKBRep +TKBool +TKBO +TKCDF +TKFillet +TKG2d +TKG3d +TKGeomAlgo +TKGeomBase +TKernel +TKHLR +TKIGES +TKMath +TKMesh +TKOffset +TKOpenGl +TKPrim +TKService +TKShHealing +TKSTEP +TKSTEP209 +TKSTEPAttr +TKSTEPBase +TKSTL +TKTopAlgo +TKV3d +TKVRML +TKXSBase + diff --git a/samples/qt/Tutorial/FILES b/samples/qt/Tutorial/FILES new file mode 100644 index 0000000000..ca4f0e567b --- /dev/null +++ b/samples/qt/Tutorial/FILES @@ -0,0 +1,2 @@ +EXTERNLIB +PACKAGES diff --git a/samples/qt/Tutorial/PACKAGES b/samples/qt/Tutorial/PACKAGES new file mode 100644 index 0000000000..bd31a4fb0b --- /dev/null +++ b/samples/qt/Tutorial/PACKAGES @@ -0,0 +1,2 @@ +Tutorial/src +Common/src \ No newline at end of file diff --git a/samples/qt/Tutorial/env.bat b/samples/qt/Tutorial/env.bat index 781e09ef67..56b7eeb0c8 100755 --- a/samples/qt/Tutorial/env.bat +++ b/samples/qt/Tutorial/env.bat @@ -9,4 +9,3 @@ set "CSF_ResourcesDefaults=%RES_DIR%" set "CSF_TutorialResourcesDefaults=%RES_DIR%" set "PATH=%QTDIR%/bin;%PATH%" -set "QT_QPA_PLATFORM_PLUGIN_PATH=%QTDIR%\plugins\platforms" \ No newline at end of file diff --git a/samples/qt/Tutorial/src/ApplicationTut.cxx b/samples/qt/Tutorial/src/ApplicationTut.cxx index 6a6baa5aa4..5be0008f5c 100755 --- a/samples/qt/Tutorial/src/ApplicationTut.cxx +++ b/samples/qt/Tutorial/src/ApplicationTut.cxx @@ -1,6 +1,8 @@ #include "ApplicationTut.h" #include "DocumentTut.h" +#include + #include #include #include @@ -59,7 +61,8 @@ void ApplicationTut::onMakeBottleAction() QString ApplicationTut::getTutResourceDir() { - static QString resDir (qgetenv ("CSF_TutorialResourcesDefaults").constData()); + static QString resDir (OSD_Environment ("CSF_TutorialResourcesDefaults").Value().ToCString()); + if (resDir.isEmpty()) + resDir = QString (OSD_Environment ("CSF_OCCTResourcePath").Value().ToCString()) + "/samples"; return resDir; } - diff --git a/samples/qt/Tutorial/src/FILES b/samples/qt/Tutorial/src/FILES new file mode 100644 index 0000000000..54bd00b648 --- /dev/null +++ b/samples/qt/Tutorial/src/FILES @@ -0,0 +1,8 @@ +ApplicationTut.cxx +ApplicationTut.h +DocumentTut.cxx +DocumentTut.h +Main.cxx +MakeBottle.cxx +Tutorial-icon.ts +Tutorial-string.ts diff --git a/samples/qt/Tutorial/src/Main.cxx b/samples/qt/Tutorial/src/Main.cxx index 1d4cfe4685..1603de271d 100755 --- a/samples/qt/Tutorial/src/Main.cxx +++ b/samples/qt/Tutorial/src/Main.cxx @@ -1,10 +1,17 @@ #include "ApplicationTut.h" +#include + #include #include int main ( int argc, char* argv[] ) { +#if QT_VERSION > 0x050000 + TCollection_AsciiString aPlugindsDirName = OSD_Environment ("QTDIR").Value(); + if (!aPlugindsDirName.IsEmpty()) + QApplication::addLibraryPath (QString (aPlugindsDirName.ToCString()) + "/plugins"); +#endif QApplication a( argc, argv ); QString resDir = ApplicationCommonWindow::getResourceDir(); diff --git a/samples/tools/TInspectorEXE/CMakeLists.txt b/samples/tools/TInspectorEXE/CMakeLists.txt index 070c323411..f7eb48ea40 100644 --- a/samples/tools/TInspectorEXE/CMakeLists.txt +++ b/samples/tools/TInspectorEXE/CMakeLists.txt @@ -1,5 +1,7 @@ project(TInspectorEXE) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_tool) - -set_property (TARGET ${PROJECT_NAME} PROPERTY FOLDER Samples) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) +set (RELATIVE_DIR "samples/tools") +include_directories("${CMAKE_SOURCE_DIR}/${RELATIVE_DIR}/TInspectorEXE/src") +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_sample) diff --git a/samples/tools/TInspectorEXE/FILES b/samples/tools/TInspectorEXE/FILES index b1a28198cd..ca4f0e567b 100644 --- a/samples/tools/TInspectorEXE/FILES +++ b/samples/tools/TInspectorEXE/FILES @@ -1,5 +1,2 @@ -TInspectorEXE.cxx -TInspectorEXE_OpenFileDialog.cxx -TInspectorEXE_OpenFileDialog.hxx -TInspectorEXE_OpenFileViewModel.cxx -TInspectorEXE_OpenFileViewModel.hxx +EXTERNLIB +PACKAGES diff --git a/samples/tools/TInspectorEXE/PACKAGES b/samples/tools/TInspectorEXE/PACKAGES new file mode 100644 index 0000000000..51a97991c3 --- /dev/null +++ b/samples/tools/TInspectorEXE/PACKAGES @@ -0,0 +1 @@ +TInspectorEXE/src diff --git a/samples/tools/TInspectorEXE/TInspectorEXE.cxx b/samples/tools/TInspectorEXE/TInspectorEXE.cxx deleted file mode 100644 index 7523a95f9e..0000000000 --- a/samples/tools/TInspectorEXE/TInspectorEXE.cxx +++ /dev/null @@ -1,136 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - - -#include - -#include - -#include - -#include -#include -#include -#include -#include - -#include - -// ======================================================================= -// function : fileNameInDataDir -// purpose : -// ======================================================================= -TCollection_AsciiString fileNameInDataDir(const TCollection_AsciiString& theEnvironmentDir, - const TCollection_AsciiString& theName) -{ - OSD_Environment anEnvironment(theEnvironmentDir); - - TCollection_AsciiString aFileName = anEnvironment.Value(); - aFileName += TCollection_AsciiString("/") + theName; - - return aFileName; -} - -// ======================================================================= -// function : setPluginSampleDirectory -// purpose : -// ======================================================================= -void setPluginSampleDirectory (const TCollection_AsciiString& theName, TInspector_Communicator* theCommunicator, - TInspectorEXE_OpenButton* theButtonControl) -{ - if (theName.IsEqual ("TKDFBrowser")) - { - theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "step/screw.step")); - theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "step")); - } - else if (theName.IsEqual ("TKShapeView")) - { - theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/hammer.brep")); - theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ")); - } - else if (theName.IsEqual ("TKVInspector")) - { - theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/face1.brep")); - theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/face2.brep")); - theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ")); - } -} - -// ======================================================================= -// function : main -// purpose : -// ======================================================================= -int main (int argc, char** argv) -{ - OSD_Environment anEnvironment ("QTDIR"); - TCollection_AsciiString aPlugindsDirName = anEnvironment.Value(); - if (aPlugindsDirName.IsEmpty()) - { - std::cout << "QTDIR is not defined" << std::endl; - return 0; - } - aPlugindsDirName += "/plugins"; - QApplication::addLibraryPath (aPlugindsDirName.ToCString()); - QApplication anApp (argc, argv); - - std::set aPlugins; - for (int anArgId = 1; anArgId < argc; anArgId++ ) - { - if (!strcmp (argv[anArgId], "dfbrowser")) - aPlugins.insert ("TKDFBrowser"); - - if (!strcmp (argv[anArgId], "shapeview")) - aPlugins.insert ("TKShapeView"); - - if (!strcmp (argv[anArgId], "vinspector")) - aPlugins.insert ("TKVInspector"); - } - NCollection_List aParameters; - - // Create tool communicator - TInspector_Communicator* aCommunicator = TInspectorEXE_OpenFileDialog::Communicator(); - if (!aCommunicator) - { - std::cout << "Communicator can not be created" << std::endl; - return 0; - } - - TInspectorEXE_OpenButton* aButtonControl = new TInspectorEXE_OpenButton (0); - TCollection_AsciiString anActivatedPluginName; - if (aPlugins.empty()) - { - aPlugins.insert("TKDFBrowser"); - aPlugins.insert("TKShapeView"); - aPlugins.insert("TKVInspector"); - - anActivatedPluginName = "TKDFBrowser"; - } - else - anActivatedPluginName = *aPlugins.rbegin(); - - for (std::set::const_iterator aPluginIt = aPlugins.begin(); aPluginIt != aPlugins.end(); aPluginIt++) - { - TCollection_AsciiString aName = *aPluginIt; - aCommunicator->RegisterPlugin (aName); - aCommunicator->Init (aName, aParameters); - setPluginSampleDirectory (aName, aCommunicator, aButtonControl); - } - aCommunicator->Activate (anActivatedPluginName); - - aCommunicator->SetVisible (true); - aCommunicator->SetOpenButton (aButtonControl->StartButton()); - - return anApp.exec(); -} diff --git a/samples/tools/TInspectorEXE/TInspectorEXE.qrc b/samples/tools/TInspectorEXE/TInspectorEXE.qrc deleted file mode 100644 index 331296a3d7..0000000000 --- a/samples/tools/TInspectorEXE/TInspectorEXE.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - icons/folder_open.png - icons/folder_import.png - - diff --git a/samples/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.cxx b/samples/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.cxx deleted file mode 100644 index 4607755c2b..0000000000 --- a/samples/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.cxx +++ /dev/null @@ -1,311 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -const int FONT_POINT_SIZE = 18; -const int ICON_SIZE = 40; - -const int OPEN_DIALOG_WIDTH = 550; -const int OPEN_DIALOG_HEIGHT = 200; - -const int MARGIN_DIALOG = 4; -const int SPACING_DIALOG = 2; - -TInspector_Communicator* MyCommunicator; - -// ======================================================================= -// function : StartButton -// purpose : -// ======================================================================= -QPushButton* TInspectorEXE_OpenButton::StartButton() -{ - if (!myStartButton) - { - myStartButton = new QPushButton(); - myStartButton->setIcon (QIcon (":/icons/folder_open.png")); - connect (myStartButton, SIGNAL (clicked()), this, SLOT (onStartButtonClicked())); - } - return myStartButton; -} - -// ======================================================================= -// function : onStartButtonClicked -// purpose : -// ======================================================================= -void TInspectorEXE_OpenButton::onStartButtonClicked() -{ - QPushButton* aButton = (QPushButton*)sender(); - TCollection_AsciiString aPluginName (aButton->objectName().toStdString().c_str()); - if (aPluginName.IsEmpty()) - return; - - QString aDataDirName = QDir::currentPath(); - if (myDefaultDirs.IsBound (aPluginName)) - aDataDirName = myDefaultDirs.Find (aPluginName).ToCString(); - - QString aFileName = TInspectorEXE_OpenFileDialog::OpenFile (0, aDataDirName); - aFileName = QDir().toNativeSeparators (aFileName); - if (!aFileName.isEmpty()) { - QApplication::setOverrideCursor (Qt::WaitCursor); - TInspectorEXE_OpenFileDialog::Communicator()->OpenFile (aPluginName, TCollection_AsciiString (aFileName.toUtf8().data())); - QApplication::restoreOverrideCursor(); - } -} - -// ======================================================================= -// function : changeMargins -// purpose : -// ======================================================================= -void changeMargins (QBoxLayout* theLayout) -{ - theLayout->setContentsMargins (MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG); - theLayout->setSpacing (SPACING_DIALOG); -} - -// ======================================================================= -// function : Constructor -// purpose : -// ======================================================================= -TInspectorEXE_OpenFileDialog::TInspectorEXE_OpenFileDialog (QWidget* theParent, const QString& theDataDirName) -: QDialog(theParent), myDataDir (theDataDirName) -{ - setWindowTitle (theDataDirName); - - QVBoxLayout* aDialogLay = new QVBoxLayout (this); - changeMargins (aDialogLay); - - // Title label - QLabel* aTitleLabel = new QLabel (this); - aTitleLabel->setText (tr ("Open File")); - aDialogLay->addWidget (aTitleLabel); - - // Samples View - QGroupBox* aSamplesBox = new QGroupBox (this); - aSamplesBox->setTitle (tr ("Samples")); - aDialogLay->addWidget (aSamplesBox); - QVBoxLayout* aSampleLay = new QVBoxLayout (aSamplesBox); - changeMargins (aSampleLay); - mySamplesView = createTableView (readSampleNames()); - aSampleLay->addWidget (mySamplesView); - - // Select file - QGroupBox* aSelectFileBox = new QGroupBox (this); - aSelectFileBox->setTitle (tr ("Select file")); - aDialogLay->addWidget (aSelectFileBox); - QGridLayout* aSelectFileLay = new QGridLayout (aSelectFileBox); - aSelectFileLay->setContentsMargins (MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG); - - mySelectedName = new QLineEdit (aSelectFileBox); - QCompleter* aCompleter = new QCompleter(); - QFileSystemModel* aFileSystemModel = new QFileSystemModel; - aFileSystemModel->setRootPath (QDir::rootPath()); - aCompleter->setModel (aFileSystemModel); - mySelectedName->setCompleter (aCompleter); - aSelectFileLay->addWidget (mySelectedName, 1, 0); - - QToolButton* aSelectFileBtn = new QToolButton (aSelectFileBox); - aSelectFileBtn->setIcon (QIcon (":/icons/folder_open.png")); - aSelectFileLay->addWidget (aSelectFileBtn, 1, 1); - - myFolderApplyOpen = new QToolButton (aSelectFileBox); - myFolderApplyOpen->setIcon (QIcon (":/icons/folder_import.png")); - myFolderApplyOpen->setIconSize (QSize (ICON_SIZE, ICON_SIZE)); - myFolderApplyOpen->setEnabled (false); - aSelectFileLay->addWidget (myFolderApplyOpen, 0, 2, 2, 1); - - connect (mySelectedName, SIGNAL (textChanged (const QString&)), - this, SLOT (onNameChanged (const QString&))); - connect (aSelectFileBtn, SIGNAL (clicked()), this, SLOT (onSelectClicked())); - connect (myFolderApplyOpen, SIGNAL (clicked()), this, SLOT (onApplySelectClicked())); - - resize (OPEN_DIALOG_WIDTH, OPEN_DIALOG_HEIGHT); -} - -// ======================================================================= -// function : OpenFile -// purpose : -// ======================================================================= -QString TInspectorEXE_OpenFileDialog::OpenFile (QWidget* theParent, const QString& theDataDirName) -{ - QString aFileName; - TInspectorEXE_OpenFileDialog* aDialog = new TInspectorEXE_OpenFileDialog(theParent, theDataDirName); - if (aDialog->exec() == QDialog::Accepted) - aFileName = aDialog->GetFileName(); - - return aFileName; -} - -// ======================================================================= -// function : Communicator -// purpose : -// ======================================================================= -TInspector_Communicator* TInspectorEXE_OpenFileDialog::Communicator() -{ - if (!MyCommunicator) - MyCommunicator = new TInspector_Communicator(); - return MyCommunicator; -} - -// ======================================================================= -// function : onSampleSelectionChanged -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileDialog::onSampleSelectionChanged (const QItemSelection& theSelected, - const QItemSelection&) -{ - QItemSelectionModel* aSelectionModel = (QItemSelectionModel*)sender(); - if (!aSelectionModel) - return; - if (theSelected.isEmpty()) - return; - - QModelIndex anIndex = theSelected.first().indexes().first(); - if (!anIndex.isValid()) - return; - - myFileName = aSelectionModel->model()->data (anIndex, Qt::ToolTipRole).toString(); - accept(); -} - -// ======================================================================= -// function : onNameChanged -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileDialog::onNameChanged (const QString& theText) -{ - QFileInfo aFileInfo (theText); - bool anExists = aFileInfo.exists() && aFileInfo.isFile(); - myFolderApplyOpen->setEnabled (anExists); -} - -// ======================================================================= -// function : onSelectClicked -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileDialog::onSelectClicked() -{ - QString anEnteredPath; - QString aDirName = mySelectedName->text(); - if (!aDirName.isEmpty()) - { - QDir aDir (aDirName); - if (aDir.exists()) - anEnteredPath = aDirName; - } - - QString aFileName = QFileDialog::getOpenFileName (0, "Open document", anEnteredPath); - - if (aFileName.isEmpty()) - return; // do nothing, left the previous value - - mySelectedName->setText (aFileName); - onNameChanged (aFileName); -} - -// ======================================================================= -// function : onApplySelectClicked -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileDialog::onApplySelectClicked() -{ - myFileName = mySelectedName->text(); - accept(); -} - -// ======================================================================= -// function : createTableView -// purpose : -// ======================================================================= -QTableView* TInspectorEXE_OpenFileDialog::createTableView (const QStringList& theFileNames) -{ - QTableView* aTableView = new QTableView (this); - aTableView->setFrameStyle (QFrame::NoFrame); - QPalette aPalette = aTableView->viewport()->palette(); - QColor aWindowColor = aPalette.color (QPalette::Window); - aPalette.setBrush (QPalette::Base, aWindowColor); - aTableView->viewport()->setPalette (aPalette); - - aTableView->horizontalHeader()->setVisible (false); - aTableView->verticalHeader()->setVisible (false); - aTableView->setGridStyle (Qt::NoPen); - aTableView->setModel (createModel (theFileNames)); - aTableView->setItemDelegateForRow (0, new TInspectorEXE_OpenFileItemDelegate (aTableView, - aPalette.color (QPalette::Highlight))); - aTableView->viewport()->setAttribute (Qt::WA_Hover); - int aCellHeight = ICON_SIZE + aTableView->verticalHeader()->defaultSectionSize(); - aTableView->setRowHeight (0, aCellHeight); - int aScrollHeight = aTableView->horizontalScrollBar()->sizeHint().height(); - aTableView->setMinimumHeight (aCellHeight + aScrollHeight); - QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aTableView->model()); - connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)), - this, SLOT (onSampleSelectionChanged (const QItemSelection&, const QItemSelection&))); - aTableView->setSelectionModel (aSelectionModel); - - return aTableView; -} - -// ======================================================================= -// function : createModel -// purpose : -// ======================================================================= -QAbstractItemModel* TInspectorEXE_OpenFileDialog::createModel (const QStringList& theFileNames) -{ - TInspectorEXE_OpenFileViewModel* aModel = new TInspectorEXE_OpenFileViewModel (this); - aModel->Init (theFileNames); - return aModel; -} - -// ======================================================================= -// function : readSampleNames -// purpose : -// ======================================================================= -QStringList TInspectorEXE_OpenFileDialog::readSampleNames() -{ - QStringList aNames; - - QDir aDir(myDataDir); - aDir.setSorting(QDir::Name); - - QFileInfoList aDirEntries = aDir.entryInfoList(); - for (int aDirId = 0; aDirId < aDirEntries.size(); ++aDirId) - { - QFileInfo aFileInfo = aDirEntries.at(aDirId); - if (aFileInfo.isFile()) - aNames.append (aFileInfo.absoluteFilePath()); - } - return aNames; -} diff --git a/samples/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.hxx b/samples/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.hxx deleted file mode 100644 index 2c492d7322..0000000000 --- a/samples/tools/TInspectorEXE/TInspectorEXE_OpenFileDialog.hxx +++ /dev/null @@ -1,143 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef TInspectorEXE_OpenFileDialog_H -#define TInspectorEXE_OpenFileDialog_H - -#include -#include - -#ifdef _MSC_VER -#pragma warning(disable : 4127) // conditional expression is constant -#endif -#include -#include -#include - -#include - -class TInspector_Communicator; - -class QAbstractItemModel; -class QLineEdit; -class QPushButton; -class QTableView; -class QToolButton; -class QWidget; - -//! \class TInspectorEXE_OpenButton -//! Class that contains push button and the button processing. It obtains a file name from the default or current -//! directory and gives the name into TInspector communicator -//! Object name of the button is the name of the plugin to get the default directory, or the current directory is used. -class TInspectorEXE_OpenButton : public QObject -{ - Q_OBJECT - -public: - - //! Constructor - TInspectorEXE_OpenButton (QObject* theParent) : QObject (theParent), myStartButton (0) {} - - //! Destructor - virtual ~TInspectorEXE_OpenButton() {} - - //! Returns the start button, if this is the first call, it creates the button and connect it to the slot - QPushButton* StartButton(); - - //! Sets the default directory of plugin. - void SetPluginDir (const TCollection_AsciiString& thePluginName, const TCollection_AsciiString& theDefaultDir) - { myDefaultDirs.Bind (thePluginName, theDefaultDir); } - -private slots: - - //! Processes the button click, open default/current directory to select open file, calls OpenFile of communicator - void onStartButtonClicked(); - -private: - - QPushButton* myStartButton; //!< processed button - NCollection_DataMap myDefaultDirs; //!< plugins default directories -}; - -//! \class TInspectorEXE_OpenFileDialog -//! Control that contains table view of samples and line to select a file name from other directory. -//! Click on element of samples table view calls this sample opening else after entering(or opening) file name -//! the import becomes active. Click on the button will open selected file if it is possible -class TInspectorEXE_OpenFileDialog : public QDialog -{ - Q_OBJECT -private: - - //! Constructor - TInspectorEXE_OpenFileDialog (QWidget* theParent, const QString& theDataDirName); - -public: - - //! Destructor - virtual ~TInspectorEXE_OpenFileDialog() Standard_OVERRIDE {} - - //! Opens this file dialog using for samples view the given directory and try to open new file - //! \param theParent a parent for the new dialog - //! \param theDataDirName path to default samples directory - //! \returns a file name from the open file dialog - static QString OpenFile (QWidget* theParent, const QString& theDataDirName); - - //! Returns selection name from the dialog - QString GetFileName() const { return myFileName; } - - //! Returns communicator, if this is the first call, create a communicator instance - static TInspector_Communicator* Communicator(); - -private slots: - - //! Stores name of selected sample file - void onSampleSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected); - - //! Updates enabling state of Open file button, it is enabled if the file by the entered path exists - //! \param theText a file name text in line edit - void onNameChanged (const QString& theText); - - //! Open file dialog to select a file name. Fills file name line, enable import button - void onSelectClicked(); - - //! Accepts open file dialog - void onApplySelectClicked(); - -private: - - //! Creates view of file names in samples directory - //! \param theFileNames a container of names - //! \return table view - QTableView* createTableView (const QStringList& theFileNames); - - //! Creates view model and fills it by the file names - //! \param theFileNames a container of names - //! \return model - QAbstractItemModel* createModel (const QStringList& theFileNames); - - //! Generates container of file names in samples directory - //! \return container of names - QStringList readSampleNames(); - -private: - - QString myDataDir; //!< samples directory - QString myFileName; //!< result file name - QTableView* mySamplesView; //! - -#include -#include -#include -#include - -const int ICON_SIZE = 40; - -// ======================================================================= -// function : paint -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileItemDelegate::paint (QPainter* thePainter, const QStyleOptionViewItem& theOption, - const QModelIndex& theIndex) const -{ - // highlight cell - if (theOption.state & QStyle::State_MouseOver) - thePainter->fillRect (theOption.rect, myColor); - - // action icon for all indices before the last one - QIcon anIcon (":/icons/folder_import.png"); - QSize anIconSize (ICON_SIZE, ICON_SIZE); - int aWidth = theOption.rect.width(); - int aCenter = aWidth / 2.; - int aHalf = anIconSize.width() / 2.; - int aMargin = qApp->style()->pixelMetric (QStyle::PM_HeaderMargin); - thePainter->drawPixmap (QRect (theOption.rect.left() + (aCenter - aHalf), - theOption.rect.top() + aMargin, - anIconSize.width(), - anIconSize.height()), - anIcon.pixmap(anIconSize.width(), anIconSize.height())); - // default paint - QItemDelegate::paint (thePainter, theOption, theIndex); -} - -// ======================================================================= -// function : Init -// purpose : -// ======================================================================= -void TInspectorEXE_OpenFileViewModel::Init (const QStringList& theValues) -{ - myValues = theValues; -} - -// ======================================================================= -// function : data -// purpose : -// ======================================================================= -QVariant TInspectorEXE_OpenFileViewModel::data (const QModelIndex& theIndex, int theRole) const -{ - switch (theRole) - { - case Qt::DisplayRole: return QFileInfo (myValues[theIndex.column()]).fileName(); - case Qt::ToolTipRole: return myValues[theIndex.column()]; - case Qt::TextAlignmentRole: return QVariant (Qt::AlignBottom | Qt::AlignHCenter); - default: break; - } - return QVariant(); -} diff --git a/samples/tools/TInspectorEXE/TInspectorEXE_OpenFileViewModel.hxx b/samples/tools/TInspectorEXE/TInspectorEXE_OpenFileViewModel.hxx deleted file mode 100644 index f71019e20f..0000000000 --- a/samples/tools/TInspectorEXE/TInspectorEXE_OpenFileViewModel.hxx +++ /dev/null @@ -1,99 +0,0 @@ -// Created on: 2017-06-16 -// Created by: Natalia ERMOLAEVA -// Copyright (c) 2017 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef TInspectorEXE_OpenFileViewModel_H -#define TInspectorEXE_OpenFileViewModel_H - -#include - -#ifdef _MSC_VER -#pragma warning(disable : 4127) // conditional expression is constant -#endif -#include -#include -#include - -class QObject; -class QPainter; - -//! \class TInspectorEXE_OpenFileItemDelegate -//! Draws large(40x40) icons in cell. The icon background in colored in highlight when mouse is over button -class TInspectorEXE_OpenFileItemDelegate : public QItemDelegate -{ - -public: - - //! Constructor - TInspectorEXE_OpenFileItemDelegate (QObject* theParent, const QColor& theHighlightColor) - : QItemDelegate (theParent), myColor(theHighlightColor) {} - - //! Destructor - virtual ~TInspectorEXE_OpenFileItemDelegate() {} - - //! Draw an icon in the cell - //! \param thePainter a painter - //! \param theOption a paint options - //! \param theIndex a view index - virtual void paint (QPainter* thePainter, const QStyleOptionViewItem& theOption, - const QModelIndex& theIndex) const Standard_OVERRIDE; - -private: - - QColor myColor; //!< highlight color -}; - -//! \class TInspectorEXE_OpenFileViewModel -//! Table model that visualizes container of string values (file names) -//! Table orientation is horizontal, it has 1 row, number of columns equals to number of values -class TInspectorEXE_OpenFileViewModel : public QAbstractTableModel -{ - -public: - - //! Constructor - TInspectorEXE_OpenFileViewModel (QObject* theParent = 0) : QAbstractTableModel (theParent) {} - - //! Destructor - virtual ~TInspectorEXE_OpenFileViewModel() {} - - //! Store values - //! \param theValues a container of values to fill model - void Init (const QStringList& theValues); - - //! Returns content of the model index for the given role, it is obtained from internal container of values - //! It returns value only for DisplayRole. - //! \param theIndex a model index - //! \param theRole a view role - //! \return value intepreted depending on the given role - virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE; - - //! Returns number of rows - //! \param theParent an index of the parent item - //! \return an integer value - virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE - { (void)theParent; return 1; } - - //! Returns number of columns - //! \param theParent an index of the parent item - //! \return an integer value - virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE - { (void)theParent; return myValues.size(); } - -private: - - QStringList myValues; //!< file names -}; - -#endif diff --git a/samples/tools/TInspectorEXE/src/FILES b/samples/tools/TInspectorEXE/src/FILES new file mode 100644 index 0000000000..b48157613c --- /dev/null +++ b/samples/tools/TInspectorEXE/src/FILES @@ -0,0 +1,6 @@ +TInspectorEXE.cxx +TInspectorEXE_OpenFileDialog.cxx +TInspectorEXE_OpenFileDialog.hxx +TInspectorEXE_OpenFileViewModel.cxx +TInspectorEXE_OpenFileViewModel.hxx +TInspectorEXE.qrc \ No newline at end of file diff --git a/samples/tools/TInspectorEXE/src/TInspectorEXE.cxx b/samples/tools/TInspectorEXE/src/TInspectorEXE.cxx new file mode 100644 index 0000000000..012e95f3fe --- /dev/null +++ b/samples/tools/TInspectorEXE/src/TInspectorEXE.cxx @@ -0,0 +1,132 @@ +// Created on: 2017-06-16 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + + +#include + +#include + +#include + +#include +#include +#include +#include +#include + +#include + +// ======================================================================= +// function : fileNameInDataDir +// purpose : +// ======================================================================= +TCollection_AsciiString fileNameInDataDir(const TCollection_AsciiString& theEnvironmentDir, + const TCollection_AsciiString& theName) +{ + OSD_Environment anEnvironment(theEnvironmentDir); + + TCollection_AsciiString aFileName = anEnvironment.Value(); + aFileName += TCollection_AsciiString("/") + theName; + + return aFileName; +} + +// ======================================================================= +// function : setPluginSampleDirectory +// purpose : +// ======================================================================= +void setPluginSampleDirectory (const TCollection_AsciiString& theName, TInspector_Communicator* theCommunicator, + TInspectorEXE_OpenButton* theButtonControl) +{ + if (theName.IsEqual ("TKDFBrowser")) + { + theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "step/screw.step")); + theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "step")); + } + else if (theName.IsEqual ("TKShapeView")) + { + theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/hammer.brep")); + theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ")); + } + else if (theName.IsEqual ("TKVInspector")) + { + theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/face1.brep")); + theCommunicator->OpenFile (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ/face2.brep")); + theButtonControl->SetPluginDir (theName, fileNameInDataDir ("CSF_OCCTDataPath", "occ")); + } +} + +// ======================================================================= +// function : main +// purpose : +// ======================================================================= +int main (int argc, char** argv) +{ +#if QT_VERSION > 0x050000 + TCollection_AsciiString aPlugindsDirName = OSD_Environment ("QTDIR").Value(); + if (!aPlugindsDirName.IsEmpty()) + QApplication::addLibraryPath (QString (aPlugindsDirName.ToCString()) + "/plugins"); +#endif + QApplication anApp (argc, argv); + + std::set aPlugins; + for (int anArgId = 1; anArgId < argc; anArgId++ ) + { + if (!strcmp (argv[anArgId], "dfbrowser")) + aPlugins.insert ("TKDFBrowser"); + + if (!strcmp (argv[anArgId], "shapeview")) + aPlugins.insert ("TKShapeView"); + + if (!strcmp (argv[anArgId], "vinspector")) + aPlugins.insert ("TKVInspector"); + } + NCollection_List aParameters; + + // Create tool communicator + TInspector_Communicator* aCommunicator = TInspectorEXE_OpenFileDialog::Communicator(); + if (!aCommunicator) + { + std::cout << "Communicator can not be created" << std::endl; + return 0; + } + + TInspectorEXE_OpenButton* aButtonControl = new TInspectorEXE_OpenButton (0); + TCollection_AsciiString anActivatedPluginName; + if (aPlugins.empty()) + { + aPlugins.insert("TKDFBrowser"); + aPlugins.insert("TKShapeView"); + aPlugins.insert("TKVInspector"); + + anActivatedPluginName = "TKDFBrowser"; + } + else + anActivatedPluginName = *aPlugins.rbegin(); + + for (std::set::const_iterator aPluginIt = aPlugins.begin(); aPluginIt != aPlugins.end(); aPluginIt++) + { + TCollection_AsciiString aName = *aPluginIt; + aCommunicator->RegisterPlugin (aName); + aCommunicator->Init (aName, aParameters); + setPluginSampleDirectory (aName, aCommunicator, aButtonControl); + } + aCommunicator->Activate (anActivatedPluginName); + + aCommunicator->SetVisible (true); + aCommunicator->SetOpenButton (aButtonControl->StartButton()); + + return anApp.exec(); +} diff --git a/samples/tools/TInspectorEXE/src/TInspectorEXE.qrc b/samples/tools/TInspectorEXE/src/TInspectorEXE.qrc new file mode 100644 index 0000000000..b3a84f67dc --- /dev/null +++ b/samples/tools/TInspectorEXE/src/TInspectorEXE.qrc @@ -0,0 +1,6 @@ + + + ../icons/folder_open.png + ../icons/folder_import.png + + diff --git a/samples/tools/TInspectorEXE/src/TInspectorEXE_OpenFileDialog.cxx b/samples/tools/TInspectorEXE/src/TInspectorEXE_OpenFileDialog.cxx new file mode 100644 index 0000000000..1b4dd51f12 --- /dev/null +++ b/samples/tools/TInspectorEXE/src/TInspectorEXE_OpenFileDialog.cxx @@ -0,0 +1,311 @@ +// Created on: 2017-06-16 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const int FONT_POINT_SIZE = 18; +const int ICON_SIZE = 40; + +const int OPEN_DIALOG_WIDTH = 550; +const int OPEN_DIALOG_HEIGHT = 200; + +const int MARGIN_DIALOG = 4; +const int SPACING_DIALOG = 2; + +TInspector_Communicator* MyCommunicator; + +// ======================================================================= +// function : StartButton +// purpose : +// ======================================================================= +QPushButton* TInspectorEXE_OpenButton::StartButton() +{ + if (!myStartButton) + { + myStartButton = new QPushButton(); + myStartButton->setIcon (QIcon (":folder_open.png")); + connect (myStartButton, SIGNAL (clicked()), this, SLOT (onStartButtonClicked())); + } + return myStartButton; +} + +// ======================================================================= +// function : onStartButtonClicked +// purpose : +// ======================================================================= +void TInspectorEXE_OpenButton::onStartButtonClicked() +{ + QPushButton* aButton = (QPushButton*)sender(); + TCollection_AsciiString aPluginName (aButton->objectName().toStdString().c_str()); + if (aPluginName.IsEmpty()) + return; + + QString aDataDirName = QDir::currentPath(); + if (myDefaultDirs.IsBound (aPluginName)) + aDataDirName = myDefaultDirs.Find (aPluginName).ToCString(); + + QString aFileName = TInspectorEXE_OpenFileDialog::OpenFile (0, aDataDirName); + aFileName = QDir().toNativeSeparators (aFileName); + if (!aFileName.isEmpty()) { + QApplication::setOverrideCursor (Qt::WaitCursor); + TInspectorEXE_OpenFileDialog::Communicator()->OpenFile (aPluginName, TCollection_AsciiString (aFileName.toUtf8().data())); + QApplication::restoreOverrideCursor(); + } +} + +// ======================================================================= +// function : changeMargins +// purpose : +// ======================================================================= +void changeMargins (QBoxLayout* theLayout) +{ + theLayout->setContentsMargins (MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG); + theLayout->setSpacing (SPACING_DIALOG); +} + +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +TInspectorEXE_OpenFileDialog::TInspectorEXE_OpenFileDialog (QWidget* theParent, const QString& theDataDirName) +: QDialog(theParent), myDataDir (theDataDirName) +{ + setWindowTitle (theDataDirName); + + QVBoxLayout* aDialogLay = new QVBoxLayout (this); + changeMargins (aDialogLay); + + // Title label + QLabel* aTitleLabel = new QLabel (this); + aTitleLabel->setText (tr ("Open File")); + aDialogLay->addWidget (aTitleLabel); + + // Samples View + QGroupBox* aSamplesBox = new QGroupBox (this); + aSamplesBox->setTitle (tr ("Samples")); + aDialogLay->addWidget (aSamplesBox); + QVBoxLayout* aSampleLay = new QVBoxLayout (aSamplesBox); + changeMargins (aSampleLay); + mySamplesView = createTableView (readSampleNames()); + aSampleLay->addWidget (mySamplesView); + + // Select file + QGroupBox* aSelectFileBox = new QGroupBox (this); + aSelectFileBox->setTitle (tr ("Select file")); + aDialogLay->addWidget (aSelectFileBox); + QGridLayout* aSelectFileLay = new QGridLayout (aSelectFileBox); + aSelectFileLay->setContentsMargins (MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG, MARGIN_DIALOG); + + mySelectedName = new QLineEdit (aSelectFileBox); + QCompleter* aCompleter = new QCompleter(); + QFileSystemModel* aFileSystemModel = new QFileSystemModel; + aFileSystemModel->setRootPath (QDir::rootPath()); + aCompleter->setModel (aFileSystemModel); + mySelectedName->setCompleter (aCompleter); + aSelectFileLay->addWidget (mySelectedName, 1, 0); + + QToolButton* aSelectFileBtn = new QToolButton (aSelectFileBox); + aSelectFileBtn->setIcon (QIcon (":folder_open.png")); + aSelectFileLay->addWidget (aSelectFileBtn, 1, 1); + + myFolderApplyOpen = new QToolButton (aSelectFileBox); + myFolderApplyOpen->setIcon (QIcon (":folder_import.png")); + myFolderApplyOpen->setIconSize (QSize (ICON_SIZE, ICON_SIZE)); + myFolderApplyOpen->setEnabled (false); + aSelectFileLay->addWidget (myFolderApplyOpen, 0, 2, 2, 1); + + connect (mySelectedName, SIGNAL (textChanged (const QString&)), + this, SLOT (onNameChanged (const QString&))); + connect (aSelectFileBtn, SIGNAL (clicked()), this, SLOT (onSelectClicked())); + connect (myFolderApplyOpen, SIGNAL (clicked()), this, SLOT (onApplySelectClicked())); + + resize (OPEN_DIALOG_WIDTH, OPEN_DIALOG_HEIGHT); +} + +// ======================================================================= +// function : OpenFile +// purpose : +// ======================================================================= +QString TInspectorEXE_OpenFileDialog::OpenFile (QWidget* theParent, const QString& theDataDirName) +{ + QString aFileName; + TInspectorEXE_OpenFileDialog* aDialog = new TInspectorEXE_OpenFileDialog(theParent, theDataDirName); + if (aDialog->exec() == QDialog::Accepted) + aFileName = aDialog->GetFileName(); + + return aFileName; +} + +// ======================================================================= +// function : Communicator +// purpose : +// ======================================================================= +TInspector_Communicator* TInspectorEXE_OpenFileDialog::Communicator() +{ + if (!MyCommunicator) + MyCommunicator = new TInspector_Communicator(); + return MyCommunicator; +} + +// ======================================================================= +// function : onSampleSelectionChanged +// purpose : +// ======================================================================= +void TInspectorEXE_OpenFileDialog::onSampleSelectionChanged (const QItemSelection& theSelected, + const QItemSelection&) +{ + QItemSelectionModel* aSelectionModel = (QItemSelectionModel*)sender(); + if (!aSelectionModel) + return; + if (theSelected.isEmpty()) + return; + + QModelIndex anIndex = theSelected.first().indexes().first(); + if (!anIndex.isValid()) + return; + + myFileName = aSelectionModel->model()->data (anIndex, Qt::ToolTipRole).toString(); + accept(); +} + +// ======================================================================= +// function : onNameChanged +// purpose : +// ======================================================================= +void TInspectorEXE_OpenFileDialog::onNameChanged (const QString& theText) +{ + QFileInfo aFileInfo (theText); + bool anExists = aFileInfo.exists() && aFileInfo.isFile(); + myFolderApplyOpen->setEnabled (anExists); +} + +// ======================================================================= +// function : onSelectClicked +// purpose : +// ======================================================================= +void TInspectorEXE_OpenFileDialog::onSelectClicked() +{ + QString anEnteredPath; + QString aDirName = mySelectedName->text(); + if (!aDirName.isEmpty()) + { + QDir aDir (aDirName); + if (aDir.exists()) + anEnteredPath = aDirName; + } + + QString aFileName = QFileDialog::getOpenFileName (0, "Open document", anEnteredPath); + + if (aFileName.isEmpty()) + return; // do nothing, left the previous value + + mySelectedName->setText (aFileName); + onNameChanged (aFileName); +} + +// ======================================================================= +// function : onApplySelectClicked +// purpose : +// ======================================================================= +void TInspectorEXE_OpenFileDialog::onApplySelectClicked() +{ + myFileName = mySelectedName->text(); + accept(); +} + +// ======================================================================= +// function : createTableView +// purpose : +// ======================================================================= +QTableView* TInspectorEXE_OpenFileDialog::createTableView (const QStringList& theFileNames) +{ + QTableView* aTableView = new QTableView (this); + aTableView->setFrameStyle (QFrame::NoFrame); + QPalette aPalette = aTableView->viewport()->palette(); + QColor aWindowColor = aPalette.color (QPalette::Window); + aPalette.setBrush (QPalette::Base, aWindowColor); + aTableView->viewport()->setPalette (aPalette); + + aTableView->horizontalHeader()->setVisible (false); + aTableView->verticalHeader()->setVisible (false); + aTableView->setGridStyle (Qt::NoPen); + aTableView->setModel (createModel (theFileNames)); + aTableView->setItemDelegateForRow (0, new TInspectorEXE_OpenFileItemDelegate (aTableView, + aPalette.color (QPalette::Highlight))); + aTableView->viewport()->setAttribute (Qt::WA_Hover); + int aCellHeight = ICON_SIZE + aTableView->verticalHeader()->defaultSectionSize(); + aTableView->setRowHeight (0, aCellHeight); + int aScrollHeight = aTableView->horizontalScrollBar()->sizeHint().height(); + aTableView->setMinimumHeight (aCellHeight + aScrollHeight); + QItemSelectionModel* aSelectionModel = new QItemSelectionModel (aTableView->model()); + connect (aSelectionModel, SIGNAL (selectionChanged (const QItemSelection&, const QItemSelection&)), + this, SLOT (onSampleSelectionChanged (const QItemSelection&, const QItemSelection&))); + aTableView->setSelectionModel (aSelectionModel); + + return aTableView; +} + +// ======================================================================= +// function : createModel +// purpose : +// ======================================================================= +QAbstractItemModel* TInspectorEXE_OpenFileDialog::createModel (const QStringList& theFileNames) +{ + TInspectorEXE_OpenFileViewModel* aModel = new TInspectorEXE_OpenFileViewModel (this); + aModel->Init (theFileNames); + return aModel; +} + +// ======================================================================= +// function : readSampleNames +// purpose : +// ======================================================================= +QStringList TInspectorEXE_OpenFileDialog::readSampleNames() +{ + QStringList aNames; + + QDir aDir(myDataDir); + aDir.setSorting(QDir::Name); + + QFileInfoList aDirEntries = aDir.entryInfoList(); + for (int aDirId = 0; aDirId < aDirEntries.size(); ++aDirId) + { + QFileInfo aFileInfo = aDirEntries.at(aDirId); + if (aFileInfo.isFile()) + aNames.append (aFileInfo.absoluteFilePath()); + } + return aNames; +} diff --git a/samples/tools/TInspectorEXE/src/TInspectorEXE_OpenFileDialog.hxx b/samples/tools/TInspectorEXE/src/TInspectorEXE_OpenFileDialog.hxx new file mode 100644 index 0000000000..2c492d7322 --- /dev/null +++ b/samples/tools/TInspectorEXE/src/TInspectorEXE_OpenFileDialog.hxx @@ -0,0 +1,143 @@ +// Created on: 2017-06-16 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef TInspectorEXE_OpenFileDialog_H +#define TInspectorEXE_OpenFileDialog_H + +#include +#include + +#ifdef _MSC_VER +#pragma warning(disable : 4127) // conditional expression is constant +#endif +#include +#include +#include + +#include + +class TInspector_Communicator; + +class QAbstractItemModel; +class QLineEdit; +class QPushButton; +class QTableView; +class QToolButton; +class QWidget; + +//! \class TInspectorEXE_OpenButton +//! Class that contains push button and the button processing. It obtains a file name from the default or current +//! directory and gives the name into TInspector communicator +//! Object name of the button is the name of the plugin to get the default directory, or the current directory is used. +class TInspectorEXE_OpenButton : public QObject +{ + Q_OBJECT + +public: + + //! Constructor + TInspectorEXE_OpenButton (QObject* theParent) : QObject (theParent), myStartButton (0) {} + + //! Destructor + virtual ~TInspectorEXE_OpenButton() {} + + //! Returns the start button, if this is the first call, it creates the button and connect it to the slot + QPushButton* StartButton(); + + //! Sets the default directory of plugin. + void SetPluginDir (const TCollection_AsciiString& thePluginName, const TCollection_AsciiString& theDefaultDir) + { myDefaultDirs.Bind (thePluginName, theDefaultDir); } + +private slots: + + //! Processes the button click, open default/current directory to select open file, calls OpenFile of communicator + void onStartButtonClicked(); + +private: + + QPushButton* myStartButton; //!< processed button + NCollection_DataMap myDefaultDirs; //!< plugins default directories +}; + +//! \class TInspectorEXE_OpenFileDialog +//! Control that contains table view of samples and line to select a file name from other directory. +//! Click on element of samples table view calls this sample opening else after entering(or opening) file name +//! the import becomes active. Click on the button will open selected file if it is possible +class TInspectorEXE_OpenFileDialog : public QDialog +{ + Q_OBJECT +private: + + //! Constructor + TInspectorEXE_OpenFileDialog (QWidget* theParent, const QString& theDataDirName); + +public: + + //! Destructor + virtual ~TInspectorEXE_OpenFileDialog() Standard_OVERRIDE {} + + //! Opens this file dialog using for samples view the given directory and try to open new file + //! \param theParent a parent for the new dialog + //! \param theDataDirName path to default samples directory + //! \returns a file name from the open file dialog + static QString OpenFile (QWidget* theParent, const QString& theDataDirName); + + //! Returns selection name from the dialog + QString GetFileName() const { return myFileName; } + + //! Returns communicator, if this is the first call, create a communicator instance + static TInspector_Communicator* Communicator(); + +private slots: + + //! Stores name of selected sample file + void onSampleSelectionChanged (const QItemSelection& theSelected, const QItemSelection& theDeselected); + + //! Updates enabling state of Open file button, it is enabled if the file by the entered path exists + //! \param theText a file name text in line edit + void onNameChanged (const QString& theText); + + //! Open file dialog to select a file name. Fills file name line, enable import button + void onSelectClicked(); + + //! Accepts open file dialog + void onApplySelectClicked(); + +private: + + //! Creates view of file names in samples directory + //! \param theFileNames a container of names + //! \return table view + QTableView* createTableView (const QStringList& theFileNames); + + //! Creates view model and fills it by the file names + //! \param theFileNames a container of names + //! \return model + QAbstractItemModel* createModel (const QStringList& theFileNames); + + //! Generates container of file names in samples directory + //! \return container of names + QStringList readSampleNames(); + +private: + + QString myDataDir; //!< samples directory + QString myFileName; //!< result file name + QTableView* mySamplesView; //! + +#include +#include +#include +#include + +const int ICON_SIZE = 40; + +// ======================================================================= +// function : paint +// purpose : +// ======================================================================= +void TInspectorEXE_OpenFileItemDelegate::paint (QPainter* thePainter, const QStyleOptionViewItem& theOption, + const QModelIndex& theIndex) const +{ + // highlight cell + if (theOption.state & QStyle::State_MouseOver) + thePainter->fillRect (theOption.rect, myColor); + + // action icon for all indices before the last one + QIcon anIcon (":/icons/folder_import.png"); + QSize anIconSize (ICON_SIZE, ICON_SIZE); + int aWidth = theOption.rect.width(); + int aCenter = aWidth / 2.; + int aHalf = anIconSize.width() / 2.; + int aMargin = qApp->style()->pixelMetric (QStyle::PM_HeaderMargin); + thePainter->drawPixmap (QRect (theOption.rect.left() + (aCenter - aHalf), + theOption.rect.top() + aMargin, + anIconSize.width(), + anIconSize.height()), + anIcon.pixmap(anIconSize.width(), anIconSize.height())); + // default paint + QItemDelegate::paint (thePainter, theOption, theIndex); +} + +// ======================================================================= +// function : Init +// purpose : +// ======================================================================= +void TInspectorEXE_OpenFileViewModel::Init (const QStringList& theValues) +{ + myValues = theValues; +} + +// ======================================================================= +// function : data +// purpose : +// ======================================================================= +QVariant TInspectorEXE_OpenFileViewModel::data (const QModelIndex& theIndex, int theRole) const +{ + switch (theRole) + { + case Qt::DisplayRole: return QFileInfo (myValues[theIndex.column()]).fileName(); + case Qt::ToolTipRole: return myValues[theIndex.column()]; + case Qt::TextAlignmentRole: return QVariant (Qt::AlignBottom | Qt::AlignHCenter); + default: break; + } + return QVariant(); +} diff --git a/samples/tools/TInspectorEXE/src/TInspectorEXE_OpenFileViewModel.hxx b/samples/tools/TInspectorEXE/src/TInspectorEXE_OpenFileViewModel.hxx new file mode 100644 index 0000000000..f71019e20f --- /dev/null +++ b/samples/tools/TInspectorEXE/src/TInspectorEXE_OpenFileViewModel.hxx @@ -0,0 +1,99 @@ +// Created on: 2017-06-16 +// Created by: Natalia ERMOLAEVA +// Copyright (c) 2017 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef TInspectorEXE_OpenFileViewModel_H +#define TInspectorEXE_OpenFileViewModel_H + +#include + +#ifdef _MSC_VER +#pragma warning(disable : 4127) // conditional expression is constant +#endif +#include +#include +#include + +class QObject; +class QPainter; + +//! \class TInspectorEXE_OpenFileItemDelegate +//! Draws large(40x40) icons in cell. The icon background in colored in highlight when mouse is over button +class TInspectorEXE_OpenFileItemDelegate : public QItemDelegate +{ + +public: + + //! Constructor + TInspectorEXE_OpenFileItemDelegate (QObject* theParent, const QColor& theHighlightColor) + : QItemDelegate (theParent), myColor(theHighlightColor) {} + + //! Destructor + virtual ~TInspectorEXE_OpenFileItemDelegate() {} + + //! Draw an icon in the cell + //! \param thePainter a painter + //! \param theOption a paint options + //! \param theIndex a view index + virtual void paint (QPainter* thePainter, const QStyleOptionViewItem& theOption, + const QModelIndex& theIndex) const Standard_OVERRIDE; + +private: + + QColor myColor; //!< highlight color +}; + +//! \class TInspectorEXE_OpenFileViewModel +//! Table model that visualizes container of string values (file names) +//! Table orientation is horizontal, it has 1 row, number of columns equals to number of values +class TInspectorEXE_OpenFileViewModel : public QAbstractTableModel +{ + +public: + + //! Constructor + TInspectorEXE_OpenFileViewModel (QObject* theParent = 0) : QAbstractTableModel (theParent) {} + + //! Destructor + virtual ~TInspectorEXE_OpenFileViewModel() {} + + //! Store values + //! \param theValues a container of values to fill model + void Init (const QStringList& theValues); + + //! Returns content of the model index for the given role, it is obtained from internal container of values + //! It returns value only for DisplayRole. + //! \param theIndex a model index + //! \param theRole a view role + //! \return value intepreted depending on the given role + virtual QVariant data (const QModelIndex& theIndex, int theRole = Qt::DisplayRole) const Standard_OVERRIDE; + + //! Returns number of rows + //! \param theParent an index of the parent item + //! \return an integer value + virtual int rowCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { (void)theParent; return 1; } + + //! Returns number of columns + //! \param theParent an index of the parent item + //! \return an integer value + virtual int columnCount (const QModelIndex& theParent = QModelIndex()) const Standard_OVERRIDE + { (void)theParent; return myValues.size(); } + +private: + + QStringList myValues; //!< file names +}; + +#endif diff --git a/samples/tools/TStandalone/adm/cmake/occt_toolkit_standalone.cmake b/samples/tools/TStandalone/adm/cmake/occt_toolkit_standalone.cmake index 2eafae1a02..223c362ca1 100644 --- a/samples/tools/TStandalone/adm/cmake/occt_toolkit_standalone.cmake +++ b/samples/tools/TStandalone/adm/cmake/occt_toolkit_standalone.cmake @@ -47,7 +47,7 @@ include_directories( add_definitions(-D__WIN32__) add_definitions(-DWNT) -add_definitions(-D${PROJECT_NAME}_EXPORTS) +add_definitions(-D__${PROJECT_NAME}_DLL) # parce EXTERNLIB file FILE_TO_LIST ("src/${PROJECT_NAME}/EXTERNLIB" USED_EXTERNLIB_AND_TOOLKITS) diff --git a/src/DRAWEXE/CMakeLists.txt b/src/DRAWEXE/CMakeLists.txt index 11673ed63a..bdf6279949 100644 --- a/src/DRAWEXE/CMakeLists.txt +++ b/src/DRAWEXE/CMakeLists.txt @@ -1,3 +1,5 @@ project(DRAWEXE) +set (EXECUTABLE_PROJECT ON) OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +unset (EXECUTABLE_PROJECT) diff --git a/tools/DFBrowserPane/DFBrowserPane.hxx b/tools/DFBrowserPane/DFBrowserPane.hxx index 6deb03a75e..be7be47031 100644 --- a/tools/DFBrowserPane/DFBrowserPane.hxx +++ b/tools/DFBrowserPane/DFBrowserPane.hxx @@ -16,7 +16,7 @@ #ifndef DFBROWSERPANE_H #define DFBROWSERPANE_H -#ifdef DFBrowserPane_EXPORTS +#ifdef __DFBrowserPane_DLL #ifdef _WIN32 #define DFBROWSERPANE_EXPORT __declspec(dllexport) #else diff --git a/tools/TInspector/TInspector_Communicator.cxx b/tools/TInspector/TInspector_Communicator.cxx index 72771c13f0..025163e350 100644 --- a/tools/TInspector/TInspector_Communicator.cxx +++ b/tools/TInspector/TInspector_Communicator.cxx @@ -37,10 +37,9 @@ TInspector_Communicator::TInspector_Communicator() static int argc = 1; static char* argv[] = { (char*)"", 0 }; #if QT_VERSION > 0x050000 - OSD_Environment anEnvironment ("QTDIR"); - TCollection_AsciiString aPlugindsDirName = anEnvironment.Value(); - aPlugindsDirName += "/plugins"; - QApplication::addLibraryPath (aPlugindsDirName.ToCString()); + TCollection_AsciiString aPlugindsDirName = OSD_Environment ("QTDIR").Value(); + if (!aPlugindsDirName.IsEmpty()) + QApplication::addLibraryPath (QString (aPlugindsDirName.ToCString()) + "/plugins"); #endif new QApplication (argc, argv); } diff --git a/tools/TKDFBrowser/CMakeLists.txt b/tools/TKDFBrowser/CMakeLists.txt index 10902483db..29b45e9843 100644 --- a/tools/TKDFBrowser/CMakeLists.txt +++ b/tools/TKDFBrowser/CMakeLists.txt @@ -1,3 +1,5 @@ project(TKDFBrowser) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) diff --git a/tools/TKShapeView/CMakeLists.txt b/tools/TKShapeView/CMakeLists.txt index d57cc9fa2d..928a72f1e8 100644 --- a/tools/TKShapeView/CMakeLists.txt +++ b/tools/TKShapeView/CMakeLists.txt @@ -1,3 +1,5 @@ project(TKShapeView) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_tool) \ No newline at end of file +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) diff --git a/tools/TKTInspector/CMakeLists.txt b/tools/TKTInspector/CMakeLists.txt index 3ed8dce1ff..0a05b7ca15 100644 --- a/tools/TKTInspector/CMakeLists.txt +++ b/tools/TKTInspector/CMakeLists.txt @@ -2,6 +2,8 @@ project(TKTInspector) set (INSTALL_API ON) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) unset (INSTALL_API) diff --git a/tools/TKTInspectorAPI/CMakeLists.txt b/tools/TKTInspectorAPI/CMakeLists.txt index a6afae44b2..d2f21e0f9b 100644 --- a/tools/TKTInspectorAPI/CMakeLists.txt +++ b/tools/TKTInspectorAPI/CMakeLists.txt @@ -2,7 +2,9 @@ project(TKTInspectorAPI) SET (TOOL_API_LIBRARY ON) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) UNSET (TOOL_API_LIBRARY) diff --git a/tools/TKToolsDraw/CMakeLists.txt b/tools/TKToolsDraw/CMakeLists.txt index 1812573e8f..f57982cf05 100644 --- a/tools/TKToolsDraw/CMakeLists.txt +++ b/tools/TKToolsDraw/CMakeLists.txt @@ -1,3 +1,5 @@ project(TKToolsDraw) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) diff --git a/tools/TKTreeModel/CMakeLists.txt b/tools/TKTreeModel/CMakeLists.txt index 6247c374a7..99fc025494 100644 --- a/tools/TKTreeModel/CMakeLists.txt +++ b/tools/TKTreeModel/CMakeLists.txt @@ -1,3 +1,5 @@ project(TKTreeModel) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) diff --git a/tools/TKVInspector/CMakeLists.txt b/tools/TKVInspector/CMakeLists.txt index dfdb809cb4..1a6de1456a 100644 --- a/tools/TKVInspector/CMakeLists.txt +++ b/tools/TKVInspector/CMakeLists.txt @@ -1,3 +1,5 @@ project(TKVInspector) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_tool) \ No newline at end of file +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) diff --git a/tools/TKView/CMakeLists.txt b/tools/TKView/CMakeLists.txt index 705ccd4047..ed33343886 100644 --- a/tools/TKView/CMakeLists.txt +++ b/tools/TKView/CMakeLists.txt @@ -1,3 +1,5 @@ project(TKView) -OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit) +OCCT_INCLUDE_CMAKE_FILE (adm/cmake/occt_toolkit_prepare_tool)