Skip to content

Commit

Permalink
Merge branch 'refactor/occhandle' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed May 2, 2024
2 parents 17fe28e + 5711be4 commit 180824c
Show file tree
Hide file tree
Showing 89 changed files with 526 additions and 436 deletions.
39 changes: 20 additions & 19 deletions src/app/dialog_inspect_xde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../base/application.h"
#include "../base/brep_utils.h"
#include "../base/caf_utils.h"
#include "../base/occ_handle.h"
#include "../base/meta_enum.h"
#include "../base/settings.h"
#include "../base/tkernel_utils.h"
Expand Down Expand Up @@ -80,7 +81,7 @@ static QStringUtils::TextOptions appDefaultTextOptions()
static void loadLabelAttributes(const TDF_Label& label, QTreeWidgetItem* treeItem)
{
for (TDF_AttributeIterator it(label); it.More(); it.Next()) {
const Handle_TDF_Attribute ptrAttr = it.Value();
const OccHandle<TDF_Attribute> ptrAttr = it.Value();
const Standard_GUID& attrId = ptrAttr->ID();
QString text;
QString value;
Expand Down Expand Up @@ -198,7 +199,7 @@ static QTreeWidgetItem* createPropertyTreeItem(const QString& text, const QStrin
return itemProperty;
}

static QTreeWidgetItem* createPropertyTreeItem(const QString& text, const Handle(TCollection_HAsciiString)& value)
static QTreeWidgetItem* createPropertyTreeItem(const QString& text, const OccHandle<TCollection_HAsciiString>& value)
{
return createPropertyTreeItem(text, to_QString(value));
}
Expand Down Expand Up @@ -264,7 +265,7 @@ static QTreeWidgetItem* createPropertyTreeItem(const QString& text, const TopoDS
}

static void loadLabelMaterialProperties(
const TDF_Label& label, const Handle_XCAFDoc_MaterialTool& materialTool, QTreeWidgetItem* treeItem)
const TDF_Label& label, const OccHandle<XCAFDoc_MaterialTool>& materialTool, QTreeWidgetItem* treeItem)
{
QList<QTreeWidgetItem*> listItemProp;
auto fnAddItem = [&](QTreeWidgetItem* item) { listItemProp.push_back(item); };
Expand All @@ -273,11 +274,11 @@ static void loadLabelMaterialProperties(
QStringUtils::TextOptions densityValueTextOptions = appDefaultTextOptions();
densityValueTextOptions.unitDecimals = 6;

Handle(TCollection_HAsciiString) name;
Handle(TCollection_HAsciiString) description;
OccHandle<TCollection_HAsciiString> name;
OccHandle<TCollection_HAsciiString> description;
double density;
Handle(TCollection_HAsciiString) densityName;
Handle(TCollection_HAsciiString) densityValueType;
OccHandle<TCollection_HAsciiString> densityName;
OccHandle<TCollection_HAsciiString> densityValueType;
if (materialTool->GetMaterial(label, name, description, density, densityName, densityValueType)) {
fnAddItem(createPropertyTreeItem("Name", to_QString(name)));
fnAddItem(createPropertyTreeItem("Description", to_QString(description)));
Expand Down Expand Up @@ -397,7 +398,7 @@ class ImageFileTreeWidgetItem : public QTreeWidgetItem {
mutable std::unordered_map<int, ItemData> m_mapColumnItemData;
};

static QTreeWidgetItem* createPropertyTreeItem(const QString& text, const Handle(Image_Texture)& imgTexture)
static QTreeWidgetItem* createPropertyTreeItem(const QString& text, const OccHandle<Image_Texture>& imgTexture)
{
if (imgTexture.IsNull())
return static_cast<QTreeWidgetItem*>(nullptr);
Expand Down Expand Up @@ -428,7 +429,7 @@ static QTreeWidgetItem* createPropertyTreeItem(const QString& text, const Handle
else if (imgTexture->DataBuffer() && !imgTexture->DataBuffer()->IsEmpty()) {
// Texture is provided by some embedded data
item->setText(1, DialogInspectXde::tr("<data>"));
const Handle(NCollection_Buffer)& buff = imgTexture->DataBuffer();
const OccHandle<NCollection_Buffer>& buff = imgTexture->DataBuffer();
item->setImage(1, QByteArray::fromRawData(reinterpret_cast<const char*>(buff->Data()), buff->Size()));
}

Expand All @@ -439,15 +440,15 @@ static QTreeWidgetItem* createPropertyTreeItem(const QString& text, const Handle
#if OCC_VERSION_HEX >= OCC_VERSION_CHECK(7, 5, 0)
static void loadLabelVisMaterialProperties(
const TDF_Label& label,
const Handle_XCAFDoc_VisMaterialTool& visMaterialTool,
const OccHandle<XCAFDoc_VisMaterialTool>& visMaterialTool,
QTreeWidgetItem* treeItem)
{
QList<QTreeWidgetItem*> listItemProp;
auto fnAddItem = [&](QTreeWidgetItem* item) { listItemProp.push_back(item); };
fnAddItem(createPropertyTreeItem("IsMaterial", visMaterialTool->IsMaterial(label)));
fnAddItem(createPropertyTreeItem("IsSetShapeMaterial", visMaterialTool->IsSetShapeMaterial(label)));

auto fnCreateVisMaterialTreeItem = [](const QString& text, const Handle_XCAFDoc_VisMaterial& material) {
auto fnCreateVisMaterialTreeItem = [](const QString& text, const OccHandle<XCAFDoc_VisMaterial>& material) {
auto item = new QTreeWidgetItem;
item->setText(0, text);
item->addChild(createPropertyTreeItem("HasPbrMaterial", material->HasPbrMaterial()));
Expand Down Expand Up @@ -499,13 +500,13 @@ static void loadLabelVisMaterialProperties(
};

if (visMaterialTool->IsMaterial(label)) {
Handle_XCAFDoc_VisMaterial visMaterial = visMaterialTool->GetMaterial(label);
OccHandle<XCAFDoc_VisMaterial> visMaterial = visMaterialTool->GetMaterial(label);
if (!visMaterial.IsNull() && !visMaterial->IsEmpty())
fnAddItem(fnCreateVisMaterialTreeItem("Material", visMaterial));
}

if (visMaterialTool->IsSetShapeMaterial(label)) {
Handle_XCAFDoc_VisMaterial visMaterial = visMaterialTool->GetShapeMaterial(label);
OccHandle<XCAFDoc_VisMaterial> visMaterial = visMaterialTool->GetShapeMaterial(label);
if (!visMaterial.IsNull() && !visMaterial->IsEmpty())
fnAddItem(fnCreateVisMaterialTreeItem("ShapeMaterial", visMaterial));
}
Expand All @@ -516,7 +517,7 @@ static void loadLabelVisMaterialProperties(

static void loadLabelColorProperties(
const TDF_Label& label,
const Handle_XCAFDoc_ColorTool& colorTool,
const OccHandle<XCAFDoc_ColorTool>& colorTool,
QTreeWidgetItem* treeItem)
{
QList<QTreeWidgetItem*> listItemProp;
Expand Down Expand Up @@ -545,7 +546,7 @@ static void loadLabelColorProperties(

static void loadLabelShapeProperties(
const TDF_Label& label,
const Handle_XCAFDoc_ShapeTool& shapeTool,
const OccHandle<XCAFDoc_ShapeTool>& shapeTool,
QTreeWidgetItem* treeItem)
{
QList<QTreeWidgetItem*> listItemProp;
Expand Down Expand Up @@ -588,7 +589,7 @@ static void loadLabelDimensionProperties(const TDF_Label& label, QTreeWidgetItem
if (!dimAttr)
return;

Handle_XCAFDimTolObjects_DimensionObject dimObject = dimAttr->GetObject();
OccHandle<XCAFDimTolObjects_DimensionObject> dimObject = dimAttr->GetObject();
fnAddItem(createPropertyTreeItem("SemanticName", dimObject->GetSemanticName()));
fnAddItem(createPropertyTreeItem(
"Qualifier", MetaEnum::nameWithoutPrefix(dimObject->GetQualifier(), "XCAFDimTolObjects_")));
Expand Down Expand Up @@ -659,7 +660,7 @@ static void loadLabelDatumProperties(const TDF_Label& label, QTreeWidgetItem* tr
if (!datumAttr)
return;

Handle_XCAFDimTolObjects_DatumObject datumObject = datumAttr->GetObject();
OccHandle<XCAFDimTolObjects_DatumObject> datumObject = datumAttr->GetObject();
fnAddItem(createPropertyTreeItem("SemanticName", datumObject->GetSemanticName()));
fnAddItem(createPropertyTreeItem("Name", datumObject->GetName()));
{
Expand Down Expand Up @@ -712,7 +713,7 @@ static void loadLabelGeomToleranceProperties(const TDF_Label& label, QTreeWidget
if (!tolAttr)
return;

Handle_XCAFDimTolObjects_GeomToleranceObject tolObject = tolAttr->GetObject();
OccHandle<XCAFDimTolObjects_GeomToleranceObject> tolObject = tolAttr->GetObject();
fnAddItem(createPropertyTreeItem("SemanticName", tolObject->GetSemanticName()));
fnAddItem(createPropertyTreeItem(
"Type", MetaEnum::nameWithoutPrefix(tolObject->GetType(), "XCAFDimTolObjects_")));
Expand Down Expand Up @@ -796,7 +797,7 @@ DialogInspectXde::~DialogInspectXde()
delete m_ui;
}

void DialogInspectXde::load(const Handle_TDocStd_Document& doc)
void DialogInspectXde::load(const OccHandle<TDocStd_Document>& doc)
{
m_doc = doc;
if (!XCAFDoc_DocumentTool::IsXCAFDocument(doc)) {
Expand Down
5 changes: 3 additions & 2 deletions src/app/dialog_inspect_xde.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#pragma once

#include "../base/occ_handle.h"
#include <QtWidgets/QDialog>
#include <TDocStd_Document.hxx>
class QTreeWidgetItem;
Expand All @@ -18,13 +19,13 @@ class DialogInspectXde : public QDialog {
DialogInspectXde(QWidget* parent = nullptr);
~DialogInspectXde();

void load(const Handle_TDocStd_Document& doc);
void load(const OccHandle<TDocStd_Document>& doc);

private:
void onLabelTreeWidgetItemClicked(QTreeWidgetItem* item, int column);

class Ui_DialogInspectXde* m_ui = nullptr;
Handle_TDocStd_Document m_doc;
OccHandle<TDocStd_Document> m_doc;
};

} // namespace Mayo
2 changes: 1 addition & 1 deletion src/app/dialog_save_image_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static QImage qtImageTemp(const Image_PixMap& occImg)

} // namespace Internal

DialogSaveImageView::DialogSaveImageView(const Handle_V3d_View& view, QWidget* parent)
DialogSaveImageView::DialogSaveImageView(const OccHandle<V3d_View>& view, QWidget* parent)
: QDialog(parent),
m_ui(new Ui_DialogSaveImageView),
m_view(view)
Expand Down
5 changes: 3 additions & 2 deletions src/app/dialog_save_image_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#pragma once

#include "../base/occ_handle.h"
#include <QtWidgets/QDialog>
#include <V3d_View.hxx>

Expand All @@ -16,7 +17,7 @@ namespace Mayo {
class DialogSaveImageView : public QDialog {
Q_OBJECT
public:
DialogSaveImageView(const Handle_V3d_View& view, QWidget* parent = nullptr);
DialogSaveImageView(const OccHandle<V3d_View>& view, QWidget* parent = nullptr);
~DialogSaveImageView();

private:
Expand All @@ -27,7 +28,7 @@ class DialogSaveImageView : public QDialog {
bool createImageView(Image_PixMap* img) const;

class Ui_DialogSaveImageView* m_ui = nullptr;
Handle_V3d_View m_view;
OccHandle<V3d_View> m_view;
};

} // namespace Mayo
4 changes: 2 additions & 2 deletions src/app/document_tree_node_properties_providers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class XCaf_DocumentTreeNodePropertiesProvider::Properties : public PropertyGroup
// Material
{
const TDF_Label labelPart = XCaf::isShapeReference(label) ? XCaf::shapeReferred(label) : label;
const Handle_XCAFDoc_Material material = XCaf::shapeMaterial(labelPart);
const OccHandle<XCAFDoc_Material> material = XCaf::shapeMaterial(labelPart);
if (material) {
m_propertyMaterialDensity.setQuantity(XCaf::shapeMaterialDensity(material));
m_propertyMaterialName.setValue(to_stdString(material->GetName()));
Expand Down Expand Up @@ -219,7 +219,7 @@ class Mesh_DocumentTreeNodePropertiesProvider::Properties : public PropertyGroup
public:
Properties(const DocumentTreeNode& treeNode)
{
Handle_Poly_Triangulation mesh;
OccHandle<Poly_Triangulation> mesh;
IMeshAccess_visitMeshes(treeNode, [&](const IMeshAccess& access) {
mesh = access.triangulation();
});
Expand Down
4 changes: 2 additions & 2 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
namespace Mayo {

// Declared in graphics/graphics_create_driver.cpp
void setFunctionCreateGraphicsDriver(std::function<Handle_Graphic3d_GraphicDriver()> fn);
void setFunctionCreateGraphicsDriver(std::function<OccHandle<Graphic3d_GraphicDriver>()> fn);

// Provides an i18n context for the current file(main.cpp)
class Main {
Expand Down Expand Up @@ -267,7 +267,7 @@ Thumbnail createGuiDocumentThumbnail(GuiDocument* guiDoc, QSize size)
params.width = size.width();
params.height = size.height();
params.backgroundColor = QtGuiUtils::toPreferredColorSpace(mayoTheme()->color(Theme::Color::Palette_Window));
Handle_Image_AlienPixMap pixmap = IO::ImageWriter::createImage(guiDoc, params);
OccHandle<Image_AlienPixMap> pixmap = IO::ImageWriter::createImage(guiDoc, params);
if (!pixmap) {
qDebug() << "Empty pixmap returned by IO::ImageWriter::createImage()";
return thumbnail;
Expand Down
8 changes: 4 additions & 4 deletions src/app/widget_clip_planes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ WidgetClipPlanes::WidgetClipPlanes(GraphicsViewPtr view, QWidget* parent)
m_view.redraw();
}
else if (property == &appModule->properties()->clipPlanesCappingHatchOn) {
Handle_Graphic3d_TextureMap hatchTexture;
OccHandle<Graphic3d_TextureMap> hatchTexture;
if (m_textureCapping && appModule->properties()->clipPlanesCappingHatchOn)
hatchTexture = m_textureCapping;

Expand Down Expand Up @@ -116,7 +116,7 @@ void WidgetClipPlanes::setClippingOn(bool on)
void WidgetClipPlanes::connectUi(ClipPlaneData* data)
{
UiClipPlane& ui = data->ui;
const Handle_Graphic3d_ClipPlane& gfx = data->graphics;
const OccHandle<Graphic3d_ClipPlane>& gfx = data->graphics;
QAbstractSlider* posSlider = ui.posSlider();
QDoubleSpinBox* posSpin = ui.posSpin();
auto signalSpinValueChanged = qOverload<double>(&QDoubleSpinBox::valueChanged);
Expand Down Expand Up @@ -201,7 +201,7 @@ void WidgetClipPlanes::connectUi(ClipPlaneData* data)
}
}

void WidgetClipPlanes::setPlaneOn(const Handle_Graphic3d_ClipPlane& plane, bool on)
void WidgetClipPlanes::setPlaneOn(const OccHandle<Graphic3d_ClipPlane>& plane, bool on)
{
plane->SetOn(on);
if (!GraphicsUtils::V3dView_hasClipPlane(m_view.v3dView(), plane))
Expand Down Expand Up @@ -242,7 +242,7 @@ void WidgetClipPlanes::createPlaneCappingTexture()
const QByteArray fileContents = file.readAll();
const QByteArray filenameUtf8 = file.fileName().toUtf8();
auto fileContentsData = reinterpret_cast<const Standard_Byte*>(fileContents.constData());
Handle_Image_AlienPixMap imageCapping = new Image_AlienPixMap;
auto imageCapping = makeOccHandle<Image_AlienPixMap>();
imageCapping->Load(fileContentsData, fileContents.size(), filenameUtf8.constData());
m_textureCapping = new GraphicsTexture2D(imageCapping);
m_textureCapping->EnableModulate();
Expand Down
7 changes: 4 additions & 3 deletions src/app/widget_clip_planes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#pragma once

#include "../base/occ_handle.h"
#include "../graphics/graphics_view_ptr.h"

#include <QtWidgets/QWidget>
Expand Down Expand Up @@ -47,15 +48,15 @@ class WidgetClipPlanes : public QWidget {
};

struct ClipPlaneData {
Handle_Graphic3d_ClipPlane graphics;
OccHandle<Graphic3d_ClipPlane> graphics;
UiClipPlane ui;
};

using Range = std::pair<double, double>;

void connectUi(ClipPlaneData* data);

void setPlaneOn(const Handle_Graphic3d_ClipPlane& plane, bool on);
void setPlaneOn(const OccHandle<Graphic3d_ClipPlane>& plane, bool on);
void setPlaneRange(ClipPlaneData* data, const Range& range);

void createPlaneCappingTexture();
Expand All @@ -64,7 +65,7 @@ class WidgetClipPlanes : public QWidget {
GraphicsViewPtr m_view;
std::vector<ClipPlaneData> m_vecClipPlaneData;
Bnd_Box m_bndBox;
Handle_Graphic3d_TextureMap m_textureCapping;
OccHandle<Graphic3d_TextureMap> m_textureCapping;
};

} // namespace Mayo
14 changes: 7 additions & 7 deletions src/app/widget_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ WidgetGrid::WidgetGrid(GraphicsViewPtr viewPtr, QWidget* parent)
m_ui(new Ui_WidgetGrid),
m_viewPtr(viewPtr)
{
const Handle_V3d_Viewer& viewer = viewPtr->Viewer();
const OccHandle<V3d_Viewer>& viewer = viewPtr->Viewer();

// Intial configuration
m_ui->setupUi(this);
Expand Down Expand Up @@ -128,7 +128,7 @@ WidgetGrid::WidgetGrid(GraphicsViewPtr viewPtr, QWidget* parent)
m_ui->combo_Plane->setCurrentIndex(3);

// Install grid draw mode
Handle_Aspect_Grid gridAspect = GraphicsUtils::V3dViewer_grid(viewer);
OccHandle<Aspect_Grid> gridAspect = GraphicsUtils::V3dViewer_grid(viewer);
if (gridAspect) {
if (gridAspect->DrawMode() == Aspect_GDM_Lines)
m_ui->combo_DrawMode->setCurrentIndex(0);
Expand Down Expand Up @@ -248,7 +248,7 @@ const gp_Ax2& WidgetGrid::toPlaneAxis(int comboBoxItemIndex)

void WidgetGrid::activateGrid(bool on)
{
const Handle_V3d_Viewer& viewer = m_viewPtr->Viewer();
const OccHandle<V3d_Viewer>& viewer = m_viewPtr->Viewer();
if (on) {
viewer->ActivateGrid(
toGridType(m_ui->combo_Type->currentIndex()),
Expand All @@ -269,7 +269,7 @@ void WidgetGrid::applyGridParams()
auto fnCorrectedGridStep = [](double gridStep) {
return !qFuzzyIsNull(gridStep) ? gridStep : 0.01;
};
const Handle_V3d_Viewer& viewer = m_viewPtr->Viewer();
const OccHandle<V3d_Viewer>& viewer = m_viewPtr->Viewer();
auto gridType = toGridType(m_ui->combo_Type->currentIndex());
if (gridType == Aspect_GT_Rectangular) {
viewer->SetRectangularGridValues(
Expand All @@ -295,7 +295,7 @@ void WidgetGrid::applyGridParams()

void WidgetGrid::applyGridGraphicsParams()
{
const Handle_V3d_Viewer& viewer = m_viewPtr->Viewer();
const OccHandle<V3d_Viewer>& viewer = m_viewPtr->Viewer();
auto gridType = toGridType(m_ui->combo_Type->currentIndex());
if (gridType == Aspect_GT_Rectangular) {
viewer->SetRectangularGridGraphicValues(
Expand All @@ -316,7 +316,7 @@ void WidgetGrid::applyGridGraphicsParams()

void WidgetGrid::chooseGridColor(GridColorType colorType)
{
const Handle_V3d_Viewer& viewer = m_viewPtr->Viewer();
const OccHandle<V3d_Viewer>& viewer = m_viewPtr->Viewer();
auto gridColors = GraphicsUtils::V3dViewer_gridColors(viewer);
// Helper function to apply some base/tenth grid color
auto fnApplyGridColor = [=](const Quantity_Color& color) {
Expand Down Expand Up @@ -356,7 +356,7 @@ void WidgetGrid::chooseGridColor(GridColorType colorType)

void WidgetGrid::enableGridColorTenth(bool on)
{
const Handle_V3d_Viewer& viewer = m_viewPtr->Viewer();
const OccHandle<V3d_Viewer>& viewer = m_viewPtr->Viewer();
m_ui->label_ColorTenth->setEnabled(on);
m_ui->btn_ColorTenth->setEnabled(on);
auto gridColors = GraphicsUtils::V3dViewer_gridColors(viewer);
Expand Down
Loading

0 comments on commit 180824c

Please sign in to comment.