libarea: split into area-native and area python

This commit is contained in:
Zheng, Lei 2017-01-19 19:01:48 +08:00
parent 9cf075a806
commit 04888f6961
6 changed files with 80 additions and 14 deletions

View File

@ -24,6 +24,24 @@ bool CArea::m_set_processing_length_in_split = false;
double CArea::m_after_MakeOffsets_length = 0.0;
//static const double PI = 3.1415926535897932;
#define _CAREA_PARAM_DEFINE(_class,_type,_name) \
_type CArea::get_##_name() {return _class::_name;}\
void CArea::set_##_name(_type _name) {_class::_name = _name;}
#define CAREA_PARAM_DEFINE(_type,_name) \
_type CArea::get_##_name() {return m_##_name;}\
void CArea::set_##_name(_type _name) {m_##_name = _name;}
_CAREA_PARAM_DEFINE(Point,double,tolerance);
CAREA_PARAM_DEFINE(bool,fit_arcs)
CAREA_PARAM_DEFINE(bool,clipper_simple);
CAREA_PARAM_DEFINE(double,clipper_clean_distance);
CAREA_PARAM_DEFINE(double,accuracy);
CAREA_PARAM_DEFINE(double,units);
CAREA_PARAM_DEFINE(short,min_arc_points);
CAREA_PARAM_DEFINE(short,max_arc_points);
CAREA_PARAM_DEFINE(double,clipper_scale);
void CArea::append(const CCurve& curve)
{
m_curves.push_back(curve);

View File

@ -84,6 +84,21 @@ public:
void SpanIntersections(const Span& span, std::list<Point> &pts)const;
void CurveIntersections(const CCurve& curve, std::list<Point> &pts)const;
void InsideCurves(const CCurve& curve, std::list<CCurve> &curves_inside)const;
//Avoid outside direct accessing static member variable because of Windows DLL issue
#define CAREA_PARAM_DECLARE(_type,_name) \
static _type get_##_name();\
static void set_##_name(_type _name);
CAREA_PARAM_DECLARE(double,tolerance);
CAREA_PARAM_DECLARE(bool,fit_arcs)
CAREA_PARAM_DECLARE(bool,clipper_simple);
CAREA_PARAM_DECLARE(double,clipper_clean_distance);
CAREA_PARAM_DECLARE(double,accuracy);
CAREA_PARAM_DECLARE(double,units);
CAREA_PARAM_DECLARE(short,min_arc_points);
CAREA_PARAM_DECLARE(short,max_arc_points);
CAREA_PARAM_DECLARE(double,clipper_scale);
};
enum eOverlapType

View File

@ -65,37 +65,52 @@ file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
# this makes the Python module
add_library(
area
MODULE
area-native
SHARED
${AREA_SRC_COMMON}
${AREA_SRC_CLIPPER}
)
add_library(
area
MODULE
${PYAREA_SRC}
)
if(MSVC)
set(area_LIBS
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
set(area_native_LIBS
debug MSVCRTD.LIB
debug MSVCPRTD.LIB
optimized MSVCRT.LIB
optimized MSVCPRT.LIB
)
elseif(MINGW)
set(area_LIBS
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
${area_native_LIBS}
)
elseif(MINGW)
set(area_native_LIBS
Rpcrt4.lib
)
set(area_LIBS
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
${area_native_LIBS}
)
else(MSVC)
set(area_native_LIBS
)
set(area_LIBS
${Boost_LIBRARIES}
${PYTHON_LIBRARIES}
)
endif(MSVC)
target_link_libraries(area ${area_LIBS})
target_link_libraries(area-native ${area_native_LIBS})
SET_BIN_DIR(area-native area-native)
target_link_libraries(area area-native ${area_LIBS} ${area_native_LIBS})
SET_BIN_DIR(area area)
SET_PYTHON_PREFIX_SUFFIX(area)
@ -108,8 +123,20 @@ execute_process(
message(STATUS "area module (for Path Workbench) will be installed to: " ${CMAKE_INSTALL_LIBDIR})
if(WIN32)
set_target_properties(area-native PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
INSTALL(TARGETS area-native
RUNTIME DESTINATION bin
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
else(WIN32)
INSTALL(TARGETS area-native
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif(WIN32)
# this installs the python library
install(
TARGETS area
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

View File

@ -13,6 +13,12 @@ double Point::tolerance = 0.001;
//static const double PI = 3.1415926535897932; duplicated in kurve/geometry.h
//This function is moved from header here to solve windows DLL not export
//static variable problem
bool Point::operator==(const Point& p)const{
return fabs(x-p.x)<tolerance && fabs(y-p.y)<tolerance;
}
double Point::length()const
{
return sqrt( x*x + y*y );

View File

@ -48,7 +48,7 @@ public:
const Point operator-(const Point& p)const{return Point(x - p.x, y - p.y);}
const Point operator*(double d)const{return Point(x * d, y * d);}
const Point operator/(double d)const{return Point(x / d, y / d);}
bool operator==(const Point& p)const{return fabs(x-p.x)<tolerance && fabs(y-p.y)<tolerance;}
bool operator==(const Point& p)const;
bool operator!=(const Point &p)const{ return !(*this == p);}
double dist(const Point &p)const{double dx = p.x - x; double dy = p.y - y; return sqrt(dx*dx + dy*dy);}
double length()const;

View File

@ -80,8 +80,8 @@ static void print_curve(const CCurve& c)
for(std::list<CVertex>::const_iterator It = c.m_vertices.begin(); It != c.m_vertices.end(); It++, i++)
{
const CVertex& vertex = *It;
printf("vertex %d type = %d, x = %g, y = %g", i+1, vertex.m_type, vertex.m_p.x / CArea::m_units, vertex.m_p.y / CArea::m_units);
if(vertex.m_type)printf(", xc = %g, yc = %g", vertex.m_c.x / CArea::m_units, vertex.m_c.y / CArea::m_units);
printf("vertex %d type = %d, x = %g, y = %g", i+1, vertex.m_type, vertex.m_p.x / CArea::get_units(), vertex.m_p.y / CArea::get_units());
if(vertex.m_type)printf(", xc = %g, yc = %g", vertex.m_c.x / CArea::get_units(), vertex.m_c.y / CArea::get_units());
printf("\n");
}
}
@ -112,12 +112,12 @@ static CVertex LastVertex(const CCurve& curve)
static void set_units(double units)
{
CArea::m_units = units;
CArea::set_units(units);
}
static double get_units()
{
return CArea::m_units;
return CArea::get_units();
}
static bool holes_linked()