diff --git a/Cassiopee/CPlot/apps/tkCADFix.py b/Cassiopee/CPlot/apps/tkCADFix.py index 59b8bffbf..b163af6d6 100644 --- a/Cassiopee/CPlot/apps/tkCADFix.py +++ b/Cassiopee/CPlot/apps/tkCADFix.py @@ -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 = [] diff --git a/Cassiopee/CPlot/apps/tkTetraMesher.py b/Cassiopee/CPlot/apps/tkTetraMesher.py index b07130856..18cfbcda9 100644 --- a/Cassiopee/CPlot/apps/tkTetraMesher.py +++ b/Cassiopee/CPlot/apps/tkTetraMesher.py @@ -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] diff --git a/Cassiopee/OCC/OCC/Atomic/rotate.cpp b/Cassiopee/OCC/OCC/Atomic/rotate.cpp index 1e0865155..5e82348e2 100644 --- a/Cassiopee/OCC/OCC/Atomic/rotate.cpp +++ b/Cassiopee/OCC/OCC/Atomic/rotate.cpp @@ -27,6 +27,7 @@ #include #include #include +#include "BRep_Builder.hxx" //===================================================================== // Rotate the full shape or some faces @@ -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) @@ -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); @@ -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 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; diff --git a/Cassiopee/OCC/OCC/Atomic/scale.cpp b/Cassiopee/OCC/OCC/Atomic/scale.cpp index 8285d47dd..bbcb5345d 100644 --- a/Cassiopee/OCC/OCC/Atomic/scale.cpp +++ b/Cassiopee/OCC/OCC/Atomic/scale.cpp @@ -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 @@ -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) @@ -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 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; diff --git a/Cassiopee/OCC/OCC/Atomic/sewing.cpp b/Cassiopee/OCC/OCC/Atomic/sewing.cpp index f86b85b20..71a635938 100644 --- a/Cassiopee/OCC/OCC/Atomic/sewing.cpp +++ b/Cassiopee/OCC/OCC/Atomic/sewing.cpp @@ -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; @@ -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) { diff --git a/Cassiopee/OCC/OCC/Atomic/translate.cpp b/Cassiopee/OCC/OCC/Atomic/translate.cpp index 3a8bac87b..ae9e3cc44 100644 --- a/Cassiopee/OCC/OCC/Atomic/translate.cpp +++ b/Cassiopee/OCC/OCC/Atomic/translate.cpp @@ -24,6 +24,7 @@ #include "TopTools_IndexedMapOfShape.hxx" #include "TopoDS.hxx" #include "BRepBuilderAPI_Transform.hxx" +#include "BRep_Builder.hxx" //===================================================================== // Translate the full shape or some faces @@ -31,8 +32,8 @@ //===================================================================== 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) @@ -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 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; diff --git a/Cassiopee/OCC/OCC/PyTree.py b/Cassiopee/OCC/OCC/PyTree.py index eef7abfaf..d9a279f55 100644 --- a/Cassiopee/OCC/OCC/PyTree.py +++ b/Cassiopee/OCC/OCC/PyTree.py @@ -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')