-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6bedd0e
commit ff19c85
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
find_package(Qt6 COMPONENTS Core Widgets Gui OpenGLWidgets REQUIRED) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
file(GLOB Source ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/*.h) | ||
|
||
add_library(pygerber-parser SHARED ${Source}) | ||
target_link_libraries(pygerber-parser PRIVATE gerber_engine Qt6::Gui Qt6::Widgets Qt6::Core) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <QApplication> | ||
#include <QPixmap> | ||
|
||
#include <iostream> | ||
|
||
#include "gerber_parser/bound_box.h" | ||
#include "gerber/gerber.h" | ||
#include "gerber_parser/gerber_parser.h" | ||
#include "engines/qpainter_engine.h" | ||
|
||
extern "C" { | ||
|
||
typedef struct ImageData_t { | ||
uchar* data; | ||
int size; | ||
}ImageData; | ||
|
||
ImageData RenderGerber2Image(char* gerber_file, int width, int height) | ||
{ | ||
int argc = 1; | ||
char arg1[] = "pygerber-parser"; | ||
char* argv[] = {arg1}; | ||
QApplication app(argc, argv); | ||
|
||
std::string file_path = std::string(gerber_file); | ||
if (file_path.empty()) { | ||
std::cout << "null gerber file path." << std::endl; | ||
return {}; | ||
} | ||
|
||
try { | ||
auto parser = std::make_shared<GerberParser>(file_path); | ||
auto gerber = parser->GetGerber(); | ||
auto image = std::make_unique<QPixmap>(width, height); | ||
auto engine = std::make_unique<QPainterEngine>( | ||
image.get(), gerber->GetBBox(), 0.00); | ||
engine->RenderGerber(gerber); | ||
|
||
auto img = image->toImage(); | ||
ImageData result; | ||
result.size = img.sizeInBytes(); | ||
auto* data = (uchar*)malloc(result.size); | ||
memcpy(data, img.bits(), result.size); | ||
result.data = data; | ||
|
||
return result; | ||
} | ||
catch (const std::exception& e) { | ||
std::cout << e.what() << std::endl; | ||
return {}; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import ctypes | ||
|
||
lib = ctypes.cdll.LoadLibrary('./libpygerber-parser.so') | ||
|
||
def gerber2image(gerber_file:str): | ||
result = lib.RenderGerber2Image(ctypes.c_char_p(bytes(gerber_file, encoding="utf-8"))) |