Skip to content

Commit

Permalink
Add option to import STL as a TopoDS_Shape object
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Apr 11, 2017
1 parent 7dde5b2 commit 1e0dde6
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 68 deletions.
Binary file added images/widget_pseudo_fold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions mayo.pro
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ CONFIG(debug, debug|release) {
GMIO_BIN_SUFFIX =
}
INCLUDEPATH += $$GMIO_ROOT/include
LIBS += -L$$GMIO_ROOT/lib -lgmio$$GMIO_BIN_SUFFIX
LIBS += -L$$GMIO_ROOT/lib -lgmio_static$$GMIO_BIN_SUFFIX
SOURCES += \
$$GMIO_ROOT/src/gmio_support/stl_occ_mesh.cpp \
$$GMIO_ROOT/src/gmio_support/stl_occ_brep.cpp \
$$GMIO_ROOT/src/gmio_support/stl_occ_mesh.cpp \
$$GMIO_ROOT/src/gmio_support/stl_occ_polytri.cpp \
$$GMIO_ROOT/src/gmio_support/stream_qt.cpp

# OpenCascade
Expand Down
1 change: 1 addition & 0 deletions mayo.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
<file>images/camera_photo.png</file>
<file>images/document.png</file>
<file>images/no.png</file>
<file>images/widget_pseudo_fold.png</file>
</qresource>
</RCC>
32 changes: 23 additions & 9 deletions src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,13 @@ static QString gmioErrorToQString(int error)
return Application::tr("GMIO_ERROR_INVALID_MEMBLOCK_SIZE");
case GMIO_ERROR_STREAM:
return Application::tr("GMIO_ERROR_STREAM");
case GMIO_ERROR_TRANSFER_STOPPED:
return Application::tr("GMIO_ERROR_TRANSFER_STOPPED");
case GMIO_ERROR_TASK_STOPPED:
return Application::tr("GMIO_ERROR_TASK_STOPPED");
case GMIO_ERROR_STDIO:
return Application::tr("GMIO_ERROR_STDIO");
case GMIO_ERROR_BAD_LC_NUMERIC:
return Application::tr("GMIO_ERROR_BAD_LC_NUMERIC");
// TODO: complete other core enum values
// STL
case GMIO_STL_ERROR_UNKNOWN_FORMAT:
return Application::tr("GMIO_STL_ERROR_UNKNOWN_FORMAT");
Expand Down Expand Up @@ -515,21 +516,34 @@ Application::IoResult Application::importStl(
Document* doc, const QString &filepath, qttask::Progress* progress)
{
Application::IoResult result = { false, QString() };
const Options::StlIoLibrary lib = Options::instance()->stlIoLibrary();
const Options::StlIoLibrary lib =
Options::instance()->stlIoLibrary();
const Options::GmioStlImportType gmioImpType =
Options::instance()->gmioStlImportType();
if (lib == Options::StlIoLibrary::Gmio) {
QFile file(filepath);
if (file.open(QIODevice::ReadOnly)) {
gmio_stream stream = gmio_stream_qiodevice(&file);
gmio_stl_read_options options = {};
options.func_stla_get_streamsize = &gmio_stla_infos_get_streamsize;
options.func_stla_get_streamsize = &gmio_stla_infos_probe_streamsize;
options.task_iface = Internal::gmio_qttask_create_task_iface(progress);
int err = GMIO_ERROR_OK;
while (gmio_no_error(err) && !file.atEnd()) {
Handle_StlMesh_Mesh stlMesh = new StlMesh_Mesh;
gmio_stl_mesh_creator_occmesh meshcreator(stlMesh);
err = gmio_stl_read(&stream, &meshcreator, &options);
if (gmio_no_error(err))
doc->addItem(Internal::createStlMeshItem(filepath, stlMesh));
if (gmioImpType == Options::GmioStlImportType::OccStlMesh) {
Handle_StlMesh_Mesh stlMesh = new StlMesh_Mesh;
gmio_stl_mesh_creator_occmesh meshcreator(stlMesh);
err = gmio_stl_read(&stream, &meshcreator, &options);
if (gmio_no_error(err))
doc->addItem(Internal::createStlMeshItem(filepath, stlMesh));
}
else if (gmioImpType == Options::GmioStlImportType::OccPolyTriShape) {
gmio_stl_mesh_creator_occshape meshcreator;
err = gmio_stl_read(&stream, &meshcreator, &options);
if (gmio_no_error(err)) {
const TopoDS_Shape& shape = meshcreator.shape();
doc->addItem(Internal::createBRepShapeItem(filepath, shape));
}
}
}
result.ok = (err == GMIO_ERROR_OK);
if (!result.ok)
Expand Down
70 changes: 46 additions & 24 deletions src/dialog_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "fougtools/qttools/gui/qwidget_utils.h"
#include "fougtools/occtools/qt_utils.h"

#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QColorDialog>

namespace Mayo {
Expand All @@ -43,7 +44,7 @@ namespace Internal {

static QPixmap colorPixmap(const QColor& color)
{
QPixmap pix(24, 24);
QPixmap pix(16, 16);
pix.fill(color);
return pix;
}
Expand All @@ -57,48 +58,60 @@ DialogOptions::DialogOptions(QWidget *parent)
m_ui->setupUi(this);

const Options* opts = Options::instance();
const auto& vecGpxMaterialMapping =
Mayo::enum_Graphic3dNameOfMaterial().mappings();

// STL import/export
auto btnGrp_stlIoLib = new QButtonGroup(this);
btnGrp_stlIoLib->addButton(m_ui->radioBtn_UseGmio);
btnGrp_stlIoLib->addButton(m_ui->radioBtn_UseOcc);
QObject::connect(
m_ui->radioBtn_UseGmio, &QAbstractButton::toggled,
m_ui->widget_gmioStlImport, &QWidget::setEnabled);

const Options::StlIoLibrary lib = opts->stlIoLibrary();
if (lib == Options::StlIoLibrary::Gmio)
m_ui->radioBtn_UseGmio->setChecked(true);
else if (lib == Options::StlIoLibrary::OpenCascade)
m_ui->radioBtn_UseOcc->setChecked(true);
m_ui->radioBtn_UseGmio->setChecked(lib == Options::StlIoLibrary::Gmio);
m_ui->radioBtn_UseOcc->setChecked(lib == Options::StlIoLibrary::OpenCascade);

const Options::GmioStlImportType impType = opts->gmioStlImportType();
m_ui->radioBtn_GmioImportStlMesh->setChecked(
impType == Options::GmioStlImportType::OccStlMesh);
m_ui->radioBtn_GmioImportPolyTriShape->setChecked(
impType == Options::GmioStlImportType::OccPolyTriShape);

// BRep shape defaults
m_ui->toolBtn_BRepShapeDefaultColor->setIcon(
Internal::colorPixmap(opts->brepShapeDefaultColor()));
m_ui->toolBtn_MeshDefaultColor->setIcon(
Internal::colorPixmap(opts->meshDefaultColor()));
m_brepShapeDefaultColor = opts->brepShapeDefaultColor();
m_meshDefaultColor = opts->meshDefaultColor();
QObject::connect(
m_ui->toolBtn_BRepShapeDefaultColor, &QAbstractButton::clicked,
[=] {
this->chooseColor(opts->brepShapeDefaultColor(),
m_ui->toolBtn_BRepShapeDefaultColor,
&m_brepShapeDefaultColor);
} );
for (const Enumeration::Mapping& m : vecGpxMaterialMapping)
m_ui->comboBox_BRepShapeDefaultMaterial->addItem(m.string, m.value);
m_ui->comboBox_BRepShapeDefaultMaterial->setCurrentIndex(
m_ui->comboBox_BRepShapeDefaultMaterial->findData(
static_cast<int>(opts->brepShapeDefaultMaterial())));

// Mesh defaults
m_ui->toolBtn_MeshDefaultColor->setIcon(
Internal::colorPixmap(opts->meshDefaultColor()));
m_meshDefaultColor = opts->meshDefaultColor();
QObject::connect(
m_ui->toolBtn_MeshDefaultColor, &QAbstractButton::clicked,
[=] {
this->chooseColor(opts->meshDefaultColor(),
m_ui->toolBtn_MeshDefaultColor,
&m_meshDefaultColor);
} );

const auto& vecGpxMaterialMapping =
Mayo::enum_Graphic3dNameOfMaterial().mappings();
for (const Enumeration::Mapping& mapping : vecGpxMaterialMapping) {
m_ui->comboBox_BRepShapeDefaultMaterial->addItem(
mapping.string, mapping.value);
m_ui->comboBox_MeshDefaultMaterial->addItem(
mapping.string, mapping.value);
}
m_ui->comboBox_BRepShapeDefaultMaterial->setCurrentIndex(
m_ui->comboBox_BRepShapeDefaultMaterial->findData(
static_cast<int>(opts->brepShapeDefaultMaterial())));
for (const Enumeration::Mapping& m : vecGpxMaterialMapping)
m_ui->comboBox_MeshDefaultMaterial->addItem(m.string, m.value);
m_ui->comboBox_MeshDefaultMaterial->setCurrentIndex(
m_ui->comboBox_MeshDefaultMaterial->findData(
static_cast<int>(opts->meshDefaultMaterial())));

m_ui->checkBox_MeshShowEdges->setChecked(opts->meshDefaultShowEdges());
m_ui->checkBox_MeshShowNodes->setChecked(opts->meshDefaultShowNodes());
}
Expand All @@ -112,21 +125,30 @@ void DialogOptions::accept()
{
Options* opts = Options::instance();

// STL import/export
if (m_ui->radioBtn_UseGmio->isChecked())
opts->setStlIoLibrary(Options::StlIoLibrary::Gmio);
else if (m_ui->radioBtn_UseOcc->isChecked())
opts->setStlIoLibrary(Options::StlIoLibrary::OpenCascade);

opts->setBrepShapeDefaultColor(m_brepShapeDefaultColor);
opts->setMeshDefaultColor(m_meshDefaultColor);
if (opts->stlIoLibrary() == Options::StlIoLibrary::Gmio) {
if (m_ui->radioBtn_GmioImportStlMesh->isChecked())
opts->setGmioStlImportType(Options::GmioStlImportType::OccStlMesh);
else if (m_ui->radioBtn_GmioImportPolyTriShape->isChecked())
opts->setGmioStlImportType(Options::GmioStlImportType::OccPolyTriShape);
}

// BRep shape defaults
opts->setBrepShapeDefaultColor(m_brepShapeDefaultColor);
opts->setBrepShapeDefaultMaterial(
static_cast<Graphic3d_NameOfMaterial>(
m_ui->comboBox_BRepShapeDefaultMaterial->currentData().toInt()));

// Mesh defaults
opts->setMeshDefaultColor(m_meshDefaultColor);
opts->setMeshDefaultMaterial(
static_cast<Graphic3d_NameOfMaterial>(
m_ui->comboBox_MeshDefaultMaterial->currentData().toInt()));

opts->setMeshDefaultShowEdges(m_ui->checkBox_MeshShowEdges->isChecked());
opts->setMeshDefaultShowNodes(m_ui->checkBox_MeshShowNodes->isChecked());

Expand Down
Loading

0 comments on commit 1e0dde6

Please sign in to comment.