Skip to content

Commit

Permalink
OCC: printOCAF
Browse files Browse the repository at this point in the history
  • Loading branch information
benoit128 committed Dec 14, 2024
1 parent ff3425c commit d3f8282
Show file tree
Hide file tree
Showing 13 changed files with 192 additions and 32 deletions.
8 changes: 4 additions & 4 deletions Cassiopee/Generator/Generator/Fortran/MetsF.for
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ c
xm11(1,2) = xxi*yxi
xm11(2,2) = yxi*yxi
c
xm12(1,1) = 2.*xxi*xet
xm12(1,1) = 2.D0*xxi*xet
xm12(1,2) = xxi*yet+yxi*xet
xm12(2,2) = 2.*yxi*yet
xm12(2,2) = 2.D0*yxi*yet
c
xm22(1,1) = xet*xet
xm22(1,2) = xet*yet
Expand Down Expand Up @@ -111,13 +111,13 @@ c
REAL_E a11, a12, a22
REAL_E s11, s12, s22
c
s11 = 2.*p11p11 + 2.*p11prg*g22/rg + prgprg*g22*g22/g/2.
s11 = 2.D0*p11p11 + 2.*p11prg*g22/rg + prgprg*g22*g22/g/2.
s12 = p11p12 - p11prg*g12/rg + p12prg*g22/rg/2. -
$ prgprg*g12*g22/g/2.
s22 = p12p12/2. - p12prg*g12/rg + prgprg*g12*g12/g/2.
c
a11 = p11 + s11*xm11(1,1) + s12*xm12(1,1) + s22*xm22(1,1)
a12 = s11*xm11(1,2) + s12*xm12(1,2) + s22*xm22(1,2)
a12 = s11*xm11(1,2) + s12*xm12(1,2) + s22*xm22(1,2)
a22 = p11 + s11*xm11(2,2) + s12*xm12(2,2) + s22*xm22(2,2)
c
RETURN
Expand Down
1 change: 0 additions & 1 deletion Cassiopee/Generator/Generator/Fortran/SolbtF.for
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,3 @@ C BACKWARD SOLUTION SWEEP.
RETURN
END
C
C
12 changes: 6 additions & 6 deletions Cassiopee/Generator/Generator/Fortran/Sor9ptF.for
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ c
omg = 0.01D0
dx = 1.D0/n
dy = 1.D0/m
tdx = 2.*dx
tdy = 2.*dy
tdx = 2.D0*dx
tdy = 2.D0*dy
dxx = dx*dx
dxy = 4.*dx*dy
dxy = 4.D0*dx*dy
dyy = dy*dy

