Skip to content

Commit 074e843

Browse files
committed
feat: make ortools optional
1 parent 37af267 commit 074e843

7 files changed

Lines changed: 35 additions & 8 deletions

File tree

.github/workflows/deploy-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- name: CMake
4141
shell: bash
4242
run: |
43-
cmake -B build -DBUILD_TESTING=OFF -DQt6_DIR=${Qt_ROOT}/lib/cmake/Qt6 -DCMAKE_PREFIX_PATH=../or-tools_x64_VisualStudio2022_cpp_v9.10.4067
43+
cmake -B build -DBUILD_TESTING=OFF -DWITH_ORTOOLS=ON -DQt6_DIR=${Qt_ROOT}/lib/cmake/Qt6 -DCMAKE_PREFIX_PATH=../or-tools_x64_VisualStudio2022_cpp_v9.10.4067
4444
- name: Build
4545
run: cmake --build build --config Release
4646
- name: Deploy Qt

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
44

55
project(dxfplotter)
66

7+
option(WITH_ORTOOLS OFF "Enable ortools support for path optimization")
8+
79
include(CTest)
810
include(CPack)
911

@@ -44,7 +46,9 @@ set(TEMPLATE_DIR ${PROJECT_SOURCE_DIR}/template)
4446
find_package(codecov)
4547

4648
find_package(PythonInterp REQUIRED)
47-
find_package(ortools CONFIG REQUIRED)
49+
if (WITH_ORTOOLS)
50+
find_package(ortools CONFIG REQUIRED)
51+
endif()
4852

4953
find_package(Qt6 COMPONENTS REQUIRED
5054
Core

ci/buildappimage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pushd "$BUILD_DIR"
3737

3838
# configure build files with CMake
3939
# we need to explicitly set the install prefix, as CMake's default is /usr/local for some reason...
40-
cmake "$REPO_ROOT" -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_TESTING=OFF -DQt6_DIR=/opt/qt/6.8.2/gcc_64/lib/cmake/Qt6
40+
cmake "$REPO_ROOT" -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_TESTING=OFF -DWITH_ORTOOLS=ON -DQt6_DIR=/opt/qt/6.8.2/gcc_64/lib/cmake/Qt6
4141

4242
# build project and install files into AppDir
4343
make -j$(nproc)

ci/buildsonarcloud.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pushd "$BUILD_DIR"
3030

3131
# configure build files with CMake
3232
# we need to explicitly set the install prefix, as CMake's default is /usr/local for some reason...
33-
cmake "$REPO_ROOT" -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON -DQt6_DIR=/opt/qt/6.8.2/gcc_64/lib/cmake/Qt6
33+
cmake "$REPO_ROOT" -DCMAKE_BUILD_TYPE=Debug -DWITH_ORTOOLS=ON -DENABLE_COVERAGE=ON -DQt6_DIR=/opt/qt/6.8.2/gcc_64/lib/cmake/Qt6
3434

3535
# Wraps the compilation with the Build Wrapper to generate configuration (used
3636
# later by the SonarQube Scanner) into the "bw-output" folder

src/geometry/CMakeLists.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ set(SRC
88
circle.cpp
99
cubicspline.cpp
1010
line.cpp
11-
orderoptimizer.cpp
1211
pocketer.cpp
1312
polyline.cpp
1413
quadraticspline.cpp
@@ -22,14 +21,26 @@ set(SRC
2221
circle.h
2322
cubicspline.h
2423
line.h
25-
orderoptimizer.h
2624
polyline.h
2725
quadraticspline.h
2826
spline.h
2927
rect.h
3028
utils.h
3129
)
3230

31+
if (WITH_ORTOOLS)
32+
list(APPEND SRC
33+
orderoptimizer.cpp
34+
35+
orderoptimizer.h
36+
)
37+
endif()
38+
3339
add_library(geometry ${SRC})
34-
target_link_libraries(geometry PUBLIC ortools::ortools)
40+
if (WITH_ORTOOLS)
41+
target_link_libraries(geometry PUBLIC ortools::ortools)
42+
target_compile_definitions(geometry PUBLIC WITH_ORTOOLS)
43+
endif()
44+
45+
3546
add_coverage(geometry)

src/model/task.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
#include <iterator>
44
#include <common/copy.h>
5+
6+
#ifdef WITH_ORTOOLS
57
#include <geometry/orderoptimizer.h>
8+
#endif
69

710
namespace model
811
{
@@ -198,6 +201,7 @@ void Task::showHidden()
198201
});
199202
}
200203

204+
#ifdef WITH_ORTOOLS
201205
geometry::OrderOptimizer::NodesPerGroup generateNodesSingleGroup(const Path::ListPtr &paths)
202206
{
203207
geometry::OrderOptimizer::Node::List group(paths.size());
@@ -255,9 +259,11 @@ geometry::OrderOptimizer::NodesPerGroup generateNodesPerGroupOfLength(const Path
255259

256260
return nodesPerGroup;
257261
}
262+
#endif
258263

259264
void Task::optimizeOrder(bool maintainPathLengthOrder, float lengthPrecision, float distancePrecision)
260265
{
266+
#ifdef WITH_ORTOOLS
261267
const geometry::OrderOptimizer::NodesPerGroup nodesPerGroup = maintainPathLengthOrder ?
262268
generateNodesPerGroupOfLength(m_paths, lengthPrecision) :
263269
generateNodesSingleGroup(m_paths);
@@ -273,6 +279,7 @@ void Task::optimizeOrder(bool maintainPathLengthOrder, float lengthPrecision, fl
273279

274280
std::swap(m_stack, newPaths);
275281
emit pathOrderChanged();
282+
#endif
276283
}
277284

278285
geometry::Rect Task::selectionBoundingRect() const

test/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ set(SRC
2222
exporterfixture.cpp
2323
exporterrenderer.cpp
2424
gcodeexporter.cpp
25-
orderoptimizer.cpp
2625
path.cpp
2726
pathsettings.cpp
2827
pocketer.cpp
@@ -37,6 +36,12 @@ set(SRC
3736
polylineutils.h
3837
)
3938

39+
if (WITH_ORTOOLS)
40+
list(APPEND SRC
41+
orderoptimizer.cpp
42+
)
43+
endif()
44+
4045
add_executable(dxfplotter-test ${SRC} main.cpp)
4146

4247
target_include_directories(dxfplotter-test PRIVATE ${Qt5Test_INCLUDE_DIRS})

0 commit comments

Comments
 (0)