From 1e0dde6bdc578404930c34f0a92dd1350de82760 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Tue, 11 Apr 2017 11:15:29 +0200 Subject: [PATCH] Add option to import STL as a TopoDS_Shape object --- images/widget_pseudo_fold.png | Bin 0 -> 216 bytes mayo.pro | 5 +- mayo.qrc | 1 + src/application.cpp | 32 +++-- src/dialog_options.cpp | 70 +++++++---- src/dialog_options.ui | 218 +++++++++++++++++++++++++++++----- src/options.cpp | 19 ++- src/options.h | 7 ++ 8 files changed, 284 insertions(+), 68 deletions(-) create mode 100644 images/widget_pseudo_fold.png diff --git a/images/widget_pseudo_fold.png b/images/widget_pseudo_fold.png new file mode 100644 index 0000000000000000000000000000000000000000..af1dd25088f45e8ff94cd8d1b2412f727929004b GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^%0SG|!3HGrwwH+jDYhhUcNd2LAh=-f^2tCE&H|6f zVj$H5!i=jPC07Ck*-JcqUD+Qpaq#N0G^&fN1q#V#hD4M&=jZ08=9K`s3=Gaisfi`2 zDGKG8B^e6tp1uJoda3L{aT`w;#}JR>Z?A0RWKa-bIT*k3|Fr9DAp$Nud6)gwEabMP zF|N9DII1?p;2=x!>V4Ks`;Kg=s=Dc8a8SmKA#)zLbdAP+HIN0Ku6{1-oD!Mimages/camera_photo.png images/document.png images/no.png + images/widget_pseudo_fold.png diff --git a/src/application.cpp b/src/application.cpp index 92d8a1d7..eebd0d79 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -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"); @@ -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) diff --git a/src/dialog_options.cpp b/src/dialog_options.cpp index 94e04000..167b4a31 100644 --- a/src/dialog_options.cpp +++ b/src/dialog_options.cpp @@ -35,6 +35,7 @@ #include "fougtools/qttools/gui/qwidget_utils.h" #include "fougtools/occtools/qt_utils.h" +#include #include namespace Mayo { @@ -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; } @@ -57,18 +58,31 @@ 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, [=] { @@ -76,6 +90,16 @@ DialogOptions::DialogOptions(QWidget *parent) 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(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, [=] { @@ -83,22 +107,11 @@ DialogOptions::DialogOptions(QWidget *parent) 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(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(opts->meshDefaultMaterial()))); - m_ui->checkBox_MeshShowEdges->setChecked(opts->meshDefaultShowEdges()); m_ui->checkBox_MeshShowNodes->setChecked(opts->meshDefaultShowNodes()); } @@ -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( m_ui->comboBox_BRepShapeDefaultMaterial->currentData().toInt())); + + // Mesh defaults + opts->setMeshDefaultColor(m_meshDefaultColor); opts->setMeshDefaultMaterial( static_cast( m_ui->comboBox_MeshDefaultMaterial->currentData().toInt())); - opts->setMeshDefaultShowEdges(m_ui->checkBox_MeshShowEdges->isChecked()); opts->setMeshDefaultShowNodes(m_ui->checkBox_MeshShowNodes->isChecked()); diff --git a/src/dialog_options.ui b/src/dialog_options.ui index 7586e338..1b2591e3 100644 --- a/src/dialog_options.ui +++ b/src/dialog_options.ui @@ -6,25 +6,106 @@ 0 0 - 219 - 332 + 379 + 359 Options + + QGroupBox { + font-weight: bold; +} + STL import/export + + true + + + 20 + + + 4 + Use gmio + + true + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + :/images/widget_pseudo_fold.png + + + + + + + + 1 + 0 + + + + Import to StlMesh_Mesh + + + + + + + + + + :/images/widget_pseudo_fold.png + + + + + + + + 1 + 0 + + + + Import to Poly_Triangulation wrapped in TopoDS_Shape + + + + @@ -42,7 +123,16 @@ BRep shape defaults - + + true + + + + 20 + + + 4 + @@ -65,7 +155,24 @@ - + + + + 1 + 0 + + + + + + + + + 1 + 0 + + + @@ -75,7 +182,16 @@ Mesh defaults - + + true + + + + 20 + + + 4 + @@ -98,35 +214,68 @@ - - - - - - Show edges + + + + 1 + 0 + - - - - + + + + + 1 + 0 + - - - - Show nodes - - - - - - - - - + + + + + + Show edges + + + + + + + + 1 + 0 + + + + + + + + + + + Show nodes + + + + + + + + 1 + 0 + + + + + + + + @@ -138,8 +287,8 @@ - 20 - 20 + 17 + 4 @@ -155,8 +304,15 @@ + groupBox_StlIo + groupBox_BRepShapeGpx + groupBox_MeshGpx + buttonBox + verticalSpacer - + + + buttonBox diff --git a/src/options.cpp b/src/options.cpp index 9669ce2d..2109d519 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -32,6 +32,7 @@ namespace Mayo { static const char keyStlIoLibrary[] = "Core/stlIoLibrary"; +static const char keyGmioStlImportType[] = "Core/gmioStlImportType"; static const char keyBrepShapeDefaultColor[] = "BRepShapeGpx/defaultColor"; static const char keyBrepShapeDefaultMaterial[] = "BRepShapeGpx/defaultMaterial"; static const char keyMeshDefaultColor[] = "MeshGpx/defaultColor"; @@ -47,8 +48,8 @@ Options *Options::instance() Options::StlIoLibrary Options::stlIoLibrary() const { - static const int defaultLib = static_cast(StlIoLibrary::Gmio); - const int stlIoLib = m_settings.value(keyStlIoLibrary, defaultLib).toInt(); + static const int defaultVal = static_cast(StlIoLibrary::Gmio); + const int stlIoLib = m_settings.value(keyStlIoLibrary, defaultVal).toInt(); return static_cast(stlIoLib); } @@ -57,6 +58,20 @@ void Options::setStlIoLibrary(Options::StlIoLibrary lib) m_settings.setValue(keyStlIoLibrary, static_cast(lib)); } +Options::GmioStlImportType Options::gmioStlImportType() const +{ + static const int defaultVal = + static_cast(GmioStlImportType::OccStlMesh); + const int gmioStlImpType = + m_settings.value(keyGmioStlImportType, defaultVal).toInt(); + return static_cast(gmioStlImpType); +} + +void Options::setGmioStlImportType(Options::GmioStlImportType imp) +{ + m_settings.setValue(keyGmioStlImportType, static_cast(imp)); +} + QColor Options::brepShapeDefaultColor() const { static const QColor defaultColor(Qt::gray); diff --git a/src/options.h b/src/options.h index 4ecf8cea..c67ca309 100644 --- a/src/options.h +++ b/src/options.h @@ -42,12 +42,19 @@ class Options Gmio, OpenCascade }; + enum class GmioStlImportType { + OccStlMesh, + OccPolyTriShape + }; static Options* instance(); StlIoLibrary stlIoLibrary() const; void setStlIoLibrary(StlIoLibrary lib); + GmioStlImportType gmioStlImportType() const; + void setGmioStlImportType(GmioStlImportType imp); + // BRep shape graphics QColor brepShapeDefaultColor() const;