Skip to content

Commit

Permalink
Merge pull request #11 from GenerateNU/features/iges-conversion
Browse files Browse the repository at this point in the history
Features/iges conversion
  • Loading branch information
hmcclew authored Feb 7, 2024
2 parents bfe581c + 81f7e05 commit 724a322
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ find_package(OpenCASCADE REQUIRED)
include_directories(${OCE_INCLUDE_DIRS})

add_executable(cad_to_gcode src/cad_to_gcode.cpp)
target_link_libraries(cad_to_gcode ${OpenCASCADE_LIBRARIES})
add_executable(iges_to_topo src/iges_to_topo.cpp)
target_link_libraries(cad_to_gcode ${OpenCASCADE_LIBRARIES})
target_link_libraries(iges_to_topo ${OpenCASCADE_LIBRARIES})

46 changes: 46 additions & 0 deletions backend/src/iges_to_topo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
#include <IGESControl_Reader.hxx>
#include <TopoDS_Shape.hxx>

// takes in an IGES file and returns a TopoDS_Shape
TopoDS_Shape read_iges(const char* filename)
{
IGESControl_Reader reader;
if (reader.ReadFile(filename) != IFSelect_RetDone) {
std::cout << "Error: cannot read file" << std::endl;
throw std::runtime_error("Error: Unable to read the IGES file.");
}

if (!reader.TransferRoots()) {
std::cerr << "Error: Unable to transfer the content to TopoDS_Shape." << std::endl;
throw std::runtime_error("Error: Unable to transfer the content to TopoDS_Shape.");
}
TopoDS_Shape shape = reader.OneShape();
return shape;
}

// to see if it works
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <IGES file>" << std::endl;
return 1; // Return a non-zero value to indicate an error
}

const char* igesFileName = argv[1];
std::cout <<igesFileName;

try {
// Call the function to read IGES file and get TopoDS_Shape
TopoDS_Shape shape = read_iges(igesFileName);
if (!shape.IsNull()) {
std::cout << "Shape is not null." << std::endl;
} else {
std::cout << "Shape is null." << std::endl;
}
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return 1; // Return 1 for error
}

return 0; // Return 0 for success
}

0 comments on commit 724a322

Please sign in to comment.