xerr = 0.D0
Expand All @@ -40,9 +40,9 @@ c
do j = 2, m-1
do i = 2, n-1
c
cf11 = 2.*( a11(i,j)/dxx + c11(i,j)/dyy )
cf12 = 2.*( a12(i,j)/dxx + c12(i,j)/dyy )
cf22 = 2.*( a22(i,j)/dxx + c22(i,j)/dyy )
cf11 = 2.D0*( a11(i,j)/dxx + c11(i,j)/dyy )
cf12 = 2.D0*( a12(i,j)/dxx + c12(i,j)/dyy )
cf22 = 2.D0*( a22(i,j)/dxx + c22(i,j)/dyy )
c
x12 = ( x(i+1,j+1) - x(i+1,j-1) - x(i-1,j+1) + x(i-1,j-1) )/
$ dxy
Expand Down
2 changes: 1 addition & 1 deletion Cassiopee/OCC/OCC/Atomic/addLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ PyObject* K_OCC::addLabel(PyObject* self, PyObject* args)
{
TopoDS_Shape face = exp.Current();
TDF_Label label;
if (shapeTool->FindShape(face, label))
if (shapeTool->FindShape(face, label))
{
// Do something with the label
}
Expand Down
5 changes: 3 additions & 2 deletions Cassiopee/OCC/OCC/Atomic/createEmptyCAD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ PyObject* K_OCC::createEmptyCAD(PyObject* self, PyObject* args)

// capsule
PyObject* hook;
E_Int sizePacket = 5;
E_Int sizePacket = 6;
void** packet = new void* [sizePacket];
packet[0] = shp; // the top shape
packet[1] = surfs; // the face map
packet[2] = edges; // the edge map
packet[3] = fileNameC; // CAD file name
packet[4] = fileFmtC; // CAD file format

packet[5] = NULL; // document

#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1)
hook = PyCObject_FromVoidPtr(packet, NULL);
#else
Expand Down
7 changes: 5 additions & 2 deletions Cassiopee/OCC/OCC/Atomic/freeHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "TopTools_IndexedMapOfShape.hxx"
#include "BRepBuilderAPI_MakeFace.hxx"
#include "BRep_Builder.hxx"

#include "TDocStd_Document.hxx"

//=====================================================================
// Split shape by max area
Expand All @@ -52,18 +52,21 @@ PyObject* K_OCC::freeHook(PyObject* self, PyObject* args)
TopoDS_Shape* shp = (TopoDS_Shape*)packet[0];
char* fileName = (char*)packet[3];
char* fileFmt = (char*)packet[4];

TDocStd_Document* doc = (TDocStd_Document*)packet[5];

delete shp;
delete edges;
delete surfaces;
delete [] fileName;
delete [] fileFmt;
//delete doc; // can i free it? not sure

packet[0] = NULL;
packet[1] = NULL;
packet[2] = NULL;
packet[3] = NULL;
packet[4] = NULL;
packet[5] = NULL;

Py_INCREF(Py_None);
return Py_None;
Expand Down
5 changes: 4 additions & 1 deletion Cassiopee/OCC/OCC/Atomic/mergeCAD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "TopExp.hxx"
#include "TopExp_Explorer.hxx"
#include "BRep_Builder.hxx"
#include "TDocStd_Document.hxx"

// ============================================================================
/* Merge two CAD hooks in a single hook
Expand Down Expand Up @@ -72,7 +73,7 @@ PyObject* K_OCC::mergeCAD(PyObject* self, PyObject* args)

// capsule
PyObject* hook;
E_Int sizePacket = 5;
E_Int sizePacket = 6;
void** packet = new void* [sizePacket];
packet[0] = newshp;

Expand All @@ -99,6 +100,8 @@ PyObject* K_OCC::mergeCAD(PyObject* self, PyObject* args)
char* fileFmtC = new char [l+1];
strcpy(fileFmtC, fileFmt);
packet[4] = fileFmtC;
TDocStd_Document* doc = (TDocStd_Document*)packet2[5]; // todo: must merge document
packet[5] = doc;

#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1)
hook = PyCObject_FromVoidPtr(packet, NULL);
Expand Down
1 change: 0 additions & 1 deletion Cassiopee/OCC/OCC/Atomic/meshEdge2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,6 @@ E_Int __getParamHminHmaxHausdF5(const TopoDS_Edge& E, E_Float hmin, E_Float hmax
}
}


// smooth hi
/*
for (E_Int i = 0; i < N-1; i++)
Expand Down
137 changes: 137 additions & 0 deletions Cassiopee/OCC/OCC/Atomic/printOCAF.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
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 "STEPCAFControl_Reader.hxx"
#include "TDF_Label.hxx"
#include "TDF_LabelSequence.hxx"
#include "TDF_Tool.hxx"
#include "XCAFDoc_ShapeTool.hxx"
#include "XCAFDoc_DocumentTool.hxx"
#include "TDocStd_Document.hxx"
#include "TDataStd_Name.hxx"
#include "TDF_ChildIterator.hxx"

// recursive iteration through labels
void iterateLabels(const TDF_Label& label)
{
// print label entry
TCollection_AsciiString es;
TDF_Tool::Entry(label, es); // retourne l'entry de la label (3:0:3 indiquant sa position dans la hierarchie)
cout << "Info: Label entry: " << es.ToCString() << endl;

// Print the label string attributes
Handle(TDataStd_Name) nameAttr;
if (label.FindAttribute(TDataStd_Name::GetID(), nameAttr))
{
TCollection_ExtendedString name = nameAttr->Get();
std::cout << "Info: Label string: " << name << std::endl;
}

// Iterate through child labels
for (TDF_ChildIterator it(label); it.More(); it.Next())
{
iterateLabels(it.Value());
}
}

//=====================================================================
// print all printable OCAF labels
//=====================================================================
PyObject* K_OCC::printOCAF(PyObject* self, PyObject* args)
{
PyObject* hook;
if (!PYPARSETUPLE_(args, O_, &hook)) 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

TDocStd_Document* doc = (TDocStd_Document*)packet[5];
if (doc == NULL)
{
PyErr_SetString(PyExc_TypeError, "printOCAF: no OCAF document.");
return NULL;
}

// parcours recursivement toutes les labels du document
iterateLabels(doc->Main());

Py_INCREF(Py_None);
return Py_None;
}

//=====================================================================
// print shape printable OCAF labels
//=====================================================================
PyObject* K_OCC::printShapeOCAF(PyObject* self, PyObject* args)
{
PyObject* hook;
if (!PYPARSETUPLE_(args, O_, &hook)) 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

TDocStd_Document* doc = (TDocStd_Document*)packet[5];
if (doc == NULL)
{
PyErr_SetString(PyExc_TypeError, "printOCAF: no OCAF document.");
return NULL;
}

//============================================================
// Retourne une collection de labels correspondants aux shapes
//============================================================
TDF_LabelSequence labels;
Handle(XCAFDoc_ShapeTool) shapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
shapeTool->GetFreeShapes(labels);

for (Standard_Integer i = 1; i <= labels.Length(); i++)
{
TDF_Label label = labels.Value(i); // one label of collection

TCollection_AsciiString es;
TDF_Tool::Entry(label, es); // retourne l'entry de la label (3:0:3 indiquant sa position dans la hierarchie)
cout << "Info: Label entry: " << es.ToCString() << endl;

Handle(TDataStd_Name) NAME = new TDataStd_Name();
if (label.FindAttribute(TDataStd_Name::GetID(), NAME)) // retourne tous les attributs de type string
{
printf("has string attribute\n");
TCollection_ExtendedString labelName = NAME->Get();
std::cout << "Info: Label name: " << labelName << std::endl;
}
else
{ printf("no string attribute\n"); }
}

Py_INCREF(Py_None);
return Py_None;
}




38 changes: 24 additions & 14 deletions Cassiopee/OCC/OCC/Atomic/readCAD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@
#include "IGESControl_Reader.hxx"
#include "STEPControl_Reader.hxx"

//Data structure
#include "TColStd_HSequenceOfTransient.hxx"
// Data structure
#include "TopoDS.hxx"
#include "TopTools_IndexedMapOfShape.hxx"
#include "TopExp.hxx"
#include "TopExp_Explorer.hxx"

// Document
#include "IGESCAFControl_Reader.hxx"
#include "STEPCAFControl_Reader.hxx"
#include "XCAFDoc_DocumentTool.hxx"
#include "TDocStd_Document.hxx"

// ============================================================================
/* Convert CAD to OpenCascade hook */
// ============================================================================
Expand All @@ -39,6 +44,8 @@ PyObject* K_OCC::readCAD(PyObject* self, PyObject* args)

TopoDS_Shape* shp = new TopoDS_Shape();

Handle(TDocStd_Document) doc = NULL;

if (strcmp(fileFmt, "fmt_iges") == 0)
{
IGESControl_Reader reader;
Expand All @@ -50,6 +57,12 @@ PyObject* K_OCC::readCAD(PyObject* self, PyObject* args)

// get shape
*shp = reader.OneShape();

// Read document
IGESCAFControl_Reader reader2;
reader2.ReadFile(fileName);
doc = new TDocStd_Document("MDTV-Standard");
reader2.Transfer(doc);
}
else if (strcmp(fileFmt, "fmt_step") == 0)
{
Expand All @@ -58,16 +71,12 @@ PyObject* K_OCC::readCAD(PyObject* self, PyObject* args)
reader.ReadFile(fileName);
reader.TransferRoots();
*shp = reader.OneShape();

// tentative pour recuperer les noms des entites
//#include "XSControl_WorkSession.hxx"
//#include "XSControl_TransferReader.hxx"
//#include "Standard_Transient.hxx"
//Handle(XSControl_WorkSession) ws = reader.WS();
//Handle(XSControl_TransferReader) tr = ws.TransferReader();
//Handle(Standard_Transient) item = tr.EntityFromShapeResult(aShape);
//char* name = item.Name().ToCString();
//print("name=%s\n", name);

// Read document
STEPCAFControl_Reader reader2;
reader2.ReadFile(fileName);
doc = new TDocStd_Document("MDTV-Standard");
reader2.Transfer(doc);
}

// Extract surfaces
Expand Down Expand Up @@ -98,14 +107,15 @@ PyObject* K_OCC::readCAD(PyObject* self, PyObject* args)

// capsule
PyObject* hook;
E_Int sizePacket = 5;
E_Int sizePacket = 6;
void** packet = new void* [sizePacket];
packet[0] = shp; // the top shape
packet[1] = surfs; // the face map
packet[2] = edges; // the edge map
packet[3] = fileNameC; // CAD file name
packet[4] = fileFmtC; // CAD file format

packet[5] = doc; // OCAF document

#if (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 7) || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 1)
hook = PyCObject_FromVoidPtr(packet, NULL);
#else
Expand Down
3 changes: 3 additions & 0 deletions Cassiopee/OCC/OCC/occ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ static PyMethodDef Pyocc [] =
{"mergeCAD", K_OCC::mergeCAD, METH_VARARGS},
{"freeHook", K_OCC::freeHook, METH_VARARGS},

{"printOCAF", K_OCC::printOCAF, METH_VARARGS},
{"printShapeOCAF", K_OCC::printShapeOCAF, METH_VARARGS},

{"bottle", K_OCC::bottle, METH_VARARGS},
{"addSphere", K_OCC::addSphere, METH_VARARGS},
{"addSquare", K_OCC::addSquare, METH_VARARGS},
Expand Down
3 changes: 3 additions & 0 deletions Cassiopee/OCC/OCC/occ.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ namespace K_OCC
PyObject* mergeCAD(PyObject* self, PyObject* args);
PyObject* freeHook(PyObject* self, PyObject* args);

PyObject* printOCAF(PyObject* self, PyObject* args);
PyObject* printShapeOCAF(PyObject* self, PyObject* args);

PyObject* bottle(PyObject* self, PyObject* args);
PyObject* addSphere(PyObject* self, PyObject* args);
PyObject* addSquare(PyObject* self, PyObject* args);
Expand Down
Loading

0 comments on commit d3f8282

Please sign in to comment.