Skip to content

Commit

Permalink
Merge branch 'fix/#229' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Oct 16, 2023
2 parents c22977e + 6194511 commit 21501ee
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 71 deletions.
24 changes: 16 additions & 8 deletions src/app/widget_model_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@ WidgetModelTree::WidgetModelTree(QWidget* widget)
modelTreeBtns->addButton(
idBtnRemove,
mayoTheme()->icon(Theme::Icon::Cross),
tr("Remove from document"));
tr("Remove from document")
);
modelTreeBtns->setButtonDetection(
idBtnRemove,
Internal::TreeItemTypeRole,
QVariant(Internal::TreeItemType_DocumentEntity));
QVariant(Internal::TreeItemType_DocumentEntity)
);
modelTreeBtns->setButtonDisplayColumn(idBtnRemove, 0);
modelTreeBtns->setButtonDisplayModes(idBtnRemove, ItemViewButtons::DisplayOnDetection);
modelTreeBtns->setButtonItemSide(idBtnRemove, ItemViewButtons::ItemRightSide);
Expand Down Expand Up @@ -318,7 +320,8 @@ WidgetModelTreeBuilder* WidgetModelTree::findSupportBuilder(const DocumentPtr& d
auto it = std::find_if(
std::next(m_vecBuilder.cbegin()),
m_vecBuilder.cend(),
[=](const BuilderPtr& builder) { return builder->supportsDocument(doc); });
[=](const BuilderPtr& builder) { return builder->supportsDocument(doc); }
);
return it != m_vecBuilder.cend() ? it->get() : m_vecBuilder.front().get();
}

Expand All @@ -328,7 +331,8 @@ WidgetModelTreeBuilder* WidgetModelTree::findSupportBuilder(const DocumentTreeNo
auto it = std::find_if(
std::next(m_vecBuilder.cbegin()),
m_vecBuilder.cend(),
[=](const BuilderPtr& builder) { return builder->supportsDocumentTreeNode(node); });
[=](const BuilderPtr& builder) { return builder->supportsDocumentTreeNode(node); }
);
return it != m_vecBuilder.cend() ? it->get() : m_vecBuilder.front().get();
}

Expand Down Expand Up @@ -409,7 +413,8 @@ void WidgetModelTree::connectTreeModelDataChanged(bool on)
if (on) {
m_connTreeModelDataChanged = QObject::connect(
m_ui->treeWidget_Model->model(), &QAbstractItemModel::dataChanged,
this, &WidgetModelTree::onTreeModelDataChanged, Qt::UniqueConnection);
this, &WidgetModelTree::onTreeModelDataChanged, Qt::UniqueConnection
);
}
else {
QObject::disconnect(m_connTreeModelDataChanged);
Expand All @@ -422,15 +427,17 @@ void WidgetModelTree::connectTreeWidgetDocumentSelectionChanged(bool on)
m_connTreeWidgetDocumentSelectionChanged = QObject::connect(
m_ui->treeWidget_Model->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &WidgetModelTree::onTreeWidgetDocumentSelectionChanged,
Qt::UniqueConnection);
Qt::UniqueConnection
);
}
else {
QObject::disconnect(m_connTreeWidgetDocumentSelectionChanged);
}
}

