gmio_support: make OCC support more C-ish

This commit is contained in:
Hugues Delorme 2015-09-09 10:54:45 +02:00
parent 4c3976d91d
commit 409e590f28
4 changed files with 62 additions and 54 deletions

View File

@ -68,7 +68,7 @@ Handle_StlMesh_Mesh stlMesh;
static void bmk_stl_read(const char* filepath) static void bmk_stl_read(const char* filepath)
{ {
stlMesh = new StlMesh_Mesh; stlMesh = new StlMesh_Mesh;
gmio_stl_mesh_creator_t mesh_creator = gmio_stl_occmesh_creator(stlMesh); gmio_stl_mesh_creator_t mesh_creator = gmio_stl_hnd_occmesh_creator(stlMesh);
int error = gmio_stl_read_file(filepath, &mesh_creator, NULL); int error = gmio_stl_read_file(filepath, &mesh_creator, NULL);
if (error != GMIO_ERROR_OK) if (error != GMIO_ERROR_OK)
printf("gmio error: 0x%X\n", error); printf("gmio error: 0x%X\n", error);
@ -76,8 +76,8 @@ static void bmk_stl_read(const char* filepath)
static void bmk_stl_write(const char* filepath, gmio_stl_format_t format) static void bmk_stl_write(const char* filepath, gmio_stl_format_t format)
{ {
const gmio_OccStlMeshDomain occMeshDomain(stlMesh); const gmio_occ_stl_mesh_domain_t occ_mesh_domain(stlMesh);
const gmio_stl_mesh_t mesh = gmio_stl_occmesh(occMeshDomain); const gmio_stl_mesh_t mesh = gmio_stl_occmesh(&occ_mesh_domain);
gmio_stl_write_options_t opts = { 0 }; gmio_stl_write_options_t opts = { 0 };
opts.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE; opts.stla_float32_format = GMIO_FLOAT_TEXT_FORMAT_SHORTEST_UPPERCASE;

View File

@ -46,10 +46,10 @@ static void occmesh_add_triangle(void* cookie,
static void occmesh_get_triangle( static void occmesh_get_triangle(
const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle) const void* cookie, uint32_t tri_id, gmio_stl_triangle_t* triangle)
{ {
const gmio_OccStlMeshDomain* meshCookie = const gmio_occ_stl_mesh_domain_t* mesh_domain =
static_cast<const gmio_OccStlMeshDomain*>(cookie); static_cast<const gmio_occ_stl_mesh_domain_t*>(cookie);
const StlMesh_SequenceOfMeshTriangle& occTriangles = const StlMesh_SequenceOfMeshTriangle& occTriangles =
meshCookie->mesh()->Triangles(meshCookie->domainId()); mesh_domain->mesh->Triangles(mesh_domain->domain_id);
const Handle_StlMesh_MeshTriangle& occTri = const Handle_StlMesh_MeshTriangle& occTri =
occTriangles.Value(tri_id + 1); occTriangles.Value(tri_id + 1);
int v1; int v1;
@ -64,7 +64,7 @@ static void occmesh_get_triangle(
triangle->normal.z = float(zN); triangle->normal.z = float(zN);
const TColgp_SequenceOfXYZ& vertices = const TColgp_SequenceOfXYZ& vertices =
meshCookie->mesh()->Vertices(meshCookie->domainId()); mesh_domain->mesh->Vertices(mesh_domain->domain_id);
const gp_XYZ& coordsV1 = vertices.Value(v1); const gp_XYZ& coordsV1 = vertices.Value(v1);
const gp_XYZ& coordsV2 = vertices.Value(v2); const gp_XYZ& coordsV2 = vertices.Value(v2);
const gp_XYZ& coordsV3 = vertices.Value(v3); const gp_XYZ& coordsV3 = vertices.Value(v3);
@ -83,46 +83,48 @@ static void occmesh_get_triangle(
} // namespace internal } // namespace internal
gmio_stl_mesh gmio_stl_occmesh(const gmio_OccStlMeshDomain &meshCookie) gmio_stl_mesh_t gmio_stl_occmesh(const gmio_occ_stl_mesh_domain_t* mesh_domain)
{ {
gmio_stl_mesh mesh = { 0 }; gmio_stl_mesh_t mesh = { 0 };
mesh.cookie = &meshCookie; mesh.cookie = mesh_domain;
mesh.triangle_count = meshCookie.mesh()->NbTriangles(meshCookie.domainId()); if (mesh_domain != NULL && mesh_domain->mesh != NULL) {
mesh.triangle_count =
mesh_domain->mesh->NbTriangles(mesh_domain->domain_id);
}
mesh.func_get_triangle = internal::occmesh_get_triangle; mesh.func_get_triangle = internal::occmesh_get_triangle;
return mesh; return mesh;
} }
gmio_stl_mesh_creator gmio_stl_occmesh_creator(const Handle_StlMesh_Mesh &mesh) gmio_stl_mesh_creator_t gmio_stl_occmesh_creator(StlMesh_Mesh* mesh)
{ {
gmio_stl_mesh_creator creator = { 0 }; gmio_stl_mesh_creator_t creator = { 0 };
creator.cookie = internal::occMeshPtr(mesh); creator.cookie = mesh;
creator.func_add_triangle = internal::occmesh_add_triangle; creator.func_add_triangle = internal::occmesh_add_triangle;
return creator; return creator;
} }
gmio_OccStlMeshDomain::gmio_OccStlMeshDomain( gmio_stl_mesh_creator_t gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh &hnd)
const Handle_StlMesh_Mesh &stlMesh, int domId) {
: m_mesh(stlMesh), return gmio_stl_occmesh_creator(internal::occMeshPtr(hnd));
m_domainId(domId) }
gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain()
: mesh(NULL),
domain_id(0)
{ {
} }
const Handle_StlMesh_Mesh &gmio_OccStlMeshDomain::mesh() const gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain(
const StlMesh_Mesh *msh, int dom_id)
: mesh(msh),
domain_id(dom_id)
{ {
return m_mesh;
} }
void gmio_OccStlMeshDomain::setMesh(const Handle_StlMesh_Mesh &stlMesh) gmio_occ_stl_mesh_domain::gmio_occ_stl_mesh_domain(
const Handle_StlMesh_Mesh &hndMesh, int dom_id)
: mesh(internal::occMeshPtr(hndMesh)),
domain_id(dom_id)
{ {
m_mesh = stlMesh;
}
int gmio_OccStlMeshDomain::domainId() const
{
return m_domainId;
}
void gmio_OccStlMeshDomain::setDomainId(int domId)
{
m_domainId = domId;
} }

View File

@ -17,6 +17,10 @@
* Support of OpenCascade's StlMesh_Mesh * Support of OpenCascade's StlMesh_Mesh
*/ */
#ifndef __cplusplus
# error C++ compiler required
#endif
#ifndef GMIO_SUPPORT_STL_OCC_H #ifndef GMIO_SUPPORT_STL_OCC_H
#define GMIO_SUPPORT_STL_OCC_H #define GMIO_SUPPORT_STL_OCC_H
@ -24,44 +28,44 @@
#include "../gmio_stl/stl_mesh.h" #include "../gmio_stl/stl_mesh.h"
#include "../gmio_stl/stl_mesh_creator.h" #include "../gmio_stl/stl_mesh_creator.h"
#include <Handle_StlMesh_Mesh.hxx> class Handle_StlMesh_Mesh;
struct gmio_stl_mesh; class StlMesh_Mesh;
struct gmio_stl_mesh_creator;
/*! Domain in a OpenCascade \c StlMesh_Mesh object /*! Domain in a OpenCascade \c StlMesh_Mesh object
* *
* The domain is indicated with its index within the STL mesh * The domain is indicated with its index within the STL mesh
*/ */
class GMIO_LIBSUPPORT_EXPORT gmio_OccStlMeshDomain struct GMIO_LIBSUPPORT_EXPORT gmio_occ_stl_mesh_domain
{ {
public: gmio_occ_stl_mesh_domain();
gmio_OccStlMeshDomain(const Handle_StlMesh_Mesh& stlMesh, int domId = 1); gmio_occ_stl_mesh_domain(const StlMesh_Mesh* mesh, int dom_id = 1);
gmio_occ_stl_mesh_domain(const Handle_StlMesh_Mesh& hndMesh, int dom_id = 1);
const Handle_StlMesh_Mesh& mesh() const; const StlMesh_Mesh* mesh;
void setMesh(const Handle_StlMesh_Mesh& stlMesh); int domain_id;
int domainId() const;
void setDomainId(int domId);
private:
Handle_StlMesh_Mesh m_mesh;
int m_domainId;
}; };
typedef struct gmio_occ_stl_mesh_domain gmio_occ_stl_mesh_domain_t;
/*! Returns a gmio_stl_mesh mapped to domain in StlMesh_Mesh /*! Returns a gmio_stl_mesh mapped to domain in StlMesh_Mesh
* *
* The mesh's cookie will point to \p meshCookie * The mesh's cookie will point to \p mesh_domain
*/ */
GMIO_LIBSUPPORT_EXPORT GMIO_LIBSUPPORT_EXPORT
gmio_stl_mesh gmio_stl_occmesh(const gmio_OccStlMeshDomain& meshCookie); gmio_stl_mesh_t gmio_stl_occmesh(const gmio_occ_stl_mesh_domain_t* mesh_domain);
/*! Returns a gmio_stl_mesh_creator that will build a new domain in a /*! Returns a gmio_stl_mesh_creator that will build a new domain in a
* StlMesh_Mesh object * StlMesh_Mesh object
* *
* The creator's cookie will point to the internal data(ie StlMesh_Mesh*) of * The creator's cookie will point \p mesh
* handle \p mesh
*/ */
GMIO_LIBSUPPORT_EXPORT GMIO_LIBSUPPORT_EXPORT
gmio_stl_mesh_creator gmio_stl_occmesh_creator(const Handle_StlMesh_Mesh& mesh); gmio_stl_mesh_creator_t gmio_stl_occmesh_creator(StlMesh_Mesh* mesh);
/*! Same as gmio_stl_occmesh_creator(StlMesh_Mesh*) but takes a handle
*
* The creator's cookie will point to the internal data(ie StlMesh_Mesh*) of
* handle \p hnd
*/
GMIO_LIBSUPPORT_EXPORT
gmio_stl_mesh_creator_t gmio_stl_hnd_occmesh_creator(const Handle_StlMesh_Mesh& hnd);
#endif /* GMIO_SUPPORT_STL_OCC_H */ #endif /* GMIO_SUPPORT_STL_OCC_H */

View File

@ -4,11 +4,13 @@
#include <QtCore/QFile> #include <QtCore/QFile>
#include "../../src/gmio_support/stream_qt.h" #include "../../src/gmio_support/stream_qt.h"
#include <Handle_StlMesh_Mesh.hxx>
int main() int main()
{ {
// OpenCascade // OpenCascade
Handle_StlMesh_Mesh stlMesh; Handle_StlMesh_Mesh stlMesh;
gmio_stl_occmesh_creator(stlMesh); gmio_stl_hnd_occmesh_creator(stlMesh);
// Qt // Qt
QFile file; QFile file;