### C++ Usage Example: Open and Read CAD File Source: https://github.com/sandyre/libopencad/blob/master/README.md Demonstrates how to open a CAD file using libopencad, retrieve its header and class information, and iterate through layers and geometries. It includes handling different geometry types like circles. ```cpp #include #include #include "lib/opencad_api.h" // returns nullptr on fail. GetLastErrorCode() returns an error code. CADFile *pCADFile = OpenCADFile( pszCADFilePath, CADFile::OpenOptions::READ_ALL ); if (pCADFile == nullptr) { std::cerr << "Failed to open CAD file. Error code: " << GetLastErrorCode() << std::endl; return 1; } const CADHeader& header = pCADFile->getHeader (); header.print (); // prints CAD Header variables. std::cout << std::endl; const CADClasses& classes = pCADFile->getClasses (); classes.print (); // prints custom CAD classes std::cout << std::endl; for ( size_t i = 0; i < pCADFile->getLayersCount (); ++i ) { CADLayer &layer = pCADFile->getLayer (i); std::cout << "Layer #" << i << " contains " << layer.getGeometryCount () << " geometries" << std::endl; for ( size_t j = 0; j < layer.getGeometryCount (); ++j ) { std::unique_ptr geom(layer.getGeometry (j)); if ( geom == nullptr ) continue; switch ( geom->getType() ) // returns GeometryType enum. { case CADGeometry::CIRCLE: CADCircle * poCADCircle = static_cast( geom.get()); std::cout << "Circle at X: " << poCADCircle->getPosition().getX() << std::endl; std::cout << "Circle at Y: " << poCADCircle->getPosition().getY() << std::endl; std::cout << "Circle at Z: " << poCADCircle->getPosition().getZ() << std::endl; break; // any other geometry type you need. default: // Handle other geometry types or ignore break; } } } // Remember to delete the CADFile object when done delete pCADFile; ``` -------------------------------- ### libopencad Build Configuration (CMake) Source: https://github.com/sandyre/libopencad/blob/master/apps/CMakeLists.txt This CMakeLists.txt file configures the build process for the libopencad project. It sets the minimum required CMake version, defines the project name, specifies include directories, lists source files for the 'cadinfo' executable, links necessary libraries, and defines installation rules. ```CMake cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) project(apps) include_directories(${CMAKE_SOURCE_DIR}/lib) set(CSOURCES cadinfo.cpp ) add_executable(cadinfo ${CSOURCES}) target_link_libraries(cadinfo ${TARGET_LINK}) if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) install(TARGETS cadinfo RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT applications ARCHIVE DESTINATION ${INSTALL_LIB_DIR} COMPONENT applications LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT applications ) endif() ``` -------------------------------- ### Build libopencad with CMake Source: https://github.com/sandyre/libopencad/blob/master/lib/CMakeLists.txt This CMakeLists.txt file configures the build process for the libopencad library. It defines project settings, includes necessary modules, lists source and header files, and manages library creation (shared or static) and installation. ```CMake cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) project(opencad) include(util) check_version(OCAD_MAJOR_VERSION OCAD_MINOR_VERSION OCAD_REV_VERSION) set(VERSION ${OCAD_MAJOR_VERSION}.${OCAD_MINOR_VERSION}.${OCAD_REV_VERSION}) set(SOVERSION 1) set(CMAKE_POSITION_INDEPENDENT_CODE ON) report_version(${PROJECT_NAME} ${VERSION}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) set(OBJ_LIB) add_subdirectory(dwg) set(HHEADERS opencad.h opencad_api.h cadfile.h cadfileio.h cadheader.h cadclasses.h cadtables.h cadgeometry.h cadlayer.h cadcolors.h caddictionary.h cadobjects.h) set(HHEADER_PRIV cadfilestreamio.h ) set(CSOURCES opencad.cpp cadfile.cpp cadfileio.cpp cadfilestreamio.cpp cadheader.cpp cadclasses.cpp cadtables.cpp cadgeometry.cpp cadobjects.cpp cadlayer.cpp caddictionary.cpp) set(LIB_NAME) if(BUILD_SHARED_LIBS) set(LIB_TYPE SHARED) set(LIB_NAME ${PROJECT_NAME}) else() set(LIB_TYPE STATIC) set(LIB_NAME ${PROJECT_NAME}static) endif() add_library(${LIB_NAME} ${LIB_TYPE} ${CSOURCES} ${HHEADERS} ${HHEADER_PRIV} ${OBJ_LIB}) set(TARGET_LINK ${TARGET_LINK} ${LIB_NAME} PARENT_SCOPE) if(BUILD_SHARED_LIBS) if(WIN32) set (LIB_VERSION ${OCAD_MAJOR_VERSION}) if(MSVC) set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_i.lib") endif() else () set (LIB_VERSION ${VERSION}) endif() set_target_properties (${LIB_NAME} PROPERTIES VERSION ${LIB_VERSION}) set_target_properties (${LIB_NAME} PROPERTIES SOVERSION ${SOVERSION}) set_target_properties (${LIB_NAME} PROPERTIES DEFINE_SYMBOL OCAD_EXPORTS) endif() if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) install(TARGETS ${LIB_NAME} EXPORT ${LIB_NAME} RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT libraries ARCHIVE DESTINATION ${INSTALL_LIB_DIR} COMPONENT libraries LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT libraries ) endif() if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL ) install(FILES ${HHEADERS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/opencad" COMPONENT headers) endif() ``` -------------------------------- ### Open DWG File with libdwgx Source: https://github.com/sandyre/libopencad/wiki/Home Initializes the libdwgx library to open a specified .DWG file. It returns a pointer to the DWG object if successful or if the file format is supported, otherwise, it returns nullptr. ```APIDOC libdwgx::InitializeDWG - Opens a .DWG file. - Parameters: - filename: const char* - The path to the .DWG file. - Returns: - Pointer to an initialized DWG object for the detected file version. - nullptr if the file format is not supported. - Limitations: - Returns nullptr for unsupported file formats. ``` -------------------------------- ### Build libopencad Static Library Source: https://github.com/sandyre/libopencad/blob/master/README.md Configures the libopencad project using CMake and then builds it as a static library using Make. This process generates a static library file for linking into other projects. ```sh cmake CMakeLists.txt make -j4 ``` -------------------------------- ### CMake Build Configuration for libopencad Tests Source: https://github.com/sandyre/libopencad/blob/master/tests/CMakeLists.txt Configures the build process for libopencad, enabling and setting up unit tests. It manages dependencies like GTest and Threads, copies data, and defines test executables. ```cmake option(BUILD_TESTS "Build unit tests" OFF) if(BUILD_TESTS) include(CTest) set(WITH_GTest ON CACHE BOOL "Google test on") set(WITH_GTest_EXTERNAL ON CACHE BOOL "Google test external on") find_anyproject(GTest REQUIRED) include_directories(${GTEST_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/lib) find_package(Threads) set(TARGET_LINK_LIB ${TARGET_LINK_LIB} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} ${TARGET_LINK}) find_library(M_LIB m) set(TARGET_LINK_LIB ${TARGET_LINK_LIB} ${M_LIB}) file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY data/r2000 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data) add_executable(io_test io_check.cpp) target_link_extlibraries(io_test) add_test( io_test io_test ) add_executable(geometry_test reading_geometries.cpp) target_link_extlibraries(geometry_test) add_test( geometry_test geometry_test ) endif() ``` -------------------------------- ### Clone libopencad Repository Source: https://github.com/sandyre/libopencad/blob/master/README.md Clones the libopencad project repository from GitHub using Git. This is the first step to obtain the library's source code. ```sh git clone https://github.com/sandyre/libopencad ``` -------------------------------- ### CMake Build Configuration for libopencad Source: https://github.com/sandyre/libopencad/blob/master/CMakeLists.txt This snippet details the CMake build system configuration for the libopencad project. It sets up project properties, includes directories, defines build types, enables testing, and manages subdirectories for libraries, applications, and tests. ```CMake cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) project(libopencad) # some init settings set(CMAKE_COLOR_MAKEFILE ON) # set path to additional CMake modules set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) include(GNUInstallDirs) set(INSTALL_BIN_DIR ${CMAKE_INSTALL_BINDIR} CACHE INTERNAL "Installation directory for executables" FORCE) set(INSTALL_LIB_DIR ${CMAKE_INSTALL_LIBDIR} CACHE INTERNAL "Installation directory for libraries" FORCE) set(INSTALL_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE INTERNAL "Installation directory for headers" FORCE) if(CMAKE_BUILD_TYPE STREQUAL Debug) add_definitions(-D_DEBUG) endif() configure_file(${CMAKE_MODULE_PATH}/uninstall.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") enable_testing() include(FindAnyProject) set(TARGET_LINK) add_subdirectory(lib) option(BUILD_APPS "Build console applications" ON) if(BUILD_APPS) add_subdirectory(apps) endif() add_subdirectory(tests) # uninstall add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) ``` -------------------------------- ### CMake Build Configuration for libopencad Source: https://github.com/sandyre/libopencad/blob/master/lib/dwg/CMakeLists.txt This snippet details the CMake build configuration for the libopencad project. It specifies the minimum required CMake version, defines source and header files, and creates a library target. It also sets up variables for object libraries. ```CMake cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) project(dwg) set(HHEADERS io.h r2000.h) set(CSOURCES io.cpp r2000.cpp ) add_library(${PROJECT_NAME} OBJECT ${CSOURCES} ${HHEADERS}) set(OBJ_LIB ${OBJ_LIB} $ PARENT_SCOPE) ``` -------------------------------- ### Build libopencad Dynamic Library Source: https://github.com/sandyre/libopencad/blob/master/README.md Configures the libopencad project using CMake with the BUILD_SHARED_LIBS option enabled and then builds it as a dynamic library using Make. This process generates a shared library file. ```sh cmake -DBUILD_SHARED_LIBS=ON CMakeLists.txt make -j4 ``` -------------------------------- ### MIT License for libopencad Source: https://github.com/sandyre/libopencad/blob/master/CMakeLists.txt This block contains the MIT License text, which governs the usage and distribution of the libopencad software. It grants broad permissions for use, modification, and distribution. ```Text The MIT License (MIT) Copyright (c) 2016 Alexandr Borzykh Copyright (c) 2016 NextGIS, Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.