opencascade AIS_ExclusionFilter过滤器 源码学习

前言

一个用于根据给定类型和/或签名来拒绝或接受对象的框架。对象被存储,并且存储的对象与标志设置一起用于定义过滤器。要过滤的对象与添加到过滤器中的存储对象进行比较,并根据排除标志设置被接受或拒绝。

  • 排除标志开启时
    • 函数 IsOk 对所有对象回答 true,除了那些类型和签名与过滤框架中存储的对象相同的对象。
  • 排除标志关闭时
    • 函数 IsOk 对所有类型和签名与存储对象相同的对象回答 true

对应方法

AIS_ExclusionFilter() [1/3]

AIS_ExclusionFilter::AIS_ExclusionFilter (const Standard_Boolean ExclusionFlagOn = Standard_True)

构造一个由标志设置 ExclusionFlagOn 定义的空排除过滤器对象。默认情况下,标志设置为 true

AIS_ExclusionFilter() [2/3]

AIS_ExclusionFilter::AIS_ExclusionFilter (const AIS_KindOfInteractive TypeToExclude, const Standard_Boolean ExclusionFlagOn = Standard_True)

所有类型为 TypeToExclude 的 AIS 对象将被 IsOk 方法拒绝。

AIS_ExclusionFilter() [3/3]

AIS_ExclusionFilter::AIS_ExclusionFilter (const AIS_KindOfInteractive TypeToExclude, const Standard_Integer SignatureInType, const Standard_Boolean ExclusionFlagOn = Standard_True)

构造一个由枚举值 TypeToExclude、签名 SignatureInType 和标志设置 ExclusionFlagOn 定义的排除过滤器对象。默认情况下,标志设置为 true

成员函数文档

Add() [1/2]

Standard_Boolean AIS_ExclusionFilter::Add (const AIS_KindOfInteractive TypeToExclude)

TypeToExclude 类型添加到类型列表中。

Add() [2/2]

Standard_Boolean AIS_ExclusionFilter::Add (const AIS_KindOfInteractive TypeToExclude, const Standard_Integer SignatureInType)

将具有特定签名的 TypeToExclude 类型添加到类型列表中。

Clear()

void AIS_ExclusionFilter::Clear ()

清空过滤器中存储的所有类型和签名。

IsExclusionFlagOn()

Standard_Boolean AIS_ExclusionFilter::IsExclusionFlagOn () const

返回当前排除标志的状态。

IsOk()

virtual Standard_Boolean AIS_ExclusionFilter::IsOk (const Handle< SelectMgr_EntityOwner > & anObj) const

指示所选的交互对象是否通过过滤器。所有者 anObj 可以是直接或用户。直接所有者是相应的构造元素,而用户是该实体组成部分的复合形状。当一个对象被鼠标检测到时 - 在 AIS 中,这是通过上下文选择器完成的 - 它的所有者作为参数传递给过滤器。如果对象返回 Standard_True,则保留;否则拒绝。如果您正在创建一个继承此框架的过滤器类,并且子类要在 AIS 本地上下文中使用,则需要实现虚函数 ActsOn

实现自 SelectMgr_Filter

IsStored()

Standard_Boolean AIS_ExclusionFilter::IsStored (const AIS_KindOfInteractive aType) const

检查特定类型是否已存储在过滤器中。

ListOfSignature()

void AIS_ExclusionFilter::ListOfSignature (const AIS_KindOfInteractive aType, TColStd_ListOfInteger & TheStoredList) const

获取特定类型的所有存储签名列表。

ListOfStoredTypes()

void AIS_ExclusionFilter::ListOfStoredTypes (TColStd_ListOfInteger & TheList) const

获取所有存储类型的列表。

Remove() [1/2]

Standard_Boolean AIS_ExclusionFilter::Remove (const AIS_KindOfInteractive TypeToExclude)

从过滤器中移除特定类型。

Remove() [2/2]

Standard_Boolean AIS_ExclusionFilter::Remove (const AIS_KindOfInteractive TypeToExclude, const Standard_Integer SignatureInType)

从过滤器中移除具有特定签名的特定类型。

SetExclusionFlag()

void AIS_ExclusionFilter::SetExclusionFlag (const Standard_Boolean theStatus)

设置排除标志的状态。

示例

下面是一个使用 OpenCASCADE 的 AIS_ExclusionFilter 的示例代码。这个示例演示了如何创建一个过滤器,并将其应用于 AIS 上下文以排除特定类型的交互对象。

cpp 复制代码
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <AIS_ExclusionFilter.hxx>
#include <TopoDS_Shape.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <AIS_InteractiveObject.hxx>
#include <Graphic3d.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <Aspect_DisplayConnection.hxx>
#include <WNT_Window.hxx>

// 初始化 OpenCASCADE 的 Viewer 和 Context
Handle(V3d_Viewer) InitViewer() {
    Handle(Aspect_DisplayConnection) aDisplayConnection = new Aspect_DisplayConnection();
    Handle(OpenGl_GraphicDriver) aGraphicDriver = new OpenGl_GraphicDriver(aDisplayConnection);
    Handle(V3d_Viewer) aViewer = new V3d_Viewer(aGraphicDriver);
    return aViewer;
}

int main() {
    // 初始化 Viewer 和 Context
    Handle(V3d_Viewer) aViewer = InitViewer();
    Handle(AIS_InteractiveContext) aContext = new AIS_InteractiveContext(aViewer);

    // 创建一个 Box 并添加到 Context
    TopoDS_Shape aBox = BRepPrimAPI_MakeBox(100.0, 100.0, 100.0).Shape();
    Handle(AIS_Shape) aShape = new AIS_Shape(aBox);
    aContext->Display(aShape, Standard_True);

    // 创建一个 Exclusion Filter 以排除 AIS_Shape 类型
    Handle(AIS_ExclusionFilter) aFilter = new AIS_ExclusionFilter(AIS_KOI_Shape);

    // 将过滤器应用于上下文
    aContext->AddFilter(aFilter);

    // 检查过滤器是否工作
    if (!aFilter->IsOk(aShape->Owner())) {
        std::cout << "The shape is excluded by the filter." << std::endl;
    } else {
        std::cout << "The shape is not excluded by the filter." << std::endl;
    }

    // 移除过滤器
    aContext->RemoveFilter(aFilter);

    return 0;
}

代码说明

  1. 初始化 Viewer 和 Context

    • 使用 InitViewer 函数初始化 OpenCASCADE 的 Viewer。
    • 创建一个 AIS_InteractiveContext 来管理交互对象。
  2. 创建和显示形状

    • 创建一个立方体 TopoDS_Shape 并将其包装在 AIS_Shape 中。
    • 使用 Display 方法将形状添加到上下文中。
  3. 创建排除过滤器

    • 创建一个 AIS_ExclusionFilter 对象,并指定要排除的交互类型为 AIS_Shape
  4. 应用过滤器

    • 使用 AddFilter 方法将过滤器添加到上下文中。
  5. 验证过滤器

    • 使用 IsOk 方法检查形状是否被过滤器排除。
  6. 移除过滤器

    • 使用 RemoveFilter 方法从上下文中移除过滤器。

这个示例展示了如何在 OpenCASCADE 中使用 AIS_ExclusionFilter 来排除特定类型的交互对象。你可以根据需要调整过滤器的类型和签名,以适应不同的应用场景。

相关推荐
西岸行者2 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
悠哉悠哉愿意2 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
别催小唐敲代码2 天前
嵌入式学习路线
学习
毛小茛2 天前
计算机系统概论——校验码
学习
babe小鑫2 天前
大专经济信息管理专业学习数据分析的必要性
学习·数据挖掘·数据分析
winfreedoms2 天前
ROS2知识大白话
笔记·学习·ros2
在这habit之下2 天前
Linux Virtual Server(LVS)学习总结
linux·学习·lvs
我想我不够好。2 天前
2026.2.25监控学习
学习
im_AMBER2 天前
Leetcode 127 删除有序数组中的重复项 | 删除有序数组中的重复项 II
数据结构·学习·算法·leetcode
CodeJourney_J2 天前
从“Hello World“ 开始 C++
c语言·c++·学习