Skip to content

Commit

Permalink
OCC: add listFace to rotate,translate,...
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Dec 18, 2024
1 parent 2c268be commit 3de5f13
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cassiopee/CPlot/apps/tkCADFix.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def removeFaces(event=None):
import OCC.PyTree as OCC
if CTK.CADHOOK is None: return
hook = CTK.CADHOOK
[hmin, hmax, hausd] = OCC.getCADcontainer(CTK.t)
#[hmin, hmax, hausd] = OCC.getCADcontainer(CTK.t)
# Get selected faces
nzs = CPlot.getSelectedZones()
faces = []
Expand Down
2 changes: 1 addition & 1 deletion Cassiopee/CPlot/apps/tkTetraMesher.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def displayFrameMenu(event=None):
WIDGETS['frameMenu'].tk_popup(event.x_root+50, event.y_root, 0)

#==============================================================================
if (__name__ == "__main__"):
if __name__ == "__main__":
import sys
if len(sys.argv) == 2:
CTK.FILE = sys.argv[1]
Expand Down
61 changes: 57 additions & 4 deletions Cassiopee/OCC/OCC/Atomic/rotate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <gp_Ax1.hxx>
#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include "BRep_Builder.hxx"

//=====================================================================
// Rotate the full shape or some faces
Expand All @@ -35,7 +36,9 @@
PyObject* K_OCC::rotate(PyObject* self, PyObject* args)
{
PyObject* hook; E_Float angle; E_Float xc, yc, zc; E_Float xaxis, yaxis, zaxis;
if (!PYPARSETUPLE_(args, O_ TRRR_ TRRR_ R_, &hook, &xc, &yc, &zc, &xaxis, &yaxis, &zaxis, &angle)) return NULL;
PyObject* listFaces;
if (!PYPARSETUPLE_(args, O_ TRRR_ TRRR_ R_ O_, &hook, &xc, &yc, &zc,
&xaxis, &yaxis, &zaxis, &angle, &listFaces)) return NULL;

void** packet = NULL;
#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1)
Expand All @@ -45,6 +48,7 @@ PyObject* K_OCC::rotate(PyObject* self, PyObject* args)
#endif

TopoDS_Shape* shp = (TopoDS_Shape*)packet[0];
TopTools_IndexedMapOfShape& surfaces = *(TopTools_IndexedMapOfShape*)packet[1];

gp_Pnt center(xc, yc, zc);
gp_Dir direction(xaxis, yaxis, zaxis);
Expand All @@ -55,11 +59,60 @@ PyObject* K_OCC::rotate(PyObject* self, PyObject* args)
gp_Trsf myTrsf;
myTrsf.SetRotation(axis, angle);

BRepBuilderAPI_Transform myTransform(*shp, myTrsf);
TopoDS_Shape tShape = myTransform.Shape();

E_Int nfaces = PyList_Size(listFaces);

TopoDS_Shape* newshp = new TopoDS_Shape();
*newshp = tShape;

if (nfaces == 0) // on all shape
{
BRepBuilderAPI_Transform myTransform(*shp, myTrsf);
TopoDS_Shape tShape = myTransform.Shape();
*newshp = tShape;
}
else
{
// Build a compound
BRep_Builder builder;
TopoDS_Compound shc;
builder.MakeCompound(shc);
E_Int nf = surfaces.Extent();
std::vector<E_Int> nos(nf);
for (E_Int i = 0; i < nf; i++) nos[i] = -1;

for (E_Int no = 0; no < nfaces; no++)
{
PyObject* noFaceO = PyList_GetItem(listFaces, no);
E_Int noFace = PyInt_AsLong(noFaceO);
nos[noFace-1] = no;
const TopoDS_Face& F = TopoDS::Face(surfaces(noFace));
builder.Add(shc, F);
}
BRepBuilderAPI_Transform myTransform(shc, myTrsf);
TopoDS_Shape tShape = myTransform.Shape();

// Rebuild
TopTools_IndexedMapOfShape surfaces2;
TopExp::MapShapes(tShape, TopAbs_FACE, surfaces2);

BRep_Builder builder2;
TopoDS_Compound shc2;
builder2.MakeCompound(shc2);
for (E_Int i = 0; i < nf; i++)
{
if (nos[i] == -1)
{
const TopoDS_Face& F = TopoDS::Face(surfaces(i+1));
builder2.Add(shc2, F);
}
else
{
const TopoDS_Face& F = TopoDS::Face(surfaces2(nos[i]+1));
builder2.Add(shc2, F);
}
}
*newshp = shc2;
}

// Rebuild the hook
packet[0] = newshp;
Expand Down
61 changes: 56 additions & 5 deletions Cassiopee/OCC/OCC/Atomic/scale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "TopTools_IndexedMapOfShape.hxx"
#include "TopoDS.hxx"
#include "BRepBuilderAPI_Transform.hxx"
#include "BRep_Builder.hxx"

//=====================================================================
// scale the full shape or some faces
Expand All @@ -32,8 +33,9 @@
PyObject* K_OCC::scale(PyObject* self, PyObject* args)
{
PyObject* hook; E_Float factor; E_Float x0, y0, z0;
if (!PYPARSETUPLE_(args, O_ R_ TRRR_, &hook, &factor,
&x0, &y0, &z0)) return NULL;
PyObject* listFaces;
if (!PYPARSETUPLE_(args, O_ R_ TRRR_ O_, &hook, &factor,
&x0, &y0, &z0, &listFaces)) return NULL;

void** packet = NULL;
#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1)
Expand All @@ -43,16 +45,65 @@ PyObject* K_OCC::scale(PyObject* self, PyObject* args)
#endif

TopoDS_Shape* shp = (TopoDS_Shape*)packet[0];
TopTools_IndexedMapOfShape& surfaces = *(TopTools_IndexedMapOfShape*)packet[1];

// idem scale
gp_Trsf myTrsf;
myTrsf.SetScale(gp_Pnt(x0, y0, z0), factor);

BRepBuilderAPI_Transform myTransform(*shp, myTrsf);
TopoDS_Shape tShape = myTransform.Shape();
E_Int nfaces = PyList_Size(listFaces);

TopoDS_Shape* newshp = new TopoDS_Shape();
*newshp = tShape;

if (nfaces == 0) // on all shape
{
BRepBuilderAPI_Transform myTransform(*shp, myTrsf);
TopoDS_Shape tShape = myTransform.Shape();
*newshp = tShape;
}
else
{
// Build a compound
BRep_Builder builder;
TopoDS_Compound shc;
builder.MakeCompound(shc);
E_Int nf = surfaces.Extent();
std::vector<E_Int> nos(nf);
for (E_Int i = 0; i < nf; i++) nos[i] = -1;

for (E_Int no = 0; no < nfaces; no++)
{
PyObject* noFaceO = PyList_GetItem(listFaces, no);
E_Int noFace = PyInt_AsLong(noFaceO);
nos[noFace-1] = no;
const TopoDS_Face& F = TopoDS::Face(surfaces(noFace));
builder.Add(shc, F);
}
BRepBuilderAPI_Transform myTransform(shc, myTrsf);
TopoDS_Shape tShape = myTransform.Shape();

// Rebuild
TopTools_IndexedMapOfShape surfaces2;
TopExp::MapShapes(tShape, TopAbs_FACE, surfaces2);

BRep_Builder builder2;
TopoDS_Compound shc2;
builder2.MakeCompound(shc2);
for (E_Int i = 0; i < nf; i++)
{
if (nos[i] == -1)
{
const TopoDS_Face& F = TopoDS::Face(surfaces(i+1));
builder2.Add(shc2, F);
}
else
{
const TopoDS_Face& F = TopoDS::Face(surfaces2(nos[i]+1));
builder2.Add(shc2, F);
}
}
*newshp = shc2;
}

// Rebuild the hook
packet[0] = newshp;
Expand Down
4 changes: 2 additions & 2 deletions Cassiopee/OCC/OCC/Atomic/sewing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
//=====================================================================
PyObject* K_OCC::sewing(PyObject* self, PyObject* args)
{
PyObject* hook; PyObject* listFaces; E_Float tol;
PyObject* hook; PyObject* listFaces; E_Float tol;
if (!PYPARSETUPLE_(args, OO_ R_, &hook, &listFaces, &tol)) return NULL;

void** packet = NULL;
Expand All @@ -61,7 +61,7 @@ PyObject* K_OCC::sewing(PyObject* self, PyObject* args)
BRepBuilderAPI_Sewing sewer(tolerance);

TopoDS_Shape* newshp = NULL;
E_Int nfaces = PyList_Size(listFaces);
E_Int nfaces = PyList_Size(listFaces);
//nfaces = 0; // force car le code par subfaces semble ne pas marcher
if (nfaces == 0)
{
Expand Down
66 changes: 56 additions & 10 deletions Cassiopee/OCC/OCC/Atomic/translate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
#include "TopTools_IndexedMapOfShape.hxx"
#include "TopoDS.hxx"
#include "BRepBuilderAPI_Transform.hxx"
#include "BRep_Builder.hxx"

//=====================================================================
// Translate the full shape or some faces
// from vector
//=====================================================================
PyObject* K_OCC::translate(PyObject* self, PyObject* args)
{
PyObject* hook; E_Float dx, dy, dz;
if (!PYPARSETUPLE_(args, O_ TRRR_, &hook, &dx, &dy, &dz)) return NULL;
PyObject* hook; E_Float dx, dy, dz; PyObject* listFaces;
if (!PYPARSETUPLE_(args, O_ TRRR_ O_, &hook, &dx, &dy, &dz, &listFaces)) return NULL;

void** packet = NULL;
#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1)
Expand All @@ -42,19 +43,64 @@ PyObject* K_OCC::translate(PyObject* self, PyObject* args)
#endif

TopoDS_Shape* shp = (TopoDS_Shape*)packet[0];

// idem scale
//gp_Trsf myTrsf;
//myTrsf.SetScale(gp_Pnt(0, 0, 0), scaleFactor); // Scale around the origin by 'scaleFactor'

TopTools_IndexedMapOfShape& surfaces = *(TopTools_IndexedMapOfShape*)packet[1];

gp_Trsf myTrsf;
myTrsf.SetTranslation(gp_Vec(dx, dy, dz)); // Translate by (dx, dy, dz)

BRepBuilderAPI_Transform myTransform(*shp, myTrsf);
TopoDS_Shape tShape = myTransform.Shape();
E_Int nfaces = PyList_Size(listFaces);

TopoDS_Shape* newshp = new TopoDS_Shape();
*newshp = tShape;

if (nfaces == 0) // on all shape
{
BRepBuilderAPI_Transform myTransform(*shp, myTrsf);
TopoDS_Shape tShape = myTransform.Shape();
*newshp = tShape;
}
else // on face list
{
// Build a compound
BRep_Builder builder;
TopoDS_Compound shc;
builder.MakeCompound(shc);
E_Int nf = surfaces.Extent();
std::vector<E_Int> nos(nf);
for (E_Int i = 0; i < nf; i++) nos[i] = -1;

for (E_Int no = 0; no < nfaces; no++)
{
PyObject* noFaceO = PyList_GetItem(listFaces, no);
E_Int noFace = PyInt_AsLong(noFaceO);
nos[noFace-1] = no;
const TopoDS_Face& F = TopoDS::Face(surfaces(noFace));
builder.Add(shc, F);
}
BRepBuilderAPI_Transform myTransform(shc, myTrsf);
TopoDS_Shape tShape = myTransform.Shape();

// Rebuild
TopTools_IndexedMapOfShape surfaces2;
TopExp::MapShapes(tShape, TopAbs_FACE, surfaces2);

BRep_Builder builder2;
TopoDS_Compound shc2;
builder2.MakeCompound(shc2);
for (E_Int i = 0; i < nf; i++)
{
if (nos[i] == -1)
{
const TopoDS_Face& F = TopoDS::Face(surfaces(i+1));
builder2.Add(shc2, F);
}
else
{
const TopoDS_Face& F = TopoDS::Face(surfaces2(nos[i]+1));
builder2.Add(shc2, F);
}
}
*newshp = shc2;
}

// Rebuild the hook
packet[0] = newshp;
Expand Down
2 changes: 1 addition & 1 deletion Cassiopee/OCC/OCC/PyTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def _setLonelyEdgesColor(t):
CPlot._addRender2Zone(ze, color='Green')
elif size == 1: # lonely: red
L = D.getLength(ze)
if L > 1.e-16: CPlot._addRender2Zone(ze, color='Red')
if L > 1.e-11: CPlot._addRender2Zone(ze, color='Red')
else: CPlot._addRender2Zone(ze, color='Green')
else: # strange!!
CPlot._addRender2Zone(ze, color='Green')
Expand Down

0 comments on commit 3de5f13

Please sign in to comment.