void WidgetModelTree::onTreeModelDataChanged(
const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles
)
{
if (roles.contains(Qt::CheckStateRole) && topLeft == bottomRight) {
const QModelIndex& indexItem = topLeft;
Expand All @@ -454,7 +461,8 @@ void WidgetModelTree::onTreeModelDataChanged(
}

void WidgetModelTree::onNodesVisibilityChanged(
const GuiDocument* guiDoc, const std::unordered_map<TreeNodeId, CheckState>& mapNodeId)
const GuiDocument* guiDoc, const std::unordered_map<TreeNodeId, CheckState>& mapNodeId
)
{
QTreeWidgetItem* treeItemDoc = this->findTreeItem(guiDoc->document());
if (!treeItemDoc)
Expand Down
8 changes: 7 additions & 1 deletion src/base/brep_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ namespace Mayo {

TopoDS_Compound BRepUtils::makeEmptyCompound()
{
BRep_Builder builder;
TopoDS_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
return comp;
}

void BRepUtils::addShape(TopoDS_Shape* ptrTargetShape, const TopoDS_Shape& shape)
{
TopoDS_Builder builder;
builder.Add(*ptrTargetShape, shape);
}

TopoDS_Face BRepUtils::makeFace(const Handle(Poly_Triangulation)& mesh)
{
TopoDS_Face face;
Expand Down
3 changes: 3 additions & 0 deletions src/base/brep_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct BRepUtils {
// Creates a valid and empty TopoDS_Compound shape
static TopoDS_Compound makeEmptyCompound();

// Adds 'shape' in target shape 'ptrTargetShape'
static void addShape(TopoDS_Shape* ptrTargetShape, const TopoDS_Shape& shape);

// Creates a non-geometric TopoDS_Face wrapping triangulation 'mesh'
static TopoDS_Face makeFace(const Handle(Poly_Triangulation)& mesh);

Expand Down
17 changes: 11 additions & 6 deletions src/base/io_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ bool System::importInDocument(const Args_ImportInDocument& args)
taskData.reader->setMessenger(messenger);
if (args.parametersProvider) {
taskData.reader->applyProperties(
args.parametersProvider->findReaderParameters(taskData.fileFormat));
args.parametersProvider->findReaderParameters(taskData.fileFormat)
);
}

if (!taskData.reader->readFile(taskData.filepath, &progress))
Expand Down Expand Up @@ -257,7 +258,8 @@ bool System::importInDocument(const Args_ImportInDocument& args)
TaskProgress progress(
taskData.progress,
args.entityPostProcessProgressSize,
args.entityPostProcessProgressStep);
args.entityPostProcessProgressStep
);
const double subPortionSize = 100. / double(taskData.seqTransferredEntity.Size());
for (const TDF_Label& labelEntity : taskData.seqTransferredEntity) {
TaskProgress subProgress(&progress, subPortionSize);
Expand Down Expand Up @@ -419,11 +421,12 @@ System::Operation_ExportApplicationItems System::exportApplicationItems()

void System::visitUniqueItems(
Span<const ApplicationItem> spanItem,
std::function<void (const ApplicationItem&)> fnCallback)
std::function<void (const ApplicationItem&)> fnCallback
)
{
std::unordered_set<DocumentPtr> setDoc;
for (const ApplicationItem& item : spanItem) {
if (item.isDocument()) {
if (item.isDocument() && item.document()->entityCount() > 0) {
auto [it, ok] = setDoc.insert(item.document());
if (ok)
fnCallback(item);
Expand All @@ -446,7 +449,8 @@ void System::visitUniqueItems(
void System::traverseUniqueItems(
Span<const ApplicationItem> spanItem,
std::function<void(const DocumentTreeNode&)> fnCallback,
TreeTraversal mode)
TreeTraversal mode
)
{
System::visitUniqueItems(spanItem, [=](const ApplicationItem& item) {
const DocumentPtr doc = item.document();
Expand Down Expand Up @@ -568,7 +572,8 @@ Format probeFormat_STL(const System::FormatProbeInput& input)
bytes[offset]
| (bytes[offset+1] << 8)
| (bytes[offset+2] << 16)
| (bytes[offset+3] << 24);
| (bytes[offset+3] << 24)
;
constexpr unsigned facetSize = (sizeof(float) * 12) + sizeof(uint16_t);
if ((facetSize * facetsCount + binaryStlHeaderSize) == input.hintFullSize)
return Format_STL;
Expand Down
6 changes: 6 additions & 0 deletions src/base/string_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ TCollection_AsciiString to_OccAsciiString(const StringType& str) {
return string_conv<TCollection_AsciiString>(str);
}

// X -> Handle(TCollection_HAsciiString)
template<typename StringType>
Handle(TCollection_HAsciiString) to_OccHandleHAsciiString(const StringType& str) {
return string_conv<Handle(TCollection_HAsciiString)>(str);
}

// X -> TCollection_ExtendedString
template<typename StringType>
TCollection_ExtendedString to_OccExtString(const StringType& str) {
Expand Down
13 changes: 5 additions & 8 deletions src/io_dxf/io_dxf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "io_dxf.h"

#include "../base/brep_utils.h"
#include "../base/cpp_utils.h"
#include "../base/document.h"
#include "../base/filepath.h"
Expand Down Expand Up @@ -213,12 +214,10 @@ TDF_LabelSequence DxfReader::transfer(DocumentPtr doc, TaskProgress* progress)
if (startsWith(layerName, "BLOCKS"))
continue; // Skip

BRep_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
TopoDS_Compound comp = BRepUtils::makeEmptyCompound();
for (const Entity& entity : vecEntity) {
if (!entity.shape.IsNull())
builder.Add(comp, entity.shape);
BRepUtils::addShape(&comp, entity.shape);
}

if (!comp.IsNull()) {
Expand Down Expand Up @@ -421,12 +420,10 @@ void DxfReader::Internal::OnReadInsert(const double* point, const double* scale,
if (!startsWith(k, prefix))
continue; // Skip

BRep_Builder builder;
TopoDS_Compound comp;
builder.MakeCompound(comp);
TopoDS_Compound comp = BRepUtils::makeEmptyCompound();
for (const DxfReader::Entity& entity : vecEntity) {
if (!entity.shape.IsNull())
builder.Add(comp, entity.shape);
BRepUtils::addShape(&comp, entity.shape);
}

if (comp.IsNull())
Expand Down
3 changes: 2 additions & 1 deletion src/io_gmio/io_gmio_amf_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class GmioAmfWriter::Properties : public PropertyGroup {
this->createZipArchive.label()));
}

void restoreDefaults() override {
void restoreDefaults() override
{
const GmioAmfWriter::Parameters params;
this->float64Format.setValue(params.float64Format);
this->float64Precision.setValue(params.float64Precision);
Expand Down
14 changes: 6 additions & 8 deletions src/io_occ/io_occ_brep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#include "io_occ_brep.h"

#include "../base/application_item.h"
#include "../base/brep_utils.h"
#include "../base/caf_utils.h"
#include "../base/document.h"
#include "../base/filepath_conv.h"
#include "../base/occ_progress_indicator.h"
#include "../base/io_system.h"
#include "../base/task_progress.h"
#include "../base/tkernel_utils.h"

Expand Down Expand Up @@ -52,7 +54,7 @@ bool OccBRepWriter::transfer(Span<const ApplicationItem> appItems, TaskProgress*

std::vector<TopoDS_Shape> vecShape;
vecShape.reserve(appItems.size());
for (const ApplicationItem& item : appItems) {
System::visitUniqueItems(appItems, [&](const ApplicationItem& item) {
if (item.isDocument()) {
for (const TDF_Label& label : item.document()->xcaf().topLevelFreeShapes())
vecShape.push_back(XCaf::shape(label));
Expand All @@ -61,16 +63,12 @@ bool OccBRepWriter::transfer(Span<const ApplicationItem> appItems, TaskProgress*
const TDF_Label labelNode = item.documentTreeNode().label();
vecShape.push_back(XCaf::shape(labelNode));
}
}
});

if (vecShape.size() > 1) {
TopoDS_Compound cmpd;
BRep_Builder builder;
builder.MakeCompound(cmpd);
m_shape = BRepUtils::makeEmptyCompound();
for (const TopoDS_Shape& subShape : vecShape)
builder.Add(cmpd, subShape);

m_shape = cmpd;
BRepUtils::addShape(&m_shape, subShape);
}
else if (vecShape.size() == 1) {
m_shape = vecShape.front();
Expand Down
13 changes: 9 additions & 4 deletions src/io_occ/io_occ_caf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../base/global.h"
#include "../base/document.h"
#include "../base/occ_progress_indicator.h"
#include "../base/io_system.h"
#include "../base/task_progress.h"
#include "../base/tkernel_utils.h"

Expand Down Expand Up @@ -58,18 +59,22 @@ bool cafGenericWriteTransfer(CafWriterType& writer, Span<const ApplicationItem>
auto _ = gsl::finally([&]{ Private::cafFinderProcess(writer)->SetProgress(nullptr); });
#endif

for (const ApplicationItem& item : appItems) {
bool okTransfer = true;
System::visitUniqueItems(appItems, [&](const ApplicationItem& item) {
if (!okTransfer)
return; // Skip if already in error state

bool okItemTransfer = false;
if (item.isDocument())
okItemTransfer = writer.Transfer(item.document());
else if (item.isDocumentTreeNode())
okItemTransfer = writer.Transfer(item.documentTreeNode().label());

if (!okItemTransfer)
return false;
}
okTransfer = false;
});

return true;
return okTransfer;
}

} // namespace
Expand Down
5 changes: 3 additions & 2 deletions src/io_occ/io_occ_gltf_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "../base/application_item.h"
#include "../base/enumeration_fromenum.h"
#include "../base/io_system.h"
#include "../base/messenger.h"
#include "../base/occ_progress_indicator.h"
#include "../base/property_builtins.h"
Expand Down Expand Up @@ -119,7 +120,7 @@ bool OccGltfWriter::transfer(Span<const ApplicationItem> spanAppItem, TaskProgre
{
m_document.Nullify();
m_seqRootLabel.Clear();
for (const ApplicationItem& appItem : spanAppItem) {
System::visitUniqueItems(spanAppItem, [=](const ApplicationItem& appItem) {
if (appItem.isDocument() && m_document.IsNull()) {
m_document = appItem.document();
}
Expand All @@ -130,7 +131,7 @@ bool OccGltfWriter::transfer(Span<const ApplicationItem> spanAppItem, TaskProgre
if (appItem.document().get() == m_document.get())
m_seqRootLabel.Append(appItem.documentTreeNode().label());
}
}
});

if (!m_document)
return false;
Expand Down
8 changes: 6 additions & 2 deletions src/io_occ/io_occ_iges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class OccIgesReader::Properties : public PropertyGroup {
"This parameter does not change the continuity of curves that are used "
"in the construction of IGES BRep entities. In this case, the parameter "
"does not influence the continuity of the resulting Open CASCADE curves "
"(it is ignored)."));
"(it is ignored)."
)
);

this->surfaceCurveMode.setDescription(
textIdTr("Preference for the computation of curves in case of 2D/3D inconsistency "
Expand All @@ -49,7 +51,9 @@ class OccIgesReader::Properties : public PropertyGroup {
"of sub-curves given in the IGES file or because of splitting of curves during "
"translation\n"
"- 3D or 2D curve is a Circular Arc (entity type 100) starting and ending "
"in the same point (note that this case is incorrect according to the IGES standard)"));
"in the same point (note that this case is incorrect according to the IGES standard)"
)
);

this->readFaultyEntities.setDescription(textIdTr("Read failed entities"));

Expand Down
5 changes: 3 additions & 2 deletions src/io_occ/io_occ_obj_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "io_occ_obj_writer.h"

#include "../base/application_item.h"
#include "../base/io_system.h"
#include "../base/occ_progress_indicator.h"
#include "../base/property_builtins.h"
#include "../base/property_enumeration.h"
Expand Down Expand Up @@ -43,7 +44,7 @@ bool OccObjWriter::transfer(Span<const ApplicationItem> spanAppItem, TaskProgres
{
m_document.Nullify();
m_seqRootLabel.Clear();
for (const ApplicationItem& appItem : spanAppItem) {
System::visitUniqueItems(spanAppItem, [=](const ApplicationItem& appItem) {
if (appItem.isDocument() && m_document.IsNull()) {
m_document = appItem.document();
}
Expand All @@ -54,7 +55,7 @@ bool OccObjWriter::transfer(Span<const ApplicationItem> spanAppItem, TaskProgres
if (appItem.document().get() == m_document.get())
m_seqRootLabel.Append(appItem.documentTreeNode().label());
}
}
});

if (!m_document)
return false;
Expand Down
13 changes: 5 additions & 8 deletions src/io_occ/io_occ_step.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "io_occ_step.h"
#include "io_occ_caf.h"
#include "../base/messenger.h"
#include "../base/meta_enum.h"
#include "../base/occ_static_variables_rollback.h"
#include "../base/property_builtins.h"
Expand Down Expand Up @@ -329,14 +330,10 @@ bool OccStepWriter::writeFile(const FilePath& filepath, TaskProgress* /*progress
this->changeStaticVariables(&rollback);

APIHeaderSection_MakeHeader makeHeader(m_writer->ChangeWriter().Model());
makeHeader.SetAuthorValue(
1, string_conv<Handle(TCollection_HAsciiString)>(m_params.headerAuthor));
makeHeader.SetOrganizationValue(
1, string_conv<Handle(TCollection_HAsciiString)>(m_params.headerOrganization));
makeHeader.SetOriginatingSystem(
string_conv<Handle(TCollection_HAsciiString)>(m_params.headerOriginatingSystem));
makeHeader.SetDescriptionValue(
1, string_conv<Handle(TCollection_HAsciiString)>(m_params.headerDescription));
makeHeader.SetAuthorValue(1, to_OccHandleHAsciiString(m_params.headerAuthor));
makeHeader.SetOrganizationValue(1, to_OccHandleHAsciiString(m_params.headerOrganization));
makeHeader.SetOriginatingSystem(to_OccHandleHAsciiString(m_params.headerOriginatingSystem));
makeHeader.SetDescriptionValue(1, to_OccHandleHAsciiString(m_params.headerDescription));

const IFSelect_ReturnStatus err = m_writer->Write(filepath.u8string().c_str());
return err == IFSelect_RetDone;
Expand Down
Loading

0 comments on commit 21501ee

Please sign in to comment.