Skip to content

Commit

Permalink
Graphics: use OccHandle<> utility
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Mar 15, 2024
1 parent bcc97e4 commit 6ff526e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 67 deletions.
1 change: 1 addition & 0 deletions src/graphics/graphics_mesh_object_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "graphics_mesh_data_source.h"
#include "graphics_utils.h"

#include <AIS_InteractiveContext.hxx>
#include <BRep_TFace.hxx>
#include <MeshVS_DisplayModeFlags.hxx>
#include <MeshVS_DrawerAttribute.hxx>
Expand Down
8 changes: 5 additions & 3 deletions src/graphics/graphics_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <V3d_AmbientLight.hxx>
#include <V3d_DirectionalLight.hxx>

#include <unordered_set>

namespace Mayo {

// Defined in graphics_create_driver.cpp
Expand Down Expand Up @@ -217,12 +219,12 @@ void GraphicsScene::deactivateObjectSelection(const GraphicsObjectPtr &object)
d->m_aisContext->Deactivate(object);
}

void GraphicsScene::addSelectionFilter(const Handle_SelectMgr_Filter& filter)
void GraphicsScene::addSelectionFilter(const OccHandle<SelectMgr_Filter>& filter)
{
d->m_aisContext->AddFilter(filter);
}

void GraphicsScene::removeSelectionFilter(const Handle_SelectMgr_Filter& filter)
void GraphicsScene::removeSelectionFilter(const OccHandle<SelectMgr_Filter>& filter)
{
d->m_aisContext->RemoveFilter(filter);
}
Expand Down Expand Up @@ -308,7 +310,7 @@ void GraphicsScene::toggleOwnerSelection(const GraphicsOwnerPtr& gfxOwner)
d->m_aisContext->AddOrRemoveSelected(gfxOwner, false);
}

void GraphicsScene::highlightAt(int xPos, int yPos, const Handle_V3d_View& view)
void GraphicsScene::highlightAt(int xPos, int yPos, const OccHandle<V3d_View>& view)
{
d->m_aisContext->MoveTo(xPos, yPos, view, false);
}
Expand Down
18 changes: 9 additions & 9 deletions src/graphics/graphics_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

#pragma once

#include "../base/occ_handle.h"
#include "../base/signal.h"
#include "graphics_object_ptr.h"
#include "graphics_owner_ptr.h"

#include <AIS_InteractiveContext.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#include <unordered_set>

namespace Mayo {

Expand All @@ -28,14 +28,14 @@ class GraphicsScene {
GraphicsScene(const GraphicsScene&) = delete;
GraphicsScene& operator=(const GraphicsScene&) = delete;

opencascade::handle<V3d_View> createV3dView();
OccHandle<V3d_View> createV3dView();

const opencascade::handle<V3d_Viewer>& v3dViewer() const;
const opencascade::handle<StdSelect_ViewerSelector3d>& mainSelector() const;
const OccHandle<V3d_Viewer>& v3dViewer() const;
const OccHandle<StdSelect_ViewerSelector3d>& mainSelector() const;
bool hiddenLineDrawingOn() const;

const opencascade::handle<Prs3d_Drawer>& drawerDefault() const;
const opencascade::handle<Prs3d_Drawer>& drawerHighlight(Prs3d_TypeOfHighlight style) const;
const OccHandle<Prs3d_Drawer>& drawerDefault() const;
const OccHandle<Prs3d_Drawer>& drawerHighlight(Prs3d_TypeOfHighlight style) const;

enum AddObjectFlag {
AddObjectDefault = 0,
Expand All @@ -57,8 +57,8 @@ class GraphicsScene {
void deactivateObjectSelection(const GraphicsObjectPtr& object, int mode);
void deactivateObjectSelection(const GraphicsObjectPtr& object);

void addSelectionFilter(const Handle_SelectMgr_Filter& filter);
void removeSelectionFilter(const Handle_SelectMgr_Filter& filter);
void addSelectionFilter(const OccHandle<SelectMgr_Filter>& filter);
void removeSelectionFilter(const OccHandle<SelectMgr_Filter>& filter);
void clearSelectionFilters();

void setObjectDisplayMode(const GraphicsObjectPtr& object, int displayMode);
Expand All @@ -79,7 +79,7 @@ class GraphicsScene {
void setSelectionMode(SelectionMode mode);

const GraphicsOwnerPtr& currentHighlightedOwner() const;
void highlightAt(int xPos, int yPos, const Handle_V3d_View& view);
void highlightAt(int xPos, int yPos, const OccHandle<V3d_View>& view);
void select();

int selectedCount() const;
Expand Down
4 changes: 4 additions & 0 deletions src/graphics/graphics_shape_object_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
#include "graphics_utils.h"

#include <AIS_ConnectedInteractive.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_DisplayMode.hxx>
#include <Prs3d_LineAspect.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <XCAFPrs_AISObject.hxx>

namespace Mayo {
Expand Down
67 changes: 40 additions & 27 deletions src/graphics/graphics_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@
#include "../base/math_utils.h"
#include "../base/tkernel_utils.h"

#include <AIS_InteractiveContext.hxx>
#include <AIS_InteractiveObject.hxx>
#include <Aspect_DisplayConnection.hxx>
#include <Aspect_Grid.hxx>
#include <Aspect_Window.hxx>
#include <Bnd_Box.hxx>
#include <ElSLib.hxx>
#include <Graphic3d_ClipPlane.hxx>
#include <Image_PixMap.hxx>
#include <ProjLib.hxx>
#include <SelectMgr_SelectionManager.hxx>
#include <Standard_Version.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>

#include <algorithm>
#include <cstring>
Expand All @@ -27,7 +34,8 @@ namespace Mayo {
namespace Internal {

static void AisContext_setObjectVisible(
AIS_InteractiveContext* ptrContext, const Handle_AIS_InteractiveObject& object, bool on)
AIS_InteractiveContext* ptrContext, const OccHandle<AIS_InteractiveObject>& object, bool on
)
{
if (ptrContext && object) {
if (on)
Expand All @@ -39,29 +47,30 @@ static void AisContext_setObjectVisible(

} // namespace Internal

void GraphicsUtils::V3dView_fitAll(const Handle_V3d_View& view)
void GraphicsUtils::V3dView_fitAll(const OccHandle<V3d_View>& view)
{
view->ZFitAll();
view->FitAll(0.01, false/*dontUpdateView*/);
}

bool GraphicsUtils::V3dView_hasClipPlane(
const Handle_V3d_View& view, const Handle_Graphic3d_ClipPlane& plane)
const OccHandle<V3d_View>& view, const OccHandle<Graphic3d_ClipPlane>& plane
)
{
const Handle_Graphic3d_SequenceOfHClipPlane& seqClipPlane = view->ClipPlanes();
const OccHandle<Graphic3d_SequenceOfHClipPlane>& seqClipPlane = view->ClipPlanes();
if (seqClipPlane.IsNull() || seqClipPlane->Size() == 0)
return false;

for (Graphic3d_SequenceOfHClipPlane::Iterator it(*seqClipPlane); it.More(); it.Next()) {
const Handle_Graphic3d_ClipPlane& candidate = it.Value();
const OccHandle<Graphic3d_ClipPlane>& candidate = it.Value();
if (candidate.get() == plane.get())
return true;
}

return false;
}

gp_Pnt GraphicsUtils::V3dView_to3dPosition(const Handle_V3d_View& view, double x, double y)
gp_Pnt GraphicsUtils::V3dView_to3dPosition(const OccHandle<V3d_View>& view, double x, double y)
{
double xEye, yEye, zEye, xAt, yAt, zAt;
view->Eye(xEye, yEye, zEye);
Expand All @@ -83,7 +92,7 @@ gp_Pnt GraphicsUtils::V3dView_to3dPosition(const Handle_V3d_View& view, double x
return ElSLib::Value(pntConvertedOnPlane.X(), pntConvertedOnPlane.Y(), planeView);
}

bool GraphicsUtils::V3dViewer_isGridActive(const Handle_V3d_Viewer& viewer)
bool GraphicsUtils::V3dViewer_isGridActive(const OccHandle<V3d_Viewer>& viewer)
{
#if OCC_VERSION_HEX >= OCC_VERSION_CHECK(7, 6, 0)
return viewer->IsGridActive();
Expand All @@ -92,7 +101,7 @@ bool GraphicsUtils::V3dViewer_isGridActive(const Handle_V3d_Viewer& viewer)
#endif
}

Handle_Aspect_Grid GraphicsUtils::V3dViewer_grid(const Handle_V3d_Viewer& viewer)
OccHandle<Aspect_Grid> GraphicsUtils::V3dViewer_grid(const OccHandle<V3d_Viewer>& viewer)
{
#if OCC_VERSION_HEX >= OCC_VERSION_CHECK(7, 6, 0)
return viewer->Grid(false/*dontCreate*/);
Expand All @@ -101,26 +110,29 @@ Handle_Aspect_Grid GraphicsUtils::V3dViewer_grid(const Handle_V3d_Viewer& viewer
#endif
}

GraphicsUtils::AspectGridColors GraphicsUtils::V3dViewer_gridColors(const Handle_V3d_Viewer& viewer)
GraphicsUtils::AspectGridColors GraphicsUtils::V3dViewer_gridColors(const OccHandle<V3d_Viewer>& viewer)
{
AspectGridColors colors;
Handle_Aspect_Grid gridAspect = V3dViewer_grid(viewer);
OccHandle<Aspect_Grid> gridAspect = V3dViewer_grid(viewer);
if (gridAspect)
gridAspect->Colors(colors.base, colors.tenth);

return colors;
}

void GraphicsUtils::V3dViewer_setGridColors(const Handle_V3d_Viewer &viewer, const AspectGridColors &colors)
void GraphicsUtils::V3dViewer_setGridColors(
const OccHandle<V3d_Viewer>& viewer, const AspectGridColors& colors
)
{
Handle_Aspect_Grid gridAspect = V3dViewer_grid(viewer);
OccHandle<Aspect_Grid> gridAspect = V3dViewer_grid(viewer);
if (gridAspect)
gridAspect->SetColors(colors.base, colors.tenth);
}

void GraphicsUtils::AisContext_eraseObject(
const Handle_AIS_InteractiveContext& context,
const Handle_AIS_InteractiveObject& object)
const OccHandle<AIS_InteractiveContext>& context,
const OccHandle<AIS_InteractiveObject>& object
)
{
if (!object.IsNull() && !context.IsNull()) {
context->Erase(object, false/*dontUpdateViewer*/);
Expand All @@ -131,14 +143,15 @@ void GraphicsUtils::AisContext_eraseObject(
}

void GraphicsUtils::AisContext_setObjectVisible(
const Handle_AIS_InteractiveContext& context,
const Handle_AIS_InteractiveObject& object,
bool on)
const OccHandle<AIS_InteractiveContext>& context,
const OccHandle<AIS_InteractiveObject>& object,
bool on
)
{
Internal::AisContext_setObjectVisible(context.get(), object, on);
}

AIS_InteractiveContext* GraphicsUtils::AisObject_contextPtr(const GraphicsObjectPtr& object)
AIS_InteractiveContext* GraphicsUtils::AisObject_contextPtr(const OccHandle<AIS_InteractiveObject>& object)
{
if (!object)
return nullptr;
Expand All @@ -150,26 +163,26 @@ AIS_InteractiveContext* GraphicsUtils::AisObject_contextPtr(const GraphicsObject
#endif
}

bool GraphicsUtils::AisObject_isVisible(const GraphicsObjectPtr& object)
bool GraphicsUtils::AisObject_isVisible(const OccHandle<AIS_InteractiveObject>& object)
{
const AIS_InteractiveContext* ptrContext = AisObject_contextPtr(object);
return ptrContext ? ptrContext->IsDisplayed(object) : false;
}

void GraphicsUtils::AisObject_setVisible(const GraphicsObjectPtr& object, bool on)
void GraphicsUtils::AisObject_setVisible(const OccHandle<AIS_InteractiveObject>& object, bool on)
{
Internal::AisContext_setObjectVisible(AisObject_contextPtr(object), object, on);
}

Bnd_Box GraphicsUtils::AisObject_boundingBox(const GraphicsObjectPtr& object)
Bnd_Box GraphicsUtils::AisObject_boundingBox(const OccHandle<AIS_InteractiveObject>& object)
{
Bnd_Box box;
if (object.IsNull())
return box;

// Ensure bounding box is calculated
#if OCC_VERSION_HEX >= OCC_VERSION_CHECK(7, 4, 0)
for (Handle_PrsMgr_Presentation prs : object->Presentations()) {
for (OccHandle<PrsMgr_Presentation> prs : object->Presentations()) {
if (prs->Mode() == object->DisplayMode() && !prs->CStructure()->BoundingBox().IsValid())
prs->CalculateBoundBox();
}
Expand All @@ -187,7 +200,7 @@ Bnd_Box GraphicsUtils::AisObject_boundingBox(const GraphicsObjectPtr& object)
return box;
}

int GraphicsUtils::AspectWindow_width(const Handle_Aspect_Window& wnd)
int GraphicsUtils::AspectWindow_width(const OccHandle<Aspect_Window>& wnd)
{
if (wnd.IsNull())
return 0;
Expand All @@ -197,7 +210,7 @@ int GraphicsUtils::AspectWindow_width(const Handle_Aspect_Window& wnd)
return w;
}

int GraphicsUtils::AspectWindow_height(const Handle_Aspect_Window& wnd)
int GraphicsUtils::AspectWindow_height(const OccHandle<Aspect_Window>& wnd)
{
if (wnd.IsNull())
return 0;
Expand All @@ -217,7 +230,7 @@ OccHandle<Aspect_DisplayConnection> GraphicsUtils::AspectDisplayConnection_creat
}

void GraphicsUtils::Gfx3dClipPlane_setCappingHatch(
const Handle_Graphic3d_ClipPlane& plane, Aspect_HatchStyle hatch)
const OccHandle<Graphic3d_ClipPlane>& plane, Aspect_HatchStyle hatch)
{
if (hatch == Aspect_HS_SOLID)
plane->SetCappingHatchOff();
Expand All @@ -227,14 +240,14 @@ void GraphicsUtils::Gfx3dClipPlane_setCappingHatch(
plane->SetCappingHatch(hatch);
}

void GraphicsUtils::Gfx3dClipPlane_setNormal(const Handle_Graphic3d_ClipPlane& plane, const gp_Dir& n)
void GraphicsUtils::Gfx3dClipPlane_setNormal(const OccHandle<Graphic3d_ClipPlane>& plane, const gp_Dir& n)
{
const double planePos = MathUtils::planePosition(plane->ToPlane());
const gp_Vec placement(planePos * gp_Vec(n));
plane->SetEquation(gp_Pln(placement.XYZ(), n));
}

void GraphicsUtils::Gfx3dClipPlane_setPosition(const Handle_Graphic3d_ClipPlane& plane, double pos)
void GraphicsUtils::Gfx3dClipPlane_setPosition(const OccHandle<Graphic3d_ClipPlane>& plane, double pos)
{
const gp_Dir& n = plane->ToPlane().Axis().Direction();
if (MathUtils::isReversedStandardDir(n))
Expand Down
Loading

0 comments on commit 6ff526e

Please sign in to comment.