Skip to content

Commit 14ca02f

Browse files
authored
Merge pull request #411 from trelau/splitter
Added GEOMAlgo_Splitter
2 parents aeff558 + b57395b commit 14ca02f

6 files changed

Lines changed: 932 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,19 @@ ${CMAKE_CURRENT_SOURCE_DIR}/src/Addons/Font3d.cpp
270270
swig_add_module(Addons python ${ADDONS_SOURCE_FILES})
271271
swig_link_libraries(Addons ${PYTHON_LIBRARIES} ${OCE_MODEL_LIBRARIES} ${OCE_VISUALIZATION_LIBRARIES})
272272

273+
############
274+
# Splitter #
275+
############
276+
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory src/Splitter)
277+
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/src/Splitter/GEOMAlgo.i PROPERTIES CPLUSPLUS ON)
278+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/Splitter)
279+
set(SPLITTER_SOURCE_FILES
280+
${CMAKE_CURRENT_SOURCE_DIR}/src/Splitter/GEOMAlgo.i
281+
${CMAKE_CURRENT_SOURCE_DIR}/src/Splitter/GEOMAlgo_Splitter.cxx
282+
)
283+
swig_add_module(GEOMAlgo python ${SPLITTER_SOURCE_FILES})
284+
swig_link_libraries(GEOMAlgo ${PYTHON_LIBRARIES} ${OCE_MODEL_LIBRARIES} ${OCE_VISUALIZATION_LIBRARIES})
285+
273286
################
274287
# DataExchange #
275288
################
@@ -344,6 +357,9 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE DESTINATION ${PYTHONOCC_INSTAL
344357
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/AUTHORS DESTINATION ${PYTHONOCC_INSTALL_DIRECTORY} )
345358
# install __init__.py file
346359
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/__init__.py DESTINATION ${PYTHONOCC_INSTALL_DIRECTORY} )
360+
# install Splitter
361+
install(FILES ${BUILD_DIR}/GEOMAlgo.py DESTINATION ${PYTHONOCC_INSTALL_DIRECTORY} )
362+
install(TARGETS _GEOMAlgo DESTINATION ${PYTHONOCC_INSTALL_DIRECTORY} )
347363

348364
#######################
349365
# pythonOCC Packaging #

examples/core_topology_splitter.py

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
##Copyright 2009-2016 Thomas Paviot (tpaviot@gmail.com)
2+
##
3+
##This file is part of pythonOCC.
4+
##
5+
##pythonOCC is free software: you can redistribute it and/or modify
6+
##it under the terms of the GNU Lesser General Public License as published by
7+
##the Free Software Foundation, either version 3 of the License, or
8+
##(at your option) any later version.
9+
##
10+
##pythonOCC is distributed in the hope that it will be useful,
11+
##but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
##GNU Lesser General Public License for more details.
14+
##
15+
##You should have received a copy of the GNU Lesser General Public License
16+
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
17+
from __future__ import print_function
18+
19+
import sys
20+
import time
21+
22+
from OCC.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, \
23+
BRepBuilderAPI_MakeFace
24+
from OCC.Display.SimpleGui import init_display
25+
from OCC.GEOMAlgo import GEOMAlgo_Splitter
26+
from OCC.TopAbs import TopAbs_EDGE
27+
from OCC.TopExp import TopExp_Explorer
28+
from OCC.gp import gp_Dir, gp_Pln, gp_Pnt
29+
30+
display, start_display, add_menu, add_function_to_menu = init_display()
31+
32+
33+
def split_face_and_edge(event=None):
34+
display.EraseAll()
35+
p0 = gp_Pnt()
36+
vnorm = gp_Dir(1, 0, 0)
37+
pln = gp_Pln(p0, vnorm)
38+
face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
39+
p1 = gp_Pnt(0, 0, 15)
40+
p2 = gp_Pnt(0, 0, -15)
41+
edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
42+
# Initialize splitter
43+
splitter = GEOMAlgo_Splitter()
44+
# Add both the face and edge as arguments. This will split both of the
45+
# shapes.
46+
splitter.AddArgument(face)
47+
splitter.AddArgument(edge)
48+
splitter.Perform()
49+
display.DisplayShape(splitter.Shape())
50+
display.FitAll()
51+
52+
53+
def split_face_with_edge(event=None):
54+
display.EraseAll()
55+
p0 = gp_Pnt()
56+
vnorm = gp_Dir(1, 0, 0)
57+
pln = gp_Pln(p0, vnorm)
58+
face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
59+
p1 = gp_Pnt(0, 0, 15)
60+
p2 = gp_Pnt(0, 0, -15)
61+
edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
62+
# Initialize splitter
63+
splitter = GEOMAlgo_Splitter()
64+
# Add the face as an argument and the edge as a tool. This will split
65+
# the face with the edge.
66+
splitter.AddArgument(face)
67+
splitter.AddTool(edge)
68+
splitter.Perform()
69+
display.DisplayShape(splitter.Shape())
70+
display.FitAll()
71+
72+
73+
def split_edge_with_face(event=None):
74+
display.EraseAll()
75+
p0 = gp_Pnt()
76+
vnorm = gp_Dir(1, 0, 0)
77+
pln = gp_Pln(p0, vnorm)
78+
face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
79+
p1 = gp_Pnt(0, 0, 15)
80+
p2 = gp_Pnt(0, 0, -15)
81+
edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
82+
# Initialize splitter
83+
splitter = GEOMAlgo_Splitter()
84+
# Add the edge as an argument and the face as a tool. This will split
85+
# the edge with the face.
86+
splitter.AddArgument(edge)
87+
splitter.AddTool(face)
88+
splitter.Perform()
89+
90+
edges = []
91+
exp = TopExp_Explorer(splitter.Shape(), TopAbs_EDGE)
92+
while exp.More():
93+
edges.append(exp.Current())
94+
exp.Next()
95+
print('Number of edges in split shape: ', len(edges))
96+
display.DisplayShape(edges[0], color='red')
97+
display.DisplayShape(edges[1], color='green')
98+
display.DisplayShape(edges[2], color='yellow')
99+
display.FitAll()
100+
101+
102+
def exit(event=None):
103+
sys.exit()
104+
105+
106+
if __name__ == '__main__':
107+
add_menu('GEOMAlgo Splitter Example')
108+
add_function_to_menu('GEOMAlgo Splitter Example', split_face_and_edge)
109+
add_function_to_menu('GEOMAlgo Splitter Example', split_face_with_edge)
110+
add_function_to_menu('GEOMAlgo Splitter Example', split_edge_with_face)
111+
add_function_to_menu('GEOMAlgo Splitter Example', exit)
112+
start_display()

src/Splitter/GEOMAlgo.i

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
Copyright 2008-2016 Thomas Paviot (tpaviot@gmail.com)
3+
4+
5+
This file is part of pythonOCC.
6+
pythonOCC is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Lesser General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
pythonOCC is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public License
17+
along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
18+
19+
*/
20+
%module (package="OCC") GEOMAlgo
21+
22+
#pragma SWIG nowarn=504,325,503
23+
24+
%{
25+
#ifdef WNT
26+
#pragma warning(disable : 4716)
27+
#endif
28+
%}
29+
30+
%include ../SWIG_files/common/CommonIncludes.i
31+
%include ../SWIG_files/common/ExceptionCatcher.i
32+
%include ../SWIG_files/common/FunctionTransformers.i
33+
%include ../SWIG_files/common/Operators.i
34+
35+
36+
%include GEOMAlgo_headers.i
37+
38+
39+
%pythoncode {
40+
def register_handle(handle, base_object):
41+
"""
42+
Inserts the handle into the base object to
43+
prevent memory corruption in certain cases
44+
"""
45+
try:
46+
if base_object.IsKind("Standard_Transient"):
47+
base_object.thisHandle = handle
48+
base_object.thisown = False
49+
except:
50+
pass
51+
};
52+
53+
/* typedefs */
54+
/* end typedefs declaration */
55+
56+
/* public enums */
57+
/* end public enums declaration */
58+
59+
%nodefaultctor GEOMAlgo_Splitter;
60+
class GEOMAlgo_Splitter : public BOPAlgo_Builder {
61+
public:
62+
%feature("compactdefaultargs") GEOMAlgo_Splitter;
63+
%feature("autodoc", " :rtype: None
64+
") GEOMAlgo_Splitter;
65+
GEOMAlgo_Splitter ();
66+
%feature("compactdefaultargs") GEOMAlgo_Splitter;
67+
%feature("autodoc", " :param theAllocator:
68+
:type theAllocator: Handle_NCollection_BaseAllocator &
69+
:rtype: None
70+
") GEOMAlgo_Splitter;
71+
GEOMAlgo_Splitter (const Handle_NCollection_BaseAllocator & theAllocator);
72+
%feature("compactdefaultargs") AddTool;
73+
%feature("autodoc", " :param theShape:
74+
:type theShape: TopoDS_Shape &
75+
:rtype: None
76+
") AddTool;
77+
void AddTool (const TopoDS_Shape & theShape);
78+
%feature("compactdefaultargs") Tools;
79+
%feature("autodoc", " :rtype: BOPCol_ListOfShape
80+
") Tools;
81+
const BOPCol_ListOfShape & Tools ();
82+
%feature("compactdefaultargs") SetLimit;
83+
%feature("autodoc", " :param aLimit:
84+
:type aLimit: TopAbs_ShapeEnum
85+
:rtype: None
86+
") SetLimit;
87+
void SetLimit (const TopAbs_ShapeEnum aLimit);
88+
%feature("compactdefaultargs") Limit;
89+
%feature("autodoc", " :rtype: TopAbs_ShapeEnum
90+
") Limit;
91+
TopAbs_ShapeEnum Limit ();
92+
%feature("compactdefaultargs") SetLimitMode;
93+
%feature("autodoc", " :param aMode:
94+
:type aMode: int
95+
:rtype: None
96+
") SetLimitMode;
97+
void SetLimitMode (const Standard_Integer aMode);
98+
%feature("compactdefaultargs") LimitMode;
99+
%feature("autodoc", " :rtype: int
100+
") LimitMode;
101+
Standard_Integer LimitMode ();
102+
%feature("compactdefaultargs") Clear;
103+
%feature("autodoc", " :rtype: void
104+
") Clear;
105+
virtual void Clear ();
106+
};
107+
108+
109+
%extend GEOMAlgo_Splitter {
110+
%pythoncode {
111+
__repr__ = _dumps_object
112+
}
113+
};

0 commit comments

Comments
 (0)