diff --git a/Cassiopee/CPlot/apps/tkTransform.py b/Cassiopee/CPlot/apps/tkTransform.py index e159fc4d5..82dbbd2f4 100644 --- a/Cassiopee/CPlot/apps/tkTransform.py +++ b/Cassiopee/CPlot/apps/tkTransform.py @@ -9,6 +9,7 @@ import CPlot.PyTree as CPlot import CPlot.Tk as CTK import KCore.Vector as Vector +import Converter.Internal as Internal import time # local widgets list @@ -115,6 +116,14 @@ def rotate(event=None): noz = CTK.Nz[nz] a = T.rotate(CTK.t[2][nob][2][noz], (X[0],X[1],X[2]), axe, angle) CTK.replace(CTK.t, nob, noz, a) + + # update CAD if necessary + if CTK.CADHOOK is not None: + if len(nzs) == len(Internal.getZones(CTK.t)): + import OCC + print('rotate cad') + OCC.occ.rotate(CTK.CADHOOK, X, axe, angle) + CTK.TXT.insert('START', 'Zones have been rotated.\n') CTK.TKTREE.updateApp() CPlot.render() @@ -157,6 +166,14 @@ def translate(): noz = CTK.Nz[nz] a = T.translate(CTK.t[2][nob][2][noz], (v[0], v[1], v[2])) CTK.replace(CTK.t, nob, noz, a) + + # update CAD if necessary + if CTK.CADHOOK is not None: + if len(nzs) == len(Internal.getZones(CTK.t)): + import OCC + print('translating cad') + OCC.occ.translate(CTK.CADHOOK, (v[0], v[1], v[2])) + CTK.TXT.insert('START', 'Zones have been translated.\n') CTK.TKTREE.updateApp() CPlot.render() @@ -271,6 +288,14 @@ def scale(): z = T.contract(z, (X[0],X[1],X[2]), axe1, axe3, v[1]) a = T.contract(z, (X[0],X[1],X[2]), axe1, axe2, v[2]) CTK.replace(CTK.t, nob, noz, a) + + # update CAD if necessary + if CTK.CADHOOK is not None: + if len(nzs) == len(Internal.getZones(CTK.t)) and len(v) == 1: + import OCC + print('scale cad') + OCC.occ.scale(CTK.CADHOOK, v[0], X) + CTK.TXT.insert('START', 'Zones have been scaled.\n') CTK.TKTREE.updateApp() CPlot.render() @@ -344,9 +369,9 @@ def createApp(win): # - VARS - # -0- Translation vector - - V = TK.StringVar(win); V.set('0;0;0'); VARS.append(V) + V = TK.StringVar(win); V.set('0; 0; 0'); VARS.append(V) # -1- Scale factors - - V = TK.StringVar(win); V.set('1;1;1'); VARS.append(V) + V = TK.StringVar(win); V.set('1; 1; 1'); VARS.append(V) # -2- Rotate axis V = TK.StringVar(win); V.set('around X'); VARS.append(V) # -3- Rotation angle diff --git a/Cassiopee/OCC/OCC/Atomic/mergeCAD.cpp b/Cassiopee/OCC/OCC/Atomic/mergeCAD.cpp new file mode 100644 index 000000000..beedeeb92 --- /dev/null +++ b/Cassiopee/OCC/OCC/Atomic/mergeCAD.cpp @@ -0,0 +1,102 @@ +/* + 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 . +*/ + +#include "occ.h" +#include "TopoDS.hxx" +#include "TopTools_IndexedMapOfShape.hxx" +#include "TopExp.hxx" +#include "TopExp_Explorer.hxx" +#include "BRep_Builder.hxx" + +// ============================================================================ +/* Merge two CAD hooks in a single hook + Caller must dealloc input hooks */ +// ============================================================================ +PyObject* K_OCC::mergeCAD(PyObject* self, PyObject* args) +{ + PyObject* hook1; PyObject* hook2; + if (!PYPARSETUPLE_(args, OO_, &hook1, &hook2)) return NULL; + + void** packet1 = NULL; +#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1) + packet1 = (void**) PyCObject_AsVoidPtr(hook1); +#else + packet1 = (void**) PyCapsule_GetPointer(hook1, NULL); +#endif + TopoDS_Shape* shp1 = (TopoDS_Shape*) packet1[0]; + TopTools_IndexedMapOfShape& surfaces1 = *(TopTools_IndexedMapOfShape*)packet1[1]; + + void** packet2 = NULL; +#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1) + packet2 = (void**) PyCObject_AsVoidPtr(hook2); +#else + packet2 = (void**) PyCapsule_GetPointer(hook2, NULL); +#endif + TopoDS_Shape* shp2 = (TopoDS_Shape*) packet2[0]; + TopTools_IndexedMapOfShape& surfaces2 = *(TopTools_IndexedMapOfShape*)packet2[1]; + + // Rebuild a single compound + BRep_Builder builder; + TopoDS_Compound compound; + builder.MakeCompound(compound); + + for (E_Int i = 1; i <= surfaces1.Extent(); i++) + { + TopoDS_Face F = TopoDS::Face(surfaces1(i)); + builder.Add(compound, F); + } + + for (E_Int i = 1; i <= surfaces2.Extent(); i++) + { + TopoDS_Face F = TopoDS::Face(surfaces2(i)); + builder.Add(compound, F); + } + + TopoDS_Shape* newshp = new TopoDS_Shape(compound); + + // capsule + PyObject* hook; + E_Int sizePacket = 5; + void** packet = new void* [sizePacket]; + packet[0] = newshp; + + // Extract surfaces + TopTools_IndexedMapOfShape* sf = new TopTools_IndexedMapOfShape(); + TopExp::MapShapes(*newshp, TopAbs_FACE, *sf); + packet[1] = sf; + + // Extract edges + TopTools_IndexedMapOfShape* se = new TopTools_IndexedMapOfShape(); + TopExp::MapShapes(*newshp, TopAbs_EDGE, *se); + packet[2] = se; + printf("INFO: after merge: Nb edges=%d\n", se->Extent()); + printf("INFO: after merge: Nb faces=%d\n", sf->Extent()); + +#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1) + hook = PyCObject_FromVoidPtr(packet, NULL); +#else + hook = PyCapsule_New(packet, NULL, NULL); +#endif + + return hook; + + + Py_INCREF(Py_None); + return Py_None; +} \ No newline at end of file diff --git a/Cassiopee/OCC/OCC/Atomic/rotate.cpp b/Cassiopee/OCC/OCC/Atomic/rotate.cpp index 049602aeb..1e0865155 100644 --- a/Cassiopee/OCC/OCC/Atomic/rotate.cpp +++ b/Cassiopee/OCC/OCC/Atomic/rotate.cpp @@ -50,6 +50,8 @@ PyObject* K_OCC::rotate(PyObject* self, PyObject* args) gp_Dir direction(xaxis, yaxis, zaxis); gp_Ax1 axis(center, direction); + //printf("angle=%g\n", angle); + angle = angle * M_PI / 180.; gp_Trsf myTrsf; myTrsf.SetRotation(axis, angle); diff --git a/Cassiopee/OCC/OCC/Atomic/trim.cpp b/Cassiopee/OCC/OCC/Atomic/trim.cpp index 74582c259..abe646775 100644 --- a/Cassiopee/OCC/OCC/Atomic/trim.cpp +++ b/Cassiopee/OCC/OCC/Atomic/trim.cpp @@ -22,7 +22,6 @@ #include "ShapeFix_Shape.hxx" #include "ShapeFix_Wireframe.hxx" #include "BRepBuilderAPI_MakeWire.hxx" -#include "ShapeUpgrade_UnifySameDomain.hxx" #include "BRepFeat_SplitShape.hxx" #include "BRep_Builder.hxx" #include "TopExp.hxx" diff --git a/Cassiopee/OCC/OCC/occ.cpp b/Cassiopee/OCC/OCC/occ.cpp index 6b9c248e5..d3d8fad5a 100644 --- a/Cassiopee/OCC/OCC/occ.cpp +++ b/Cassiopee/OCC/OCC/occ.cpp @@ -31,6 +31,7 @@ static PyMethodDef Pyocc [] = {"readCAD", K_OCC::readCAD, METH_VARARGS}, {"writeCAD", K_OCC::writeCAD, METH_VARARGS}, {"createEmptyCAD", K_OCC::createEmptyCAD, METH_VARARGS}, + {"mergeCAD", K_OCC::mergeCAD, METH_VARARGS}, {"freeHook", K_OCC::freeHook, METH_VARARGS}, {"bottle", K_OCC::bottle, METH_VARARGS}, diff --git a/Cassiopee/OCC/OCC/occ.h b/Cassiopee/OCC/OCC/occ.h index af2287971..54f15c80b 100644 --- a/Cassiopee/OCC/OCC/occ.h +++ b/Cassiopee/OCC/OCC/occ.h @@ -30,6 +30,7 @@ namespace K_OCC PyObject* readCAD(PyObject* self, PyObject* args); PyObject* writeCAD(PyObject* self, PyObject* args); PyObject* createEmptyCAD(PyObject* self, PyObject* args); + PyObject* mergeCAD(PyObject* self, PyObject* args); PyObject* freeHook(PyObject* self, PyObject* args); PyObject* bottle(PyObject* self, PyObject* args); diff --git a/Cassiopee/OCC/srcs.py b/Cassiopee/OCC/srcs.py index ac745c713..be2e896d5 100644 --- a/Cassiopee/OCC/srcs.py +++ b/Cassiopee/OCC/srcs.py @@ -36,6 +36,7 @@ def getFiles(module): 'OCC/Atomic/readCAD.cpp', 'OCC/Atomic/writeCAD.cpp', 'OCC/Atomic/createEmptyCAD.cpp', + 'OCC/Atomic/mergeCAD.cpp', 'OCC/Atomic/freeHook.cpp', 'OCC/Atomic/bottle.cpp',