Skip to content

Commit

Permalink
Merge branch 'bugfix/#313' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Feb 24, 2025
2 parents c69d48b + 3b7fe0a commit 47bb2b7
Show file tree
Hide file tree
Showing 61 changed files with 345 additions and 277 deletions.
77 changes: 75 additions & 2 deletions src/app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
#endif

#include <QtDebug>
#include <QtGui/QFontMetrics>
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QLabel>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QScrollArea>
#include <QtWidgets/QStyle>

namespace Mayo {

Expand Down Expand Up @@ -273,9 +279,76 @@ void MainWindow::onGuiDocumentErased(GuiDocument* /*guiDoc*/)
this->updateControlsActivation();
}

// Async execution of a resizable message box dialog
// Text is also selectable and displayed within a scroll area
QDialog* runMessageBox(
QMessageBox::Icon icon,
QWidget* parentWidget,
const QString& text,
QDialogButtonBox::StandardButtons btns = QDialogButtonBox::StandardButton::Ok
)
{
auto dlg = new QDialog(parentWidget);
dlg->setModal(true);

QStyle::StandardPixmap dlgIcon;
QString title;
switch (icon) {
case QMessageBox::NoIcon:
case QMessageBox::Information:
dlgIcon = QStyle::SP_MessageBoxInformation;
title = MainWindow::tr("Information");
break;
case QMessageBox::Warning:
dlgIcon = QStyle::SP_MessageBoxWarning;
title = MainWindow::tr("Warning");
break;
case QMessageBox::Critical:
dlgIcon = QStyle::SP_MessageBoxCritical;
title = MainWindow::tr("Error");
break;
case QMessageBox::Question:
dlgIcon = QStyle::SP_MessageBoxQuestion;
title = MainWindow::tr("Question");
break;
}

dlg->setWindowTitle(title);

auto dlgMsgLayout = new QHBoxLayout;
auto label = new QLabel(dlg);
const int iconSize = QApplication::style()->pixelMetric(QStyle::PM_MessageBoxIconSize, nullptr, dlg);
label->setPixmap(QApplication::style()->standardIcon(dlgIcon).pixmap(iconSize, iconSize));
dlgMsgLayout->addWidget(label, 0, Qt::AlignHCenter | Qt::AlignTop);

auto textLabel = new QLabel;
textLabel->setText(text);
textLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
auto scrollArea = new QScrollArea(dlg);
scrollArea->setWidget(textLabel);
scrollArea->setWidgetResizable(true);
textLabel->setAlignment(Qt::AlignTop);
dlgMsgLayout->addWidget(scrollArea, 5);

auto dlgLayout = new QVBoxLayout(dlg);
auto btnBox = new QDialogButtonBox(btns, dlg);
if (btns.testFlag(QDialogButtonBox::StandardButton::Ok)) {
btnBox->button(QDialogButtonBox::StandardButton::Ok)->setDefault(true);
btnBox->button(QDialogButtonBox::StandardButton::Ok)->setFocus();
}

dlgLayout->addLayout(dlgMsgLayout);
dlgLayout->addWidget(btnBox);

QObject::connect(btnBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept);
QtWidgetsUtils::asyncDialogExec(dlg);
return dlg;
}

void MainWindow::onMessage(const Messenger::Message& msg)
{
const auto qtext = to_QString(msg.text);

switch (msg.type) {
case MessageType::Trace:
qDebug() << qtext;
Expand All @@ -284,10 +357,10 @@ void MainWindow::onMessage(const Messenger::Message& msg)
WidgetMessageIndicator::showInfo(qtext, this);
break;
case MessageType::Warning:
QtWidgetsUtils::asyncMsgBoxWarning(this, tr("Warning"), qtext);
runMessageBox(QMessageBox::Warning, this, qtext);
break;
case MessageType::Error:
QtWidgetsUtils::asyncMsgBoxCritical(this, tr("Error"), qtext);
runMessageBox(QMessageBox::Critical, this, qtext);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/base/brep_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct BRepUtils {
// Deserializes string 'str' obtained from 'shapeToToString()' into a shape object
static TopoDS_Shape shapeFromString(const std::string& str);

// Does 'edge' rely on 3D curve of curve on surface?
// Does 'edge' rely on 3D curve or curve on surface?
static bool isGeometric(const TopoDS_Edge& edge);

// Does 'face' rely on a geometric surface?
Expand Down
19 changes: 18 additions & 1 deletion src/base/geom_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

#include "geom_utils.h"
#include "math_utils.h"

#include <Adaptor3d_Curve.hxx>
#include <gp_Trsf.hxx>
#include <Standard_Version.hxx>
#include <TopLoc_Location.hxx>

#include <algorithm>
#include <cmath>

namespace Mayo {

Expand Down Expand Up @@ -42,4 +48,15 @@ std::pair<gp_Pnt, gp_Vec> GeomUtils::d0d1(const Adaptor3d_Curve& curve, double u
return { pnt, vec };
}

} // namespace Mayo
bool GeomUtils::hasScaling(const gp_Trsf& trsf)
{
#if OCC_VERSION_HEX >= 0x070600
const double scalePrec = TopLoc_Location::ScalePrec();
#else
constexpr double scalePrec = 1.e-14;
#endif
// This test comes from implementation of TopoDS_Shape::Location() function
return std::abs(std::abs(trsf.ScaleFactor()) - 1.) > scalePrec || trsf.IsNegative();
}

} // namespace Mayo::GeomUtils
11 changes: 7 additions & 4 deletions src/base/geom_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
class Adaptor3d_Curve;
class gp_Trsf;

namespace Mayo {
namespace GeomUtils {
namespace Mayo::GeomUtils {

double normalizedU(const Adaptor3d_Curve& curve, double u);

gp_Pnt d0(const Adaptor3d_Curve& curve, double u);
gp_Vec d1(const Adaptor3d_Curve& curve, double u);
std::pair<gp_Pnt, gp_Vec> d0d1(const Adaptor3d_Curve& curve, double u);

} // namespace GeomUtils
} // namespace Mayo
// Detects if transformation matrix 'trsf' contains scaling
bool hasScaling(const gp_Trsf& trsf);

} // namespace Mayo::GeomUtils
6 changes: 2 additions & 4 deletions src/base/io_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

#include <algorithm>

namespace Mayo {
namespace IO {
namespace Mayo::IO {

std::string_view formatIdentifier(Format format)
{
Expand Down Expand Up @@ -133,5 +132,4 @@ bool formatProvidesMesh(Format format)
;
}

} // namespace IO
} // namespace Mayo
} // namespace Mayo::IO
6 changes: 2 additions & 4 deletions src/base/io_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#include "span.h"
#include <string_view>

namespace Mayo {
namespace IO {
namespace Mayo::IO {

// Predefined I/O formats
enum Format {
Expand Down Expand Up @@ -51,5 +50,4 @@ bool formatProvidesBRep(Format format);
// Does 'format' provide mesh model ?
bool formatProvidesMesh(Format format);

} // namespace IO
} // namespace Mayo
} // namespace Mayo::IO
6 changes: 2 additions & 4 deletions src/base/io_parameters_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

namespace Mayo { class PropertyGroup; }

namespace Mayo {
namespace IO {
namespace Mayo::IO {

// Abstract mechanism to provide reader/writer parameters for a format
class ParametersProvider {
Expand All @@ -20,5 +19,4 @@ class ParametersProvider {
virtual const PropertyGroup* findWriterParameters(Format format) const = 0;
};

} // namespace IO
} // namespace Mayo
} // namespace Mayo::IO
6 changes: 2 additions & 4 deletions src/base/io_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#include "io_reader.h"

namespace Mayo {
namespace IO {
namespace Mayo::IO {

} // namespace IO
} // namespace Mayo
} // namespace Mayo::IO
6 changes: 2 additions & 4 deletions src/base/io_single_format_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#include "../base/io_reader.h"
#include "../base/io_writer.h"

namespace Mayo {
namespace IO {
namespace Mayo::IO {

template<Format Fmt, typename FormatReader>
class SingleFormatFactoryReader : public FactoryReader {
Expand Down Expand Up @@ -84,5 +83,4 @@ SingleFormatFactoryWriter<Fmt, FormatWriter>::createProperties(Format format, Pr
return {};
}

} // namespace IO
} // namespace Mayo
} // namespace Mayo::IO
Loading

0 comments on commit 47bb2b7

Please sign in to comment.