### Install and Run Node.js Example Source: https://github.com/aewallin/opencamlib/blob/master/examples/nodejs/README.md Use these commands to install the Node.js wrapper for OpenCamlib and execute the test script. Ensure you are in the correct directory. ```shell npm link ../../src/npmpackage ``` ```shell node test.js ``` -------------------------------- ### Install and Run OpenCAMLib Browser Environment Source: https://github.com/aewallin/opencamlib/blob/master/examples/emscripten/README.md Commands to install dependencies, link the local source package, and start the development server. ```shell npm install npm link ../../src/npmpackage npm start ``` -------------------------------- ### Setup Emscripten SDK Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Downloads, installs, and activates the Emscripten SDK, which is required for compiling OpenCAMLib for the web. ```shell git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk install latest ./emsdk activate latest ``` -------------------------------- ### CMakeLists.txt for OpenCAMLib Point Example Source: https://github.com/aewallin/opencamlib/blob/master/examples/cpp/point/CMakeLists.txt This CMakeLists.txt file sets up the build environment for the point_example. It specifies C++ standards, finds the OpenCAMLib package, and configures installation directories. It also includes a post-build command for Windows to copy necessary DLLs. ```cmake cmake_minimum_required(VERSION 3.12...3.15) cmake_policy(SET CMP0025 NEW) set(CMAKE_CXX_STANDARD 20) project(OCL_POINT_EXAMPLE) # install targets in root of the build dir, using $<0:> generator expression to force it from not being overwritten set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<0:>) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<0:>) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<0:>) foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/$<0:>) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/$<0:>) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/$<0:>) endforeach() find_package(OpenCAMLib REQUIRED) set(EXAMPLE_SRC ${PROJECT_SOURCE_DIR}/point_example.cpp ) add_executable( point_example ${EXAMPLE_SRC} ) target_link_libraries( point_example OpenCAMLib::ocl ) if(WIN32) add_custom_command(TARGET point_example POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ $ COMMAND_EXPAND_LISTS ) endif() ``` -------------------------------- ### Install OpenCAMLib via npm Source: https://context7.com/aewallin/opencamlib/llms.txt Install the OpenCAMLib Node.js/Browser package using npm. ```bash npm install --save @opencamlib/opencamlib ``` -------------------------------- ### Install OpenCAMLib via pip Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Standard installation commands for the Python library using pip or pip3. ```shell pip install opencamlib ``` ```shell pip3 install opencamlib ``` -------------------------------- ### Install OpenCAMLib via pip Source: https://context7.com/aewallin/opencamlib/llms.txt Install the OpenCAMLib Python package using pip. ```bash pip install opencamlib ``` -------------------------------- ### Configure dput for Launchpad Upload Source: https://github.com/aewallin/opencamlib/blob/master/src/deb/readme_debian.txt The '/etc/dput.cf' file configures the 'dput' tool for uploading packages to Launchpad. This example shows settings for the 'cam-ppa' target, using SFTP. ```ini [cam-ppa] fqdn = ppa.launchpad.net method = sftp incoming = ~anders-e-e-wallin/cam/ubuntu login = anders-e-e-wallin ``` -------------------------------- ### CMakeLists.txt for OpenCAMLib Example Source: https://github.com/aewallin/opencamlib/blob/master/examples/cpp/test/CMakeLists.txt This CMakeLists.txt file sets up a project to build an executable that links against the OpenCAMLib library. It specifies C++20 standard and configures output directories. ```cmake cmake_minimum_required(VERSION 3.12...3.15) cmake_policy(SET CMP0025 NEW) set(CMAKE_CXX_STANDARD 20) project(OCL_TEST_EXAMPLE) # install targets in root of the build dir, using $<0:> generator expression to force it from not being overwritten set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<0:>) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<0:>) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/$<0:>) foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES}) string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/$<0:>) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/$<0:>) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/$<0:>) endforeach() find_package(OpenCAMLib REQUIRED) set(EXAMPLE_SRC ${PROJECT_SOURCE_DIR}/test_example.cpp ) add_executable( test_example ${EXAMPLE_SRC} ) target_link_libraries( test_example OpenCAMLib::ocl ) if(WIN32) add_custom_command(TARGET test_example POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy $ $ COMMAND_EXPAND_LISTS ) endif() ``` -------------------------------- ### Install Node.js Library Dependencies Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Installs the necessary Node.js dependencies for the OpenCAMLib Node.js library using npm. ```shell cd src/nodejslib npm install ``` -------------------------------- ### Install Ubuntu Dependencies for OpenCAMLib Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Installs essential packages for compiling OpenCAMLib on Ubuntu, including git, cmake, curl, build-essential, and libboost-dev. ```shell sudo apt install -y git cmake curl build-essential libboost-dev ``` -------------------------------- ### Install OpenCAMLib via npm or yarn Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Commands to add the JavaScript library to a Node.js project. ```shell npm install --save @opencamlib/opencamlib ``` ```shell yarn add @opencamlib/opencamlib ``` -------------------------------- ### Install OpenCAMLib via Python Source: https://github.com/aewallin/opencamlib/blob/master/README.rst Commands for installing the Python library using pip or within an embedded interpreter. ```shell pip install opencamlib ``` ```shell pip3 install opencamlib ``` ```shell /path/to/your/custom/python -m pip install opencamlib ``` ```python import sys; import subprocess; subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'opencamlib']) ``` -------------------------------- ### Build Debian Binary Package Source: https://github.com/aewallin/opencamlib/blob/master/src/deb/readme_debian.txt Use 'make package' to build the Debian binary package. Install the built package using 'sudo dpkg -i opencamlib--.deb'. ```bash make package ``` ```bash sudo dpkg -i opencamlib--.deb ``` -------------------------------- ### Install OpenCAMLib in custom Python environment Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Use this command to install the library into a specific Python interpreter not in the system PATH. ```shell /path/to/your/custom/python -m pip install opencamlib ``` -------------------------------- ### Install OpenCAMLib via Python interpreter Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Execute this command within an embedded Python console, such as those found in FreeCAD or Blender. ```python import sys; import subprocess; subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'opencamlib']) ``` -------------------------------- ### Install macOS Dependencies for OpenCAMLib Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Installs required dependencies for OpenCAMLib on macOS using Homebrew, including git, cmake, curl, boost, and python@3.11 with boost-python3. ```shell brew install git cmake curl boost python@3.11 boost-python3 ``` -------------------------------- ### Build C++ Library for OpenCAMLib Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Builds the C++ library for OpenCAMLib using CMake. Ensure Boost headers are installed or specify BOOST_ROOT if not in a standard location. ```shell git clone https://github.com/aewallin/opencamlib cd opencamlib mkdir build cd build cmake .. -D BUILD_CXX_LIB="ON" cmake --build . cmake --install . ``` -------------------------------- ### Build Node.js Library for OpenCAMLib Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Compiles the Node.js library for OpenCAMLib using cmake-js. This command configures the build with specific options for Node.js, including parallel builds and installation paths. ```shell git clone https://github.com/aewallin/opencamlib cd opencamlib mkdir build cd build ../src/nodejslib/node_modules/.bin/cmake-js \ build \ --directory ".." \ --out "." \ --parallel 4 \ --CD BUILD_NODEJS_LIB="ON" \ --CD USE_OPENMP="ON" \ --CD CMAKE_INSTALL_PREFIX="/path/to/opencamlib/build/Release/$(node --print 'process.platform')-nodejs-$(node --print 'process.arch')" \ --CD BOOST_ROOT="/path/to/boost" \ --config "Release" ``` -------------------------------- ### Prepare Boost Headers Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Required commands when using a Boost source repository cloned from GitHub. ```shell ./bootstrap.sh ./b2 headers ``` -------------------------------- ### Display Build Instructions Source: https://github.com/aewallin/opencamlib/blob/master/src/CMakeLists.txt Outputs available make commands to the console during the configuration phase. ```cmake message(STATUS "type:") message(STATUS " 'make' for a normal build") message(STATUS " 'make -j8' to build faster (if you have many cpus)") message(STATUS " 'make install' to install") message(STATUS " 'make package' to build a binary deb-packate") message(STATUS " 'make spackage' to build debian source-packages") message(STATUS " 'make test' to run the tests") ``` -------------------------------- ### Configure OpenCAMLib Build Source: https://github.com/aewallin/opencamlib/blob/master/README.rst Configuration flags for building OpenCAMLib with specific architecture and Python support. ```shell variant="release" \ link="static" \ address-model="64" \ architecture="x86" \ --layout="system" \ --with-python \ --user-config="./user-config.jam" \ cxxflags="-fPIC" \ stage ``` -------------------------------- ### Download and Extract Boost Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Commands to fetch and prepare the Boost source code for compilation. ```shell curl "https://boostorg.jfrog.io/artifactory/main/release/1.80.0/source/boost_1_80_0.tar.gz" --output "boost_1_80_0.tar.gz" --location tar -zxf boost_1_80_0.tar.gz -C /tmp/boost cd /tmp/boost/boost_1_80_0 ``` -------------------------------- ### Configure src/algo Directory Source: https://github.com/aewallin/opencamlib/blob/master/src/algo/CMakeLists.txt Sets up the build configuration for the src/algo directory, including conditional definitions for Unix-like systems and include directories. ```cmake message(STATUS " configuring src/algo") if (UNIX) add_definitions(-fPIC) endif (UNIX) include_directories( ${PROJECT_SOURCE_DIR} ) include_directories( ${PROJECT_SOURCE_DIR}/geo ) include_directories( ${PROJECT_SOURCE_DIR}/cutters ) include_directories( ${PROJECT_SOURCE_DIR}/algo ) include_directories( ${PROJECT_SOURCE_DIR}/common ) ``` -------------------------------- ### Compile Boost.Python Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Configuration and build commands for Boost.Python using b2. ```shell echo "using python ;" > ./user-config.jam ./bootstrap.sh ./b2 \ -a \ threading="multi" \ -j4 \ variant="release" \ link="static" \ address-model="64" \ architecture="x86" \ --layout="system" \ --with-python \ --user-config="./user-config.jam" \ cxxflags="-fPIC" \ stage ``` -------------------------------- ### Configure Doxygen Documentation Build Source: https://github.com/aewallin/opencamlib/blob/master/src/CMakeLists.txt Checks for Doxygen and LaTeX dependencies to enable documentation generation via 'make doc'. Requires a Doxyfile template in the project source directory. ```cmake if(BUILD_DOC) find_package(Doxygen) if(DOXYGEN_FOUND) message(STATUS "Found doxygen. Documentation can be built with 'make doc' ") find_package(LATEX) if(NOT LATEX_COMPILER) message(STATUS "latex command LATEX_COMPILER not found but usually required. You will probably get warnings and user inetraction on doxy run.") endif() if(NOT MAKEINDEX_COMPILER) message(STATUS "makeindex command MAKEINDEX_COMPILER not found but usually required.") endif() if(NOT DVIPS_CONVERTER) message(STATUS "dvips command DVIPS_CONVERTER not found but usually required.") endif() configure_file(${PROJECT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) set(DOXY_CONFIG ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) execute_process( COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/doc/html ${CMAKE_CURRENT_BINARY_DIR}/doc/latex ) add_custom_command( OUTPUT doc/latex/index.tex doc/html/index.html COMMAND ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG} COMMENT building LaTex & HTML docs ) add_custom_target( doc DEPENDS doc/latex/index.tex ) if(EXISTS ${PDFLATEX_COMPILER}) add_custom_command( OUTPUT doc/latex/refman.pdf DEPENDS doc/latex/index.tex WORKING_DIRECTORY doc/latex COMMAND make pdf COMMENT building PDF docs COMMAND mv refman.pdf ../ocl-manual.pdf ) add_custom_target( doc-pdf DEPENDS doc/latex/refman.pdf ) add_dependencies(doc doc-pdf) else() message(STATUS "pdflatex compiler not found, PDF docs will not be built") endif() add_custom_target( doc-latex DEPENDS doc/latex/index.tex ) endif() endif() ``` -------------------------------- ### Point Class Operations in C++ Source: https://context7.com/aewallin/opencamlib/llms.txt Demonstrates creating Point objects and performing arithmetic operations like addition, subtraction, dot product, cross product, and normalization in C++. ```cpp #include ocl::Point p1(1.2, 3.4, 5.6); ocl::Point p2(1.23, 4.56, 3.219); // Arithmetic operations ocl::Point sum = p1 + p2; ocl::Point diff = p1 - p2; double dot = p1.dot(p2); ocl::Point cross = p1.cross(p2); double length = p1.norm(); // Normalize ocl::Point p3 = p1; p3.normalize(); ``` -------------------------------- ### Perform Machining Operations in C++ Source: https://context7.com/aewallin/opencamlib/llms.txt Demonstrates loading an STL model, configuring cutters, and executing waterline and path drop operations. ```cpp #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include int main() { std::cout << "OCL version: " << ocl::version() << "\n"; std::cout << "Max threads: " << ocl::max_threads() << "\n"; // Load STL surface ocl::STLSurf surface; std::wstring stlPath = L"model.stl"; ocl::STLReader(stlPath, surface); std::cout << "Loaded " << surface.size() << " triangles\n"; // Create cutters ocl::CylCutter cylCutter(0.4, 10); ocl::BallCutter ballCutter(4, 20); ocl::BullCutter bullCutter(4, 0.05, 20); ocl::ConeCutter coneCutter(4, 0.05, 20); // Waterline operation ocl::Waterline wl; wl.setSTL(surface); wl.setCutter(&cylCutter); wl.setSampling(0.1); for (double z = 0; z < 2.0; z += 0.1) { wl.reset(); wl.setZ(z); wl.run(); auto loops = wl.getLoops(); // Process loops... } // Path drop cutter operation ocl::Path path; ocl::Point p1(-2, 0, 0); ocl::Point p2(11, 0, 0); ocl::Line line(p1, p2); path.append(line); ocl::AdaptivePathDropCutter apdc; apdc.setSTL(surface); apdc.setCutter(&ballCutter); apdc.setPath(&path); apdc.setSampling(0.1); apdc.setMinSampling(0.01); apdc.setZ(0); apdc.run(); auto points = apdc.getPoints(); for (const auto& pt : points) { std::cout << "G01 X" << pt.x << " Y" << pt.y << " Z" << pt.z << "\n"; } return 0; } ``` -------------------------------- ### Build Debian Source Package Source: https://github.com/aewallin/opencamlib/blob/master/src/deb/readme_debian.txt The 'spackage' target in CMakeLists.txt builds the source package. Use 'make spackage' to initiate the build. Upload the resulting .changes file to Launchpad using 'dput'. ```bash make spackage ``` ```bash dput cam-ppa *.changes ``` -------------------------------- ### Point Class Operations in Python Source: https://context7.com/aewallin/opencamlib/llms.txt Demonstrates creating a Point object and performing arithmetic operations like addition, subtraction, dot product, cross product, and normalization. ```python from opencamlib import ocl # Create a point at coordinates (1.5, 2.5, 3.0) p = ocl.Point(1.5, 2.5, 3.0) print(f"X={p.x}, Y={p.y}, Z={p.z}") # Point arithmetic p1 = ocl.Point(1, 2, 3) p2 = ocl.Point(4, 5, 6) p3 = p1 + p2 # Addition p4 = p1 - p2 # Subtraction dot = p1.dot(p2) # Dot product cross = p1.cross(p2) # Cross product length = p1.norm() # Vector length p1.normalize() # Normalize in place ``` -------------------------------- ### Create Paths and Segments Source: https://context7.com/aewallin/opencamlib/llms.txt Construct paths by appending line segments defined by points. ```python p1 = ocl.Point(0, 0, 0) p2 = ocl.Point(10, 0, 0) line = ocl.Line(p1, p2) # Create a path and add lines to it path = ocl.Path() path.append(line) # Add more lines for a multi-segment path p3 = ocl.Point(10, 5, 0) line2 = ocl.Line(p2, p3) path.append(line2) ``` ```javascript const { Point, Line, Path } = require('@opencamlib/opencamlib') // Create points and line const p1 = new Point(0, 0, 0) const p2 = new Point(10, 0, 0) const line = new Line(p1, p2) // Build a path const path = new Path() path.append(line) // Add another segment const p3 = new Point(10, 5, 0) const line2 = new Line(p2, p3) path.append(line2) ``` -------------------------------- ### Build Emscripten Library Source: https://github.com/aewallin/opencamlib/blob/master/README.rst Configures and builds the Emscripten library using emcmake and emmake. Ensure to source the emsdk environment and replace path placeholders. USE_OPENMP is disabled as it's not supported with Emscripten. ```shell source path/to/emsdk/emsdk_env.sh git clone https://github.com/aewallin/opencamlib cd opencamlib mkdir build cd build emcmake \ -D CMAKE_BUILD_TYPE="Release" \ -D BUILD_EMSCRIPTEN_LIB="ON" \ -D USE_OPENMP="OFF" \ -D CMAKE_INSTALL_PREFIX="/path/to/opencamlib/src/npmpackage/build" \ -D BOOST_ROOT="/path/to/boost" \ .. emmake make ``` -------------------------------- ### Configure pbuilder for Universe Dependencies Source: https://github.com/aewallin/opencamlib/blob/master/src/deb/readme_debian.txt If your package has dependencies from the 'universe' repository, add 'COMPONENTS="main universe"' to your '~/.pbuilderrc' file. The pbuilder environment needs to be recreated after this change. ```bash HOOKDIR="/var/cache/pbuilder/hook.d" COMPONENTS="main universe" ``` -------------------------------- ### Include CPack Source: https://github.com/aewallin/opencamlib/blob/master/src/CMakeLists.txt Integrates CPack for binary packaging; should be placed at the end of the CMake configuration. ```cmake include(CPack) # this should be last ``` -------------------------------- ### Test Source Package Build with pbuilder Source: https://github.com/aewallin/opencamlib/blob/master/src/deb/readme_debian.txt Use 'pbuilder' to test the build of a Debian source package. Ensure 'pbuilder' is set up correctly, especially if dependencies from 'universe' are required. ```bash sudo pbuilder --create ``` ```bash sudo pbuilder build *.dsc ``` -------------------------------- ### Configure src/dropcutter Directory Source: https://github.com/aewallin/opencamlib/blob/master/src/dropcutter/CMakeLists.txt This CMakeLists.txt file configures the build for the src/dropcutter directory. It sets up include paths and defines a static library named ocl_dropcutter. ```cmake message(STATUS " configuring src/dropcutter") if (UNIX) add_definitions(-fPIC) endif (UNIX) include_directories( ${PROJECT_SOURCE_DIR} ) include_directories( ${PROJECT_SOURCE_DIR}/geo ) include_directories( ${PROJECT_SOURCE_DIR}/algo ) include_directories( ${PROJECT_SOURCE_DIR}/dropcutter ) include_directories( ${PROJECT_SOURCE_DIR}/cutters ) include_directories( ${PROJECT_SOURCE_DIR}/common ) add_library( ocl_dropcutter STATIC ${OCL_DROPCUTTER_SRC} ) ``` -------------------------------- ### Build Emscripten Library for OpenCAMLib Source: https://github.com/aewallin/opencamlib/blob/master/docs/index.md Compiles the Emscripten library for OpenCAMLib. This requires activating the Emscripten environment and configuring CMake with specific build options, including disabling OpenMP. ```shell source path/to/emsdk/emsdk_env.sh git clone https://github.com/aewallin/opencamlib cd opencamlib mkdir build cd build emcmake cmake \ -D CMAKE_BUILD_TYPE="Release" \ -D BUILD_EMSCRIPTEN_LIB="ON" \ -D USE_OPENMP="OFF" \ -D CMAKE_INSTALL_PREFIX="/path/to/opencamlib/src/npmpackage/build" \ -D BOOST_ROOT="/path/to/boost" \ .. emmake make ``` -------------------------------- ### Integrate OpenCAMLib with CMake Source: https://context7.com/aewallin/opencamlib/llms.txt Configuration for linking the OpenCAMLib library into a C++ project. ```cmake cmake_minimum_required(VERSION 3.15) project(MyCAMProject) find_package(OpenCAMLib REQUIRED) add_executable(my_cam_app main.cpp) target_link_libraries(my_cam_app OpenCAMLib::ocl) ``` -------------------------------- ### Build Static ocl_algo Library Source: https://github.com/aewallin/opencamlib/blob/master/src/algo/CMakeLists.txt Defines a static library named 'ocl_algo' using source files from the OCL_ALGO_SRC variable. Ensure OCL_ALGO_SRC is defined elsewhere in the CMake configuration. ```cmake add_library( ocl_algo STATIC ${OCL_ALGO_SRC} ) ``` -------------------------------- ### Perform Waterline Operations Source: https://context7.com/aewallin/opencamlib/llms.txt Generate toolpaths at constant Z heights using the Waterline algorithm. ```python from opencamlib import ocl # Load surface surface = ocl.STLSurf() ocl.STLReader("model.stl", surface) # Create cutter cutter = ocl.BallCutter(0.5, 10) # Configure waterline operation wl = ocl.Waterline() wl.setSTL(surface) wl.setCutter(cutter) wl.setSampling(0.0314) # Sampling resolution # Generate waterlines at multiple Z heights z_heights = [0.2, 0.4, 0.6, 0.8, 1.0, 1.2] all_loops = [] for z in z_heights: wl.reset() wl.setZ(z) wl.run() loops = wl.getLoops() all_loops.append(loops) # Output G-code for each loop for loop in loops: for point in loop: print(f"G01 X{point.x:.5f} Y{point.y:.5f} Z{point.z:.5f}") ``` ```javascript const fs = require('fs') const { Waterline, STLSurf, STLReader, CylCutter } = require('@opencamlib/opencamlib') const surface = new STLSurf() const stlContents = fs.readFileSync('model.stl') new STLReader(stlContents, surface) const cutter = new CylCutter(4, 20) const wl = new Waterline() wl.setSTL(surface) wl.setCutter(cutter) wl.setZ(1.0) wl.setSampling(0.1) wl.run() const loops = wl.getLoops() loops.forEach(loop => { loop.forEach(point => { console.log(`G01 X${point[0].toFixed(5)} Y${point[1].toFixed(5)} Z${point[2].toFixed(5)}`) }) }) ``` -------------------------------- ### Create Cone Cutter in Python Source: https://context7.com/aewallin/opencamlib/llms.txt Create a ConeCutter (tapered end mill) with specified diameter, angle (in radians), and length. Prints the cutter representation. ```python from opencamlib import ocl import math # Create a cone cutter: diameter=4mm, angle=45 degrees, length=20mm cutter = ocl.ConeCutter(4, math.pi/4, 20) print(cutter) ``` -------------------------------- ### Configure OpenMP Support Source: https://github.com/aewallin/opencamlib/blob/master/src/CMakeLists.txt Detects and configures OpenMP, including platform-specific paths for macOS and compiler flag injection. ```cmake if(USE_OPENMP) if(APPLE) if(DEFINED ENV{OPENMP_PREFIX_MACOS}) message(STATUS "Will use libomp at $ENV{OPENMP_PREFIX_MACOS}.") set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp") set(OpenMP_C_LIB_NAMES "omp") set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp") set(OpenMP_CXX_LIB_NAMES "omp") set(OpenMP_omp_LIBRARY "$ENV{OPENMP_PREFIX_MACOS}/lib/libomp.dylib") include_directories("$ENV{OPENMP_PREFIX_MACOS}/include") else() list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/libomp") list(APPEND CMAKE_PREFIX_PATH "/opt/homebrew/opt/libomp") endif() endif() find_package(OpenMP REQUIRED) if(OPENMP_FOUND) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") message(STATUS "found OpenMP, compiling with flags: " ${OpenMP_CXX_FLAGS} ) include_directories(${OpenMP_CXX_INCLUDE_DIRS}) endif() endif() ``` -------------------------------- ### Compile Boost.Python Source: https://github.com/aewallin/opencamlib/blob/master/README.rst Configures and compiles Boost.Python using b2, specifying multi-threading and parallel build options. ```shell echo "using python ;" > ./user-config.jam ./bootstrap.sh ./b2 \ -a \ threading="multi" \ -j4 \ ``` -------------------------------- ### Configure OpenCAMLib src/common Source: https://github.com/aewallin/opencamlib/blob/master/src/common/CMakeLists.txt This snippet configures the build for the src/common directory. It sets compiler flags for Unix-like systems and defines include directories for various submodules. ```cmake message(STATUS " configuring src/common") if (UNIX) add_definitions(-fPIC) endif (UNIX) include_directories( ${PROJECT_SOURCE_DIR} ) include_directories( ${PROJECT_SOURCE_DIR}/geo ) include_directories( ${PROJECT_SOURCE_DIR}/algo ) include_directories( ${PROJECT_SOURCE_DIR}/dropcutter ) include_directories( ${PROJECT_SOURCE_DIR}/cutters ) include_directories( ${PROJECT_SOURCE_DIR}/common ) add_library( ocl_common STATIC ${OCL_COMMON_SRC} ) ``` -------------------------------- ### Manage Project Versioning Source: https://github.com/aewallin/opencamlib/blob/master/src/CMakeLists.txt Extracts version information from an existing header or generates a new one based on build specifications or Git commit IDs. ```cmake if(EXISTS ${PROJECT_SOURCE_DIR}/version_string.hpp) file(STRINGS "${PROJECT_SOURCE_DIR}/version_string.hpp" PROJECT_BUILD_SPECIFICATION REGEX "^[ \t]*#define[ \t]+VERSION_STRING[ \t]+.*$") if(PROJECT_BUILD_SPECIFICATION) string(REGEX REPLACE ".*#define[ \t]+VERSION_STRING[ \t]+\"(.*)\".*" "\\1" MY_VERSION ${PROJECT_BUILD_SPECIFICATION}) else() message(FATAL_ERROR "Data were not found for the required build specification.") endif() set(version_string ${PROJECT_SOURCE_DIR}/version_string.hpp) else() ################ create version_string.hpp, http://stackoverflow.com/questions/3780667 # include the output directory, where the version_string.hpp file is generated include_directories(${CMAKE_CURRENT_BINARY_DIR}) if(VERSION_STRING) set( vstring "//version_string.hpp - written by cmake. changes will be lost!\n" "#ifndef VERSION_STRING\n" "#define VERSION_STRING \"${VERSION_STRING}\"\n" "#endif\n" ) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/version_string.hpp ${vstring} ) set(MY_VERSION ${VERSION_STRING}) set(version_string ${VERSION_STRING}) else() include(version_string.cmake) # now parse the git commit id: string(REGEX REPLACE "([0-9]+).*" "\\1" GIT_MAJOR_VERSION "${GIT_COMMIT_ID}" ) string(REGEX REPLACE "[0-9]+.([0-9]+)-.*" "\\1" GIT_MINOR_VERSION "${GIT_COMMIT_ID}" ) string(REGEX REPLACE "[0-9]+.[0-9]+-(.*)-.*" "\\1" GIT_PATCH_VERSION "${GIT_COMMIT_ID}" ) set(MY_VERSION "${GIT_MAJOR_VERSION}.${GIT_MINOR_VERSION}.${GIT_PATCH_VERSION}" CACHE STRING "name") set(version_string ${CMAKE_CURRENT_BINARY_DIR}/version_string.hpp) endif() endif() message(STATUS "OpenCAMLib version: ${MY_VERSION}") ``` -------------------------------- ### Create Bull Cutter in Python Source: https://context7.com/aewallin/opencamlib/llms.txt Create a BullCutter (radius end mill/toroidal) with specified diameter, corner radius, and length. Prints the cutter representation. ```python from opencamlib import ocl # Create a bull cutter: diameter=4mm, corner radius=0.5mm, length=20mm cutter = ocl.BullCutter(4, 0.5, 20) print(cutter) # Output: BullCutter(d=4, r=0.5, L=20) ``` -------------------------------- ### Perform Adaptive Path Cutting Source: https://context7.com/aewallin/opencamlib/llms.txt Uses AdaptivePathDropCutter to refine toolpaths in steep areas. Requires setting both sampling and minimum sampling parameters. ```python from opencamlib import ocl surface = ocl.STLSurf() ocl.STLReader("model.stl", surface) cutter = ocl.CylCutter(0.25, 5) # Create a zig-zag parallel finish pattern def create_zig_paths(xmin, xmax, ymin, ymax, num_lines): paths = [] dy = (ymax - ymin) / (num_lines - 1) for n in range(num_lines): y = ymin + n * dy p1 = ocl.Point(xmin, y, 0) p2 = ocl.Point(xmax, y, 0) line = ocl.Line(p1, p2) path = ocl.Path() path.append(line) paths.append(path) return paths paths = create_zig_paths(0, 10, 0, 12, 40) # Configure adaptive path drop cutter apdc = ocl.AdaptivePathDropCutter() apdc.setSTL(surface) apdc.setCutter(cutter) apdc.setSampling(0.04) # Maximum step distance apdc.setMinSampling(0.01) # Minimum step distance for steep areas toolpaths = [] for path in paths: apdc.setPath(path) apdc.run() points = apdc.getCLPoints() toolpaths.append(points) # Output G-code for tp in toolpaths: if len(tp) > 0: print(f"G00 X{tp[0].x:.4f} Y{tp[0].y:.4f}") print(f"G01 Z{tp[0].z:.4f}") for point in tp: print(f"G01 X{point.x:.4f} Y{point.y:.4f} Z{point.z:.4f}") print("G00 Z3") ``` ```javascript const fs = require('fs') const { AdaptivePathDropCutter, STLSurf, STLReader, CylCutter, Path, Line, Point } = require('@opencamlib/opencamlib') const surface = new STLSurf() new STLReader(fs.readFileSync('model.stl'), surface) const cutter = new CylCutter(0.25, 5) // Create zig-zag paths function createZigPaths(xmin, xmax, ymin, ymax, Ny) { const paths = [] const dy = (ymax - ymin) / (Ny - 1) for (let n = 0; n < Ny; n++) { const y = ymin + n * dy const p1 = new Point(xmin, y, 0) const p2 = new Point(xmax, y, 0) const line = new Line(p1, p2) const path = new Path() path.append(line) paths.push(path) } return paths } const paths = createZigPaths(0, 10, 0, 12, 40) const apdc = new AdaptivePathDropCutter() apdc.setSTL(surface) apdc.setCutter(cutter) apdc.setSampling(0.04) apdc.setMinSampling(0.01) paths.forEach(path => { apdc.setPath(path) apdc.run() const points = apdc.getCLPoints() if (points.length > 0) { console.log(`G00 X${points[0][0].toFixed(4)} Y${points[0][1].toFixed(4)}`) console.log(`G01 Z${points[0][2].toFixed(4)}`) points.forEach(pt => { console.log(`G01 X${pt[0].toFixed(4)} Y${pt[1].toFixed(4)} Z${pt[2].toFixed(4)}`) }) console.log('G00 Z3') } }) ``` -------------------------------- ### Create Cone Cutter in Node.js Source: https://context7.com/aewallin/opencamlib/llms.txt Create a ConeCutter (tapered end mill) with specified diameter, angle (in radians), and length. ```javascript const { ConeCutter } = require('@opencamlib/opencamlib') // Create a cone cutter: diameter=4, angle=PI/4 radians (45 deg), length=20 const cutter = new ConeCutter(4, Math.PI / 4, 20) ``` -------------------------------- ### Define Debian Source Package Target Source: https://github.com/aewallin/opencamlib/blob/master/src/CMakeLists.txt Creates a custom target 'spackage' to trigger Debian source package creation using external CMake scripts. ```cmake add_custom_target(spackage ${CMAKE_COMMAND} -D SRC_DIR:STRING=${CMAKE_CURRENT_SOURCE_DIR} -D MY_VERSION:STRING=${MY_VERSION} -C ${CMAKE_CURRENT_SOURCE_DIR}/deb/package_details.cmake -P ${CMAKE_CURRENT_SOURCE_DIR}/deb/DebSourcePPA.cmake ) ``` -------------------------------- ### Create Cylindrical Cutter in Python Source: https://context7.com/aewallin/opencamlib/llms.txt Create a CylCutter (flat end mill) with specified diameter and length. Prints the cutter representation. ```python from opencamlib import ocl # Create a cylindrical cutter with 4mm diameter and 20mm length cutter = ocl.CylCutter(4, 20) print(cutter) # Output: CylCutter(d=4, L=20) ``` -------------------------------- ### Filter Toolpaths with LineCLFilter Source: https://context7.com/aewallin/opencamlib/llms.txt Reduces G-code file size by removing redundant points within a straight-line tolerance. ```python from opencamlib import ocl # Create sample CL points p0 = ocl.CLPoint(0, 0, 0) p1 = ocl.CLPoint(1, 2, 3) p2 = ocl.CLPoint(1.1, 2.2, 3.3) p3 = ocl.CLPoint(2, 4, 6) ``` -------------------------------- ### Load STL Surface in Python Source: https://context7.com/aewallin/opencamlib/llms.txt Load an STL file into an STLSurf object using STLReader. Checks the number of loaded triangles. ```python from opencamlib import ocl # Create an STL surface container surface = ocl.STLSurf() # Load STL file into the surface ocl.STLReader("model.stl", surface) # Check how many triangles were loaded print(f"Loaded {surface.size()} triangles") ``` -------------------------------- ### Execute BatchDropCutter Operation Source: https://context7.com/aewallin/opencamlib/llms.txt Evaluates multiple points in parallel for grid-based surface mapping. ```python from opencamlib import ocl surface = ocl.STLSurf() ocl.STLReader("model.stl", surface) cutter = ocl.BallCutter(1.4, 5) # Create a grid of CL points clpoints = [] for x in range(0, 100): for y in range(0, 100): p = ocl.CLPoint(x * 0.1, y * 0.1, -17) clpoints.append(p) print(f"Generated {len(clpoints)} CL points") # Configure batch drop cutter bdc = ocl.BatchDropCutter() bdc.setSTL(surface) bdc.setCutter(cutter) # Add all points for p in clpoints: bdc.appendPoint(p) # Run the calculation (uses parallel processing) print(f"Using {bdc.getThreads()} threads") bdc.run() # Get the computed CL points with Z values result_points = bdc.getCLPoints() for point in result_points: print(f"X{point.x:.4f} Y{point.y:.4f} Z{point.z:.4f}") ``` -------------------------------- ### Create Bull Cutter in Node.js Source: https://context7.com/aewallin/opencamlib/llms.txt Create a BullCutter (radius end mill/toroidal) with specified diameter, corner radius, and length. ```javascript const { BullCutter } = require('@opencamlib/opencamlib') // Create a bull cutter: diameter=4, cornerRadius=0.5, length=20 const cutter = new BullCutter(4, 0.5, 20) ``` -------------------------------- ### Perform AdaptiveWaterline Operations Source: https://context7.com/aewallin/opencamlib/llms.txt Use adaptive sampling to refine toolpath resolution in detailed areas. ```python from opencamlib import ocl surface = ocl.STLSurf() ocl.STLReader("model.stl", surface) cutter = ocl.BallCutter(0.5, 10) # Configure adaptive waterline awl = ocl.AdaptiveWaterline() awl.setSTL(surface) awl.setCutter(cutter) awl.setSampling(0.1) # Maximum sampling interval awl.setMinSampling(0.001) # Minimum sampling (for detailed areas) awl.setZ(1.0) awl.run() loops = awl.getLoops() for loop in loops: for point in loop: print(f"G01 X{point.x:.5f} Y{point.y:.5f} Z{point.z:.5f}") ``` ```javascript const { AdaptiveWaterline, STLSurf, STLReader, CylCutter } = require('@opencamlib/opencamlib') const surface = new STLSurf() new STLReader(fs.readFileSync('model.stl'), surface) const cutter = new CylCutter(4, 20) const awl = new AdaptiveWaterline() awl.setSTL(surface) awl.setCutter(cutter) awl.setSampling(0.1) awl.setMinSampling(0.001) awl.setZ(1) awl.run() awl.getLoops().forEach(loop => { loop.forEach(point => { console.log(`G01 X${point[0]} Y${point[1]} Z${point[2]}`) }) }) ``` -------------------------------- ### Create Ball Cutter in Python Source: https://context7.com/aewallin/opencamlib/llms.txt Create a BallCutter (ball end mill) with specified diameter and length. Prints the cutter representation. ```python from opencamlib import ocl # Create a ball cutter with 4mm diameter and 20mm length cutter = ocl.BallCutter(4, 20) print(cutter) # Output: BallCutter(d=4, L=20) ``` -------------------------------- ### Configure Boost for Emscripten Source: https://github.com/aewallin/opencamlib/blob/master/src/CMakeLists.txt Adjusts CMake root path modes to ensure Boost is correctly located when building for Emscripten. ```cmake if(BUILD_EMSCRIPTEN_LIB) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) endif() find_package(Boost REQUIRED) include_directories(${Boost_INCLUDE_DIRS}) if(BUILD_EMSCRIPTEN_LIB) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) endif() ``` -------------------------------- ### Perform PathDropCutter Operations Source: https://context7.com/aewallin/opencamlib/llms.txt Project a path onto a 3D surface by dropping the cutter until contact. ```python from opencamlib import ocl surface = ocl.STLSurf() ocl.STLReader("model.stl", surface) cutter = ocl.CylCutter(4, 20) # Create a path from point A to B p1 = ocl.Point(-2, 4, 0) p2 = ocl.Point(11, 4, 0) line = ocl.Line(p1, p2) path = ocl.Path() path.append(line) # Configure path drop cutter pdc = ocl.PathDropCutter() pdc.setSTL(surface) pdc.setCutter(cutter) pdc.setPath(path) pdc.setZ(0) # Starting Z height pdc.setSampling(0.1) pdc.run() ``` -------------------------------- ### Create Cylindrical Cutter in Node.js Source: https://context7.com/aewallin/opencamlib/llms.txt Create a CylCutter (flat end mill) with specified diameter and length. ```javascript const { CylCutter } = require('@opencamlib/opencamlib') // Create a cylindrical cutter: diameter=4, length=20 const cutter = new CylCutter(4, 20) ``` -------------------------------- ### Generate STL Surfaces from Triangles Source: https://context7.com/aewallin/opencamlib/llms.txt Manually define geometry by adding triangles to an STLSurf object. ```python from opencamlib import ocl # Define three vertices of a triangle a = ocl.Point(0.1, 0, -10) b = ocl.Point(-0.1, 0, -10) c = ocl.Point(0, 0, 0) # Create a triangle triangle = ocl.Triangle(a, b, c) # Add triangle to a surface surface = ocl.STLSurf() surface.addTriangle(triangle) print(f"Surface has {surface.size()} triangles") ``` -------------------------------- ### Load STL Surface in Node.js Source: https://context7.com/aewallin/opencamlib/llms.txt Load an STL file into an STLSurf object using STLReader in Node.js. Requires fs module for file reading. ```javascript const fs = require('fs') const { STLSurf, STLReader } = require('@opencamlib/opencamlib') // Create STL surface container const surface = new STLSurf() // Read STL file contents and parse into surface const stlContents = fs.readFileSync('model.stl') new STLReader(stlContents, surface) console.log('Surface loaded successfully') ``` -------------------------------- ### Generate Cutter-Location Points with PathDropCutter Source: https://context7.com/aewallin/opencamlib/llms.txt Extracts cutter-location points from a defined path and surface. The output is formatted as G-code commands. ```python points = pdc.getCLPoints() for point in points: print(f"G01 X{point.x:.5f} Y{point.y:.5f} Z{point.z:.5f}") ``` ```javascript const { PathDropCutter, STLSurf, STLReader, CylCutter, Path, Line, Point } = require('@opencamlib/opencamlib') const surface = new STLSurf() new STLReader(fs.readFileSync('model.stl'), surface) const cutter = new CylCutter(4, 20) // Define the path const path = new Path() const p1 = new Point(-2, 4, 0) const p2 = new Point(11, 4, 0) const line = new Line(p1, p2) path.append(line) // Run path drop cutter const pdc = new PathDropCutter() pdc.setSTL(surface) pdc.setCutter(cutter) pdc.setPath(path) pdc.setZ(0) pdc.setSampling(0.1) pdc.run() const points = pdc.getCLPoints() points.forEach(point => { console.log(`G01 X${point[0]} Y${point[1]} Z${point[2]}`) }) ``` -------------------------------- ### Create Ball Cutter in Node.js Source: https://context7.com/aewallin/opencamlib/llms.txt Create a BallCutter (ball end mill) with specified diameter and length. ```javascript const { BallCutter } = require('@opencamlib/opencamlib') // Create a ball cutter: diameter=4, length=20 const cutter = new BallCutter(4, 20) ```