-
Notifications
You must be signed in to change notification settings - Fork 14
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
Showing
5 changed files
with
267 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* | ||
Copyright 2013-2024 Onera. | ||
This file is part of Cassiopee. | ||
Cassiopee is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Cassiopee is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Cassiopee. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "occ.h" | ||
#include "TopoDS.hxx" | ||
#include "TopoDS_Shape.hxx" | ||
#include "TopTools_IndexedMapOfShape.hxx" | ||
#include "TopExp.hxx" | ||
#include "TopExp_Explorer.hxx" | ||
#include "BRepPrimAPI_MakeSphere.hxx" | ||
#include "BRep_Builder.hxx" | ||
#include "BRepBuilderAPI_MakeEdge.hxx" | ||
#include "BRepBuilderAPI_MakeWire.hxx" | ||
#include "BRepBuilderAPI_MakeFace.hxx" | ||
|
||
//===================================================================== | ||
// Add a box to CAD hook | ||
//===================================================================== | ||
PyObject* K_OCC::addBox(PyObject* self, PyObject* args) | ||
{ | ||
PyObject* hook; | ||
E_Float x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4; | ||
E_Float x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8; | ||
if (!PYPARSETUPLE_(args, O_ TRRR_ TRRR_ TRRR_ TRRR_ TRRR_ TRRR_ TRRR_ TRRR_, | ||
&hook, | ||
&x1, &y1, &z1, &x2, &y2, &z2, &x3, &y3, &z3, &x4, &y4, &z4, | ||
&x5, &y5, &z5, &x6, &y6, &z6, &x7, &y7, &z7, &x8, &y8, &z8)) return NULL; | ||
|
||
void** packet = NULL; | ||
#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1) | ||
packet = (void**) PyCObject_AsVoidPtr(hook); | ||
#else | ||
packet = (void**) PyCapsule_GetPointer(hook, NULL); | ||
#endif | ||
|
||
//TopoDS_Shape* shp = (TopoDS_Shape*) packet[0]; | ||
TopTools_IndexedMapOfShape& surfaces = *(TopTools_IndexedMapOfShape*)packet[1]; | ||
|
||
/* new square */ | ||
gp_Pnt p1(x1, y1, z1); // Bottom left | ||
gp_Pnt p2(x2, y2, z2); // Bottom right | ||
gp_Pnt p3(x3, y3, z3); // Top right | ||
gp_Pnt p4(x4, y4, z4); // Top left | ||
gp_Pnt p5(x5, y5, z5); // Bottom left | ||
gp_Pnt p6(x6, y6, z6); // Bottom right | ||
gp_Pnt p7(x7, y7, z7); // Top right | ||
gp_Pnt p8(x8, y8, z8); // Top left | ||
|
||
TopoDS_Edge edge1 = BRepBuilderAPI_MakeEdge(p1, p2); | ||
TopoDS_Edge edge2 = BRepBuilderAPI_MakeEdge(p2, p3); | ||
TopoDS_Edge edge3 = BRepBuilderAPI_MakeEdge(p3, p4); | ||
TopoDS_Edge edge4 = BRepBuilderAPI_MakeEdge(p4, p1); | ||
|
||
TopoDS_Wire wire = BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4); | ||
TopoDS_Face face1 = BRepBuilderAPI_MakeFace(wire); | ||
|
||
edge1 = BRepBuilderAPI_MakeEdge(p5, p8); | ||
edge2 = BRepBuilderAPI_MakeEdge(p8, p7); | ||
edge3 = BRepBuilderAPI_MakeEdge(p7, p6); | ||
edge4 = BRepBuilderAPI_MakeEdge(p6, p5); | ||
|
||
wire = BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4); | ||
TopoDS_Face face2 = BRepBuilderAPI_MakeFace(wire); | ||
|
||
edge1 = BRepBuilderAPI_MakeEdge(p1, p4); | ||
edge2 = BRepBuilderAPI_MakeEdge(p4, p8); | ||
edge3 = BRepBuilderAPI_MakeEdge(p8, p5); | ||
edge4 = BRepBuilderAPI_MakeEdge(p5, p1); | ||
|
||
wire = BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4); | ||
TopoDS_Face face3 = BRepBuilderAPI_MakeFace(wire); | ||
|
||
edge1 = BRepBuilderAPI_MakeEdge(p2, p6); | ||
edge2 = BRepBuilderAPI_MakeEdge(p6, p7); | ||
edge3 = BRepBuilderAPI_MakeEdge(p7, p3); | ||
edge4 = BRepBuilderAPI_MakeEdge(p3, p2); | ||
|
||
wire = BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4); | ||
TopoDS_Face face4 = BRepBuilderAPI_MakeFace(wire); | ||
|
||
edge1 = BRepBuilderAPI_MakeEdge(p4, p3); | ||
edge2 = BRepBuilderAPI_MakeEdge(p3, p7); | ||
edge3 = BRepBuilderAPI_MakeEdge(p7, p8); | ||
edge4 = BRepBuilderAPI_MakeEdge(p8, p4); | ||
|
||
wire = BRepBuilderAPI_MakeWire(edge1, edge2, edge3, edge4); | ||
TopoDS_Face face5 = BRepBuilderAPI_MakeFace(wire); | ||
|
||
|
||
|
||
// Rebuild a single compound | ||
BRep_Builder builder; | ||
TopoDS_Compound compound; | ||
builder.MakeCompound(compound); | ||
|
||
for (E_Int i = 1; i <= surfaces.Extent(); i++) | ||
{ | ||
TopoDS_Face F = TopoDS::Face(surfaces(i)); | ||
builder.Add(compound, F); | ||
} | ||
builder.Add(compound, face1); | ||
builder.Add(compound, face2); | ||
builder.Add(compound, face3); | ||
builder.Add(compound, face4); | ||
|
||
TopoDS_Shape* newshp = new TopoDS_Shape(compound); | ||
|
||
// Rebuild the hook | ||
packet[0] = newshp; | ||
// Extract surfaces | ||
TopTools_IndexedMapOfShape* ptr = (TopTools_IndexedMapOfShape*)packet[1]; | ||
delete ptr; | ||
TopTools_IndexedMapOfShape* sf = new TopTools_IndexedMapOfShape(); | ||
TopExp::MapShapes(*newshp, TopAbs_FACE, *sf); | ||
packet[1] = sf; | ||
|
||
// Extract edges | ||
TopTools_IndexedMapOfShape* ptr2 = (TopTools_IndexedMapOfShape*)packet[2]; | ||
delete ptr2; | ||
TopTools_IndexedMapOfShape* se = new TopTools_IndexedMapOfShape(); | ||
TopExp::MapShapes(*newshp, TopAbs_EDGE, *se); | ||
packet[2] = se; | ||
printf("INFO: after addBox: Nb edges=%d\n", se->Extent()); | ||
printf("INFO: after addBox: Nb faces=%d\n", sf->Extent()); | ||
|
||
Py_INCREF(Py_None); | ||
return Py_None; | ||
|
||
} |
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,116 @@ | ||
/* | ||
Copyright 2013-2024 Onera. | ||
This file is part of Cassiopee. | ||
Cassiopee is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Cassiopee is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Cassiopee. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "occ.h" | ||
#include "TopoDS.hxx" | ||
#include "TopoDS_Shape.hxx" | ||
#include "TopTools_IndexedMapOfShape.hxx" | ||
#include "TopExp.hxx" | ||
#include "TopExp_Explorer.hxx" | ||
#include "BRepPrimAPI_MakeSphere.hxx" | ||
#include "BRep_Builder.hxx" | ||
#include "BRepBuilderAPI_MakeEdge.hxx" | ||
#include "BRepBuilderAPI_MakeWire.hxx" | ||
#include "BRepBuilderAPI_MakeFace.hxx" | ||
#include <BRepPrimAPI_MakeCylinder.hxx> | ||
#include <gp_Cylinder.hxx> | ||
#include <gp_Ax2.hxx> | ||
#include <BRepBuilderAPI_MakeFace.hxx> | ||
#include <TopoDS_Shape.hxx> | ||
|
||
//===================================================================== | ||
// Add a part cylinder to CAD hook | ||
//===================================================================== | ||
PyObject* K_OCC::addCylinder(PyObject* self, PyObject* args) | ||
{ | ||
PyObject* hook; | ||
E_Float xc, yc, zc, xaxis, yaxis, zaxis, R, H; | ||
if (!PYPARSETUPLE_(args, O_ TRRR_ TRRR_ R_ R_, | ||
&hook, &xc, &yc, &zc, &xaxis, &yaxis, &zaxis, &R, &H)) return NULL; | ||
|
||
void** packet = NULL; | ||
#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1) | ||
packet = (void**) PyCObject_AsVoidPtr(hook); | ||
#else | ||
packet = (void**) PyCapsule_GetPointer(hook, NULL); | ||
#endif | ||
|
||
//TopoDS_Shape* shp = (TopoDS_Shape*) packet[0]; | ||
TopTools_IndexedMapOfShape& surfaces = *(TopTools_IndexedMapOfShape*)packet[1]; | ||
|
||
// Define the radius, height, and angle of the cylinder | ||
//Standard_Real angle = 2*M_PI; | ||
// Create the cylinder with closing faces | ||
//TopoDS_Shape part = BRepPrimAPI_MakeCylinder(R, H, angle).Shape(); | ||
|
||
// Create only the side of cylinder | ||
gp_Ax2 axis(gp_Pnt(xc, yc, zc), gp_Dir(xaxis, yaxis, zaxis)); // Axis of the cylinder | ||
gp_Cylinder cylinder(axis, R); // Radius of 10.0 | ||
Standard_Real uMin = 0.0; | ||
Standard_Real uMax = 2 * M_PI; // Full circle | ||
Standard_Real vMin = 0.0; | ||
Standard_Real vMax = H; // Height of the cylinder | ||
TopoDS_Face face = BRepBuilderAPI_MakeFace(cylinder, uMin, uMax, vMin, vMax); | ||
|
||
// Rebuild a single compound | ||
BRep_Builder builder; | ||
TopoDS_Compound compound; | ||
builder.MakeCompound(compound); | ||
|
||
for (E_Int i = 1; i <= surfaces.Extent(); i++) | ||
{ | ||
TopoDS_Face F = TopoDS::Face(surfaces(i)); | ||
builder.Add(compound, F); | ||
} | ||
builder.Add(compound, face); | ||
|
||
/* | ||
TopTools_IndexedMapOfShape sf2 = TopTools_IndexedMapOfShape(); | ||
TopExp::MapShapes(part, TopAbs_FACE, sf2); | ||
for (E_Int i = 1; i <= sf2.Extent(); i++) | ||
{ | ||
TopoDS_Face F = TopoDS::Face(sf2(i)); | ||
builder.Add(compound, F); | ||
}*/ | ||
|
||
|
||
TopoDS_Shape* newshp = new TopoDS_Shape(compound); | ||
|
||
// Rebuild the hook | ||
packet[0] = newshp; | ||
// Extract surfaces | ||
TopTools_IndexedMapOfShape* ptr = (TopTools_IndexedMapOfShape*)packet[1]; | ||
delete ptr; | ||
TopTools_IndexedMapOfShape* sf = new TopTools_IndexedMapOfShape(); | ||
TopExp::MapShapes(*newshp, TopAbs_FACE, *sf); | ||
packet[1] = sf; | ||
|
||
// Extract edges | ||
TopTools_IndexedMapOfShape* ptr2 = (TopTools_IndexedMapOfShape*)packet[2]; | ||
delete ptr2; | ||
TopTools_IndexedMapOfShape* se = new TopTools_IndexedMapOfShape(); | ||
TopExp::MapShapes(*newshp, TopAbs_EDGE, *se); | ||
packet[2] = se; | ||
printf("INFO: after addPartCylinder: Nb edges=%d\n", se->Extent()); | ||
printf("INFO: after addPartCylinder: Nb faces=%d\n", sf->Extent()); | ||
|
||
Py_INCREF(Py_None); | ||
return Py_None; | ||
|
||
} |
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
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