PowerPoint 演示文稿

advertisement
OpenCascade
Preliminaries
Introduction

Open CASCADE Technology is a powerful open
source C++ library, consisting of thousands of
classes and providing solutions in the area of





Surface and solid modeling : to model any type of
object,
3D and 2D visualization : to display and animate objects,
Data exchange : to import and export standard CAD
formats,
Rapid application development : to manipulate custom
application data.
and in many others in CAD/CAM/CAE, not excluding
AEC, GIS and PDM.


Open CASCADE Technology is designed for
industrial development of 3D modeling,
numeric simulation and visualization
applications which require guaranteed
quality, reliability and a robust set of tools.
Open CASCADE Technology libraries are
distributed in open source for multiple
platforms, and protected by Open CASCADE
Public License which allows unconditional
commercial usage of our code and binaries.
Advanced Components

Advanced Data Exchange





DXF Import / Export
ACIS SAT Import / Export
Parasolid XT Import
Catia V5 Import
Advanced Algorithms



Surface from Scattered Points
Canonical Recognition
Collision Detection

Mesh related



Mesh Framework
Express Mesher
Advanced Samples





Advanced XDE
Advanced OCAF
Shape Healer
Kitchen Demo
Camshaft Drive
Object Libraries Modules

Each module contains several libraries, each
library contains classes grouped into
packages :
Directories Structure
What You Should Know

To pass through the training successfully it
is necessary to know :



C++ Object Oriented Language
Programming technologies
In addition, the following knowledge may
be useful :


Common mathematics, algebra, geometry
Basics of Computer Aided Design
Standard Types
II Notion Of Handles
What Is A Handle
In a concept of Object Oriented Language,
an object is an instance of a data type.
The definition of this object determines the
way it can be used.


Data types fall into two categories
according to the way they are manipulated :


either by value,
or by reference (pointer).

C++ usual problems linked to usage of pointers
are :



Syntax difficulties : Where do I put "*", "&", etc. ?
Management difficulties : When should I delete my
objects ?
To cope with the last issue, Open CASCADE
Technology provides so called Handle mechanism
that is an implementation of smart pointer
mechanism. With this mechanism, referenced
objects created on the heap are automatically
destroyed when no longer in use.
The Handle Mechanism

In general, the Handle mechanism is based
on two elements :



a counter that stores the number of
references to an object in memory,
a pointer to an object in memory.
Every time a new handle to an object is
created, the object's reference counter is
incremented.


Every time a handle to an object is removed,
the object's reference counter is
decremented. As soon as the reference
counter reaches 0, the object is
automatically deleted.
This way the reference counter secures the
delete function.
Use Of Handles

In the program, the handles are manipulated as
conventional pointers :




Declaration of a handle : Handle(Geom_BezierCurve) aBezierCurve;
// Note: a new handle points to nothing
Allocation of a handled object : aBezierCurve = new
Geom_BezierCurve(...);
// Note: operator 'new' is overloaded to benefit from the custom
memory management
De-referencing the handle : Standard_Integer NbPoles =
aBezierCurve->NbPoles();
// Note: operator ?>?is overloaded to provide access to the
handled object
To be manipulated by handle, objects have to
inherit MMgt_TShared class.
Getting Type Of A Handled Object

A specific mechanism allows you to find out the
type of an object pointed to by a handle via
DynamicType method :


Handle(Standard_Type) aType = aGeom->DynamicType();
Two methods inherited from MMgt_TShared can
be applied to check the type of an object :

IsInstance(TheType) : returns Standard_True if the
object is an instance of "TheType"


IsKind(TheType) : returns Standard_True if the
object is an instance of "TheType" or an instance of any
class that inherits "TheType"


if (aGeom->IsInstance(STANDARD_TYPE(Geom_BezierCurve)))
if (aGeom->IsKind(STANDARD_TYPE(Geom_BoundedCurve)))
The macro STANDARD_TYPE returns the object
type from a class name.
Specific Methods Applicable On
Handle


IsNull() : returns Standard_True if the
Handle refers to nothing. if
(aBezierCurve.IsNull()) ...
Nullify() : nullifies the reference to the
object (the reference counter is
decremented). aBezierCurve.Nullify();

DownCast() : converts the given reference
into a reference to a specified class. In pure
C++, if B inherits A, we can assign b to a,
but not a to b. Using DownCast this is
possible :

Example :
Handle(Geom_BezierCurve) aBezierCurve =
Handle(Geom_BezierCurve)::DownCast(aCurve);

If the DownCast operation fails, the
result is a null Handle
Definition Of A New Handled
Class
Creation Of A Handled Class
The users can create theirs own handled
classes (AIS classes for example). These
classes must inherit MMgt_TShared or its
descendants.
Creating a new handled class it is necessary
to respect the following procedure :






Define the header file for the handled class,
Implement the handled class in the source file.
Once the header file is defined, creation of
the Handle class is automatic.

In the header file :
#include <Standard_Macro.hxx>
#include <AIS_Shape.hxx>
#include <Standard_DefineHandle.hxx>
// Your class has to inherit MMgt_TShared or its descendant
DEFINE_STANDARD_HANDLE(MyClass,AIS_Shape)
class MyClass : public AIS_Shape
{ // Declare the methods of your class here
//...
DEFINE_STANDARD_RTTIEXT(MyClass) };

In the source file :
#include <MyClass.hxx>
IMPLEMENT_STANDARD_HANDLE(MyClass,AIS_Shape)
IMPLEMENT_STANDARD_RTTI(MyClass,AIS_Shape)
// Define the methods of your class here
//...
Geometry
I - Review Of Geometry

Analytic Geometry


Defined by an explicit equation of type f(x,y) = 0
Parametric Geometry :


Defined by a set of equations depending on one
or more parameters.
Mathematics Of Surface modeling



Conic : Circle, Parabola, Hyperbola …
Bezier Curves :
B-Splines :



Complex surfaces can also be based on
curves which can themselves be defined by
points. Two numerical methods (or a
combination of them) are used to model a
curve using points :
Interpolation
Smoothing or Approximation

Interpolation : This is the simplest method,
curves pass through all points.

Approximation : A single or a set of piecewise continuous curves is fitted onto points
using defined geometric constraints
(tangency, curvature, tolerance...).
Geometry Versus Topology



It is important to understand the differences
between geometry and topology when using Open
CASCADE.
Geometry is representation of simple shapes
which have a mathematical description (Cylinder,
Planes, Bezier and B-Splines surfaces...).
Topology involves structuring geometry in order
to :


Delimit a geometric region limited by boundaries
Group regions together to define complex shapes
II - Elementary Geometry
Open CASCADE Reusable
Components
Global Structure
The Open CASCADE libraries contain
components
The components comprise 3 aspects:
Abstraction, Presentation, Control
Each of these aspects contains packages
These in turn contain classes and functions
as seen previously





The Component Design Model


Open CASCADE is a set of components the
user can manipulate or enlarge by adding
his own components.
Each component is structured as shown
below :


Example : Model Design structure of a 2D circle
Data abstraction : An axis and a radius



Control :




The Constructors of such a circle are : Default
constructor, Constructor with an axis and a radius
(NB : No circle construction with 3 points is allowed in
standard creation. You have to build a CircleFactory as a
control.)
To build a circle with a center and a radius
To build a circle with 3 points ...
(Note : Each control has a method to return the
abstract object)
Presentation : The object you display in a viewer
Benefits



Data Abstraction is perennial : new
controls can be added without changing the
Data Abstraction.
Data Abstraction is minimal : Controls
are created as needed during the session.
Controls have a lifetime : Intermediate
results can be queried before validation.
Component Implementation


Data Abstraction, Controls and Presentation
are in separate packages.
Applied Controls in Open CASCADE can be :



Direct constructions (Make…)
Constraint constructions (in 2D)
Algorithms (intersect, boolean operations, etc.)
Elementary Geometry
Overview
Basic Geometry Packages
Use Of Basic Geometry



Basic Geometry is manipulated by value
Basic Geometry has no inheritance
Use On-Line documentation to get more
information about these packages
Primitives Of Basic Geometry
III - Advanced Geometry

Advanced Geometry Package
Use Of Advanced Geometry



Hierarchy of classes is STEP compliant
Entities from Geom and Geom2d are
manipulated by HANDLE (useful to share data
without copying them)
Provide tools to go back and forth from Geom to
gp
Example :
Handle(Geom_Circle) C = new Geom_Circle(gp_Circ c);
gp_Circ c = C->Circ();

Entities from GC, GCE2d and Geom2dGcc are
manipulated by VALUE (Control Classes)
Primitives Of Advanced Geometry
Constraint Geometry




Constrained geometry creation involves to
qualify solutions and arguments
outside : The solution and argument are
outside each other
enclosing : The solution encompasses the
argument
enclosed : The solution is encompassed by
the argument


Arguments are ordered. This means that we
have an implicit orientation:
By convention, the interior of a contour is
on the left according to the positive
direction of the contour description.
IV - Geometry Digest
Points

Basic :


- gp_Pnt(X,Y,Z)
- gp::Origin()
From points :

- gp_Pnt::Barycenter() : compute the barycenter of 2 points
- gp_Pnt::Translate() translates a point.
- gp_Pnt::Translated() translates a point (the initial point is
duplicated).
- gp_Pnt::Rotate() rotates a point.
- gp_Pnt::Rotated() rotates a point (the initial point is
duplicated).
- GProp_PEquation::Point() : returns the mean point of a
collection of points, considered to be coincident.

From curve :

- gp_Circle::Location() : returns the center
of the circle (or the origin of a line)
- GCPnts and CPnts packages : to compute
points on a 2D or 3D curve
- LProp_CLProps to compute a local point on
a curve
- Geom_Curve::D0() : computes a point
identified by a given parameter

Projections :


- onto curves :
GeomAPI_ProjectPointOnCurve class
- onto surfaces :
GeomAPI_ProjectPointOnSurf class
From intersections :

- see GeomAPI_IntCS class
Curves

Building curves from points :

- FairCurve_Batten : constructs curves with a
constant or linearly increasing section. These
curves are two-dimensional, and simulate
physical splines or battens.
- GeomAPI_PointsToBSpline : builds a 3D
BSpline curve which approximates a set of
points, with a given continuity.

Projections of curves :


- onto planes : see GeomAPI::To2d(),
GeomAPI::To3d() methods
- onto any surface : see
GeomProjLib::Project() method
Intersections :

- Geom2dAPI_InterCurveCurve :
intersection between two 2D curves
- GeomAPI_IntSS : intersection curves
between two surfaces

Extremas :


Extrapolation :


- GeomAPI_ExtremaCurveCurve : extrema
between two curves.
- GeomAPI_ExtremaCurveSurface :
extrema between a curve and a surface.
- GeomLib::ExtentCurveToPoint() method
is used to extend a bounded curve C to a point
P.
Information :

- GeomLProp_CurveTool class provides
methods to query local properties of curves.
Surfaces

From points :


- GeomAPI_PointsToBSplineSurface :
builds a BSpline surface which approximates or
interpolates a set of points.
- GeomPlate_BuildAveragePlane computes
an average inertial plane with an array of points.
- GeomPlate_BuildPlateSurface builds a
plate surface so that it conforms to given curve
and / or point constraints.
From curves :

- see GeomFill package : builds a ruled surface
between two curves.

Extremas :


Extrapolation :


- see GeomAPI_ExtremaSurfaceSurface
class
- see GeomLib::ExtentSurfaceByLength()
method : extends the bounded surface Surf
along one of its boundaries
Information :

- see GeomLProp_SurfaceTool class
Topology
I - Review Of Topology
Topological Concepts
Topology is the limitation (in the sense of
boundary) of a geometric object
Topology is mainly used to describe :






Restrictions of a given object
Connexity between objects (i.e. how objects are
connected together)
In Open CASCADE, topological entities are
called shapes.
Topological Entities








Vertex
Edge
Wire
Face
Shell : a set of faces connected by their edges.
Solid : a part of space limited by shells.
Compound : a group of any type of the
topological objects.
Compsolid : a set of solids connected by their
faces.
Shapes Creation

Shapes can be created following one of
these two concepts :


ABSTRACT TOPOLOGY (TopoDS) : In this
case, the data structure description is built
around the notion of reference to an object.
Example : an edge is described by its
boundaries which are two vertices.


BOUNDARY REPRESENTATION (BRep) :
Boundary Representation gives a complete
description of an object by associating
topological and geometric information. In this
case, objects are described by their boundaries.
Example : an edge lies on a curve and is
bounded by two vertices.
II - Data Structure
Topological Data Structure

Shape Hierarchy

A shape is defined by :



A TShape (TopoDS package)
A local coordinate system (TopLoc package)
An orientation (TopAbs package)

TShape : A TShape is a pointer which
describes the object in its default coordinate
system. It is never used directly, what is
manipulated is the Shape.
 The TShape class is provided in the
TopoDS package.

Location : The location is described by
defining a local coordinate system which
references a shape at different positions
from that of its definition.

Example : all these boxes share the same
TShape (manipulated by handle) but can have
different locations.
Shapes Connexity

Two objects are connected if they share a
same Sub-Shape.

Example : Let's consider two edges TE1 and TE2. Each
of them is limited by its boundaries which are vertices
(V1F and V1L for TE1 and V2F and V2L for TE2). When
these two edges are connected together, they share a
common vertex TV2.
Graph Structure

All the shapes can be subdivided into subshapes according to the following graph :
TopoDS_Shape Methods

The TopoDS classes provides methods that
allow you to control creation of shapes.







IsNull(), Nullify() : Access to TShape
Location(), Move(), Moved() : Access to location
Orientation(), Oriented(),Reverse(), Reversed() : Access to
orientation
ShapeType() : Returns the type of the TopoDS_Shape
IsPartner() : Checks if two shapes have the same TShape but
different location and orientation
IsSame() : Checks if two shapes have same TShape and location
but different orientation
IsEqual() : Checks if two shapes have same TShape, location and
orientation [equivalent to ‘==‘ operator]

TopoDS_Shape are manipulated by value. That is
why special methods are implemented to supply
DownCast functionality (reminder : DownCast
uses Handle) :








TopoDS::Vertex(...) Returns a TopoDS_Vertex
TopoDS::Edge(...) Returns a TopoDS_Edge
TopoDS::Wire(...) Returns a TopoDS_Wire
TopoDS::Face(...) Returns a TopoDS_Face
TopoDS::Shell(...) Returns a TopoDS_Shell
TopoDS::Solid(...) Returns a TopoDS_Solid
TopoDS::CompSolid(...) Returns a TopoDS_CompSolid
TopoDS::Compound(...) Returns a TopoDS_Compound



// 1 -- correct
if (aShape.Shapetype() == TopAbs_VERTEX)
{ TopoDS_Vertex V;
V = TopoDS::Vertex(aShape); }else
// 2 -- correct
if (aShape.Shapetype() == TopAbs_VERTEX)
TopoDS_Vertex V2 = TopoDS::Vertex(aShape);
// 3 -- rejected by compiler
if (aShape.Shapetype() == TopAbs_VERTEX)
TopoDS_Vertex V3 = aShape;
Topological Tools


TopTools package provides basic tools to
act on topological data structure.
TopExp package provides tools for
exploring the data structure described with
the TopoDS package.
Basic Tools

The TopTools package provides utilities for
the topological data structure :




Some classes, to hash a shape based on the
TShape with or without Location and
Orientation.
Some classes for writing and reading Location
and Shapes.
Instantiation of TCollections for shapes.
For more details about these tools, you can
consult the on-line documentation.
Exploring Shapes

Exploring a topological data structure
means finding all the sub-objects of a given
type that compose this shape.


General tools to explore a shape are available.
Some of them are described below. For the
others, consult the on-line documentation.
TopExp_Explorer class allows to explore a
shape and returns all sub-shapes contained in it
with the possibility to select a kind of entities
(for example, only faces).


Example :
TopExp_Explorer Exp;
for (Exp.Init(aShape,TopAbs_EDGE);
Exp.More(); Exp.Next()) { TopoDS_Edge
myEdge; myEdge =
TopoDS::Edge(Exp.Current()); }


BRepTools_WireExplorer class is used to
return the edges of a wire in their order of
connexion.
TopExp::MapShapes() method allows to
explore shapes but detects common
elements and puts results in a map.

TopExp::MapShapesAndAncestors()
method returns all the entities that
reference another one.
BRepFilletAPI_MakeChamfer MC(theBox);
// add all the edges to chamfer
TopTools_IndexedDataMapOfShapeListOfShape M;
/* put each edge (E1, E2, E3 and E4) in a map M and bind it with the list
of faces which reference it (F1, F5, ...). */
TopExp::MapShapesAndAncestors(theBox,
TopAbs_EDGE,TopAbs_FACE,M);
Standard_Integer i;
for (i = 1; i<=M.Extent(); i++) {
/* Explore M and return the key associated with index i (an edge or a
face) */
TopoDS_Edge E = TopoDS::Edge(M.FindKey(i));
TopoDS_Face F = TopoDS::Face(M.FindFromIndex(i).First());
/* use all edges by applying Add() method to generate the chamfer. */
MC.Add(5,5,E,F);
}


In Open CASCADE, there is no back
pointer from sub-shapes to shapes.
So if you want to find all the faces which
contain a given vertex or a given face, you
have to use this tool :
TopExp::MapShapesAndAncestors().
III - Boundary Representation
BRep Introduction
The Boundary Representation describes the
data structure for modeling objects in three
dimensions.
In BRep modeling, entities are represented
by their frontiers or their boundaries.




BRep mixes Geometry with Topology :



Geometry : a face lies on a surface, an edge
lies on a curve and a vertex lies on a point ;
Topology : connectivity of shapes.
BRep description lies on two packages :


TopoDS package is used to describe the
topological structure of objects,
Geom (and Geom2d) packages are used to
describe the geometry of these objects
Topology And Geometry In
BRep
Geometry in BRep
BRep_TVertex, BRep_TEdge or BRep_TFace
are defined to add geometric information on
the BRep model.
BRep_TFace, BRep_TEdge and
BRep_TVertex inherit from
TopoDS_TShape.
The geometric information is not stored in
the same way according to the topological
entity




Topology In BRep
Generated entities are : (Store geometric
information)





Space limited by faces BRep_TFace
Surface limited by edges BRep_TEdge
Curve limited by Vertices BRep_Tvertex


BRep_TFace, BRep_TEdge and
BRep_TVertex inherit from TopoDS_Tshape
Geometry In BRep_TVertex

BRep_TVertex Geometry is stored as :



A 3D point (gp_Pnt)
A list of points on curves (Geom_Curve,
parameter)
A list of points on surfaces (Uparameter,
Vparameter , Geom_Surface)
Geometry In BRep_TEdge

BRep_TEdge Geometry is stored as :


A Geom_Curve and the 2 vertices parameter
A list of curves on surfaces (Geom2d_Curve,
V1parameter, V2parameter, Geom_Surface,
V1UVCoord V2UVCoord)

The SameParameter property forces a
point to have the same parameter value on
the 3D curve and each 2D curves.
Geometry In BRep_TFace


BRep_TFace Geometry is stored as a
Geom_Surface
Note that for the BRep_TFace, it is
necessary to define a location with the
TopLoc package.
BRep Tools

Two packages propose tools to manipulate
BRep models :

The BRep package provides classes :



to access the geometric information in the data
structure : the BRep_Tool class,
to set a precision for topology entities : the
BRep_Builder class.
The BRepAdaptor package provides classes to
access the geometry of the BRep models.
The BRep_Tool Class

BRep_Tool class provides methods to
access the geometric information in a
model :





Tolerance(...) Returns a Standard_Real
Surface(...) Returns a Geom_Surface
Curve(...) Returns a Geom_Curve
CurveOnSurface(...) Returns a
Geom2d_Curve
Pnt(...) Returns a gp_Pnt
The BRep_Builder Class

Among the tools, we find the BRep_Builder
class which provides the methods for creating a
model step by step by associating geometry and
topology. This class enables you to :
1. Change precision / Tolerance
...
Standard_Real aTol = 1e-4;
/* a Vertex is created from point P with tolerance
Precision::Confusion() */
TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(P);
BRep_Builder aBuilder;
/* The tolerance Precision::Confusion() becomes aTol */
aBuilder.UpdateVertex(aVertex, aTol);
2. Build a compound
TopoDS_Compound aComp;
BRep_Builder aBuilder;
/* Create a new compound */
aBuilder.MakeCompound(aComp); //Make an empty
result
/* Add a shape to compound */
aBuilder.Add(aComp, aShape1);
The BRepAdaptor Package


This package provides classes to perform
geometric computation directly on
topological data structure.
The classes defined in BRepAdaptor are :



BRepAdaptor_Surface allows to see a face
like a Surface from package Adaptor2d.
BRepAdaptor_Curve allows to see an edge
like a Curve from package Adaptor3d.
BRepAdaptor_Curve2d allows to see a curve
on a face like a Curve2d from package
Adaptor2d.
IV - Modeling Algorithms

- BRepAlgoAPI
- BRepBuilderAPI
- BRepFilletAPI
- BRepFeat : Specific package for
Advanced Modeling
- BRepOffsetAPI
- BRepPrimAPI
BRepBuilderAPI Package

1 - Building objects :








BRepBuilderAPI_MakeVertex : Builds a vertex from points
BRepBuilderAPI_MakeEdge, MakeEdge2d : Builds edges
from curves
BRepBuilderAPI_MakePolygon : Builds wire from points
BRepBuilderAPI_MakeWire : Builds a wire from edges
BRepBuilderAPI_MakeFace : Builds a face from a surface
BRepBuilderAPI_MakeShell : Builds a shell from non C2
surface
BRepBuilderAPI_MakeSolid : Builds a solid from shell
2 - Modifying objects :


BRepBuilderAPI_Transform : Applies transformation to a
shape
BRepBuilderAPI_Copy : Duplicates shapes
BRepPrimAPI Package

BRepPrimAPI_MakeBox :
1 - Creating primitive objects :

BRepPrimAPI_MakeWedge :
BRepPrimAPI_MakeSphere
1 - Creating primitive objects :

BRepPrimAPI_MakeCone :
1 - Creating primitive objects :

BRepPrimAPI_MakeCylinder :
1 - Creating primitive objects :

BRepPrimAPI_MakeTorus :
2 - Creating sweeps :

BRepPrimAPI_MakeHalfSpace : Builds
solid from a face or a shell and a point
2 - Creating sweeps :


- BRepPrimAPI_MakePrism : Makes a linear prism
from a shape
- BRepPrimAPI_MakeRevol : : Makes a revolved sweep
BRepAlgoAPI Package

BRepAlgoAPI_Cut

BRepAlgoAPI_Fuse

BRepAlgoAPI_Common

BRepAlgoAPI_Section
BRepFilletAPI Package



BRepFilletAPI_MakeFillet
BRepFilletAPI_MakeFillet2d
BRepFilletAPI_MakeChamfer
BRepOffsetAPI Package


BRepOffsetAPI_MakeThickSolid :
BRepOffsetAPI_DraftAngle :


BRepOffsetAPI_MakePipe :
BRepOffsetAPI_MakeEvolved :



BRepOffsetAPI_ThruSections : Builds
shell or solid from wire
BRepOffsetAPI_Sewing builds a shell
from a set of faces including connectivity
BRepOffsetAPI_FindContiguousEdges :
finds the contiguous edges among a set of
shapes within the given tolerance
V – Topology Digest
VI - Features


“Feature” is used to qualify an element of
shape which characterizes a form such as a
boss, a hole, a rib, slots, etc. In that sense
features are extensions of the classical
boundary representation of shapes.
The BRepFeat package is used to create
and manipulate form and mechanical
features in a Boundary Representation
framework.

Features can be depressions or protrusions.


The BRepFeat classes are used to build :
Form features including the following types :


-
Draft Prism;
Prism;
Pipe;
Revolved feature.
Mechanical features including :

- ribs
- protrusions grooves (or slots)
- depressions along planar(linear) surfaces or revolution surfaces.


The BRepFeat_MakePrism class
describes functions to build a prism feature,
that means a prism interacting with a shape.
The BRepFeat_MakeRevol class is used
to build revolved shells from basis shapes.



The MakeDPrism class describes functions
to build draft prism topologies from basic
shape surfaces.
The MakePipe class constructs compound
shapes with pipe features.
These topologies can be depression or
protrusion.
Mechanical features

The LinearForm class is used to build a rib
or a groove along a developable, planar
surface.
The Gluer Class



It is used to glue two solids along faces.
The contact faces of the glued shapes must have no part
outside the contact faces of the basic shape.
This class is created or initialized from two shapes.
The SplitShape Class

BRepFeat_SplitShape class is used to
split faces of a shape with wires or edges.
The shape containing the new entities is
rebuilt, sharing the unmodified ones.
Visualization
I - Introduction


Visualization in Open CASCADE is managed
by a set of tools independent of the
definition of the objects.
This allows:


to define as many modes of presentation as
you want for a same object,
to define as many modes of selection as you
want for a same object.

These presentation or selection modes are
available:


either from ready-to-use algorithms which
create graphic presentations from geometric
models
either from user defined algorithms which
create specific graphic presentation.

Display is managed through the
presentation services and selection
through the selection services.


With these services, data structures and
algorithms are provided to display objects of
your application, and to support the graphical
selection of these objects.
Such a graphical application created with
these tools uses Viewers, Views and AIS
(Application Interactive Services).
Key Words

Viewers manage a list of views and thus
allow visualizing objects. Note that each
object is displayed in all views. Any number
of viewers can be created in an application
for different purposes.

Views are sets of graphic objects arranged
in a display list. A view has 2 states :


Degenerated (normal mode)
Non-Degenerated (Hidden Line mode).

Application Interactive Services (AIS) is a
set of high level classes allowing you to
simply manage display and dynamic
selection in a viewer.
Presentation
Packages
Selection
packages
Basic
Management
PrsMgr
SelectMgr
2D objects
V2d and
Graphic2d
3D objects
V3d, Prs3d,
Graphic3d and
StdPrs
SelectBasics,
Select2d,
Select3d and
StdSelect
Presentation Packages
Selection Packages
II - Application Interactive
Services
Interactive Context
The interactive context is the central
entity which pilots visualizations and
selections.
The constructor of an Interactive
Context defines a principal viewer :



AIS_InteractiveContext(const
Handle(V3d_Viewer)& MainViewer);

The Interactive Context allows you to
manage the graphic and "selectable"
behavior of interactive objects by providing
useful mechanisms like:




Graphic Presentation (Display(), Highlight(), Erase() ...
methods)
Dynamic Selection (MoveTo(), Select(), ShiftSelect() ...
methods)
Selection results (InitSelected(), MoreSelected() ...
methods)
Shape oriented methods (SelectedShape() ... methods)

An Interactive Context has two operating
modes :


A default mode named Neutral Point
A local Presentation mode named Local
Context

Opening Local Contexts allows you to :


Prepare and use a temporary presentation as
well as a selection environment without
disturbing the neutral point.
Break down a shape into sub-shapes. Each
selection mode represents a breakdown into
sensitive primitives. (for a shape, there are 7
selection modes : selection of the shape,
selection of the vertices, edges, wires, faces,
shells, and the constituent solids.)

You can open several local contexts
(identified by an index), but only the last is
active.
Standard_Integer OpenLocalContext();

Some functions can only be used in Local
Context state. Others have context specific
behaviors.

When closing the local context, you return
to the state in which you were before
opening it (neutral point or previous local
context in the stack).
void CloseLocalContext(const Standard_Integer Index=-1);


Objects temporarily put in a local context
are not recognized by other local contexts.
All objects visualized at Neutral Point or
only a few one can be recognized by all
local contexts.
Interactive Object


An Interactive Object is a virtual entity
which can be presented and selected.
There are 3 kinds of Interactive Objects
available in AIS package:

1. The construction elements: AIS_Point,
AIS_Axis, AIS_Line, AIS_Circle, AIS_Plane,
AIS_Trihedron

2. The Relations concerning dimensions and
constraints :






AIS_ConcentricRelation, AIS_FixRelation, AIS_IdenticRelation,
AIS_ParallelRelation, AIS_PerpendicularRelation, AIS_Relation,
AIS_SymmetricRelation, AIS_TangentRelation, AIS_AngleDimension,
AIS_Chamf2dDimension, AIS_Chamf3dDimension,
AIS_DiameterDimension,
AIS_DimensionOwner, AIS_LengthDimension, AIS_OffsetDimension,
AIS_RadiusDimension

3. The Objects:




AIS_Shape, AIS_ConnectedInteractive,
AIS_ConnectedShape,
AIS_MultipleConnectedInteractive,
AIS_MultipleConnectedShape.

An Interactive Object can have some
graphic attributes which are specific to it,
such as color, material or default
visualization mode.
Use Of AIS Interactive Objects


You can reuse standard interactive objects,
but you can also implement your own
classes of interactive objects, provided you
respect certain rules.
Modifying an interactive object which is
already known by the Context must be
done using Context functions. You can call
the interactive object available functions
only if this object has not been loaded into
an Interactive Context.
User-Defined Interactive Objects


Computation of various presentations of an
interactive object is done in Compute
functions.
These are automatically called at a
visualization or an update request. They
have to be redefined for new Interactive
Objects.


Selection : ComputeSelection (...)
Presentation : Compute (...)
III - Presentation

Use the AIS_InteractiveContext to Display
an object
void AIS_InteractiveContext::Display(const
Handle(AIS_InteractiveObject)&);

By default, the interactive object takes the graphic
attributes of the context in which it is visualized :




visualization mode,
type of lines,
number of isoparameters,
...

Each interactive object can have its own
visualization attributes:


SetDisplayMode(), SetColor(), SetMaterial(),
SetTransparency()
A presentation is identified with an index.
By convention, the default representation
mode is 0 (wireframe). You can manage the
presentation mode at 2 levels :


void SetDisplayMode(const Handle(AIS_InteractiveObject)&, const
Standard_Integer aMode);
void SetDisplayMode(const Standard_Integer aMode);

Example : an AIS_Shape has 3
visualization modes :



mode 0 : Wireframe (default mode)
mode 1 : Shading (depending on the type of
shape)
mode 2 : Bounding Box
IV - Selection


Management of selection differs according
to the operating mode : Neutral point or
Local Context.
The majority of visualization functions can
be used in both, but some of these are
specific to each.
At Neutral Point


A mechanism allows you to highlight
detected entities in the Interactive Context
at neutral point
It is possible to:

Pre-highlight objects detected at mouse
position
MoveTo(), HasDetected(), DetectInteractive()

Select objects at mouse position
In A Local Context


A mechanism allows you to highlight
detected entities in the Interactive Context
in a Local Context
It is possible to:

Pre-highlight objects detected at mouse
position
MoveTo(), HasDetected(), DetectInteractive(), DetectedShape()

Select objects at mouse position
Select(), ShiftSelect(), InitSelected(), MoreSelected(),
NextSelected(), Applicative(), SelectedShape()
Difference Between NP And LC


In a Local Context an interactive object can
have an indefinite number of modes of selection.
These modes are identified by an index, the
default is 0 (It is the only available mode at
Neutral Point).
Example : Selection modes for AIS_Shape are :





0
2
4
6
8
- Shape
- Edge
- Face
– Solid
- Compound
1 - Vertex
3 - Wire
5 - Shell
7 - Compsolid

At Neutral Point, it is not advisable to
activate other identification modes than the
default selection mode 0. It is better to
open a local context in order to activate
specific selection modes.
Filter


Selection is based on the concept of
dynamic detection which allows to highlight
objects when the mouse cursor moves over
them. This makes the user be sure that the
picked object is the correct one.
Filters allow you to refine the dynamic
detection context

Users can program their own filters and
load them into the interactive context. For
instance: Edges based on circles
myAISContext->OpenLocalContext();
myAISContext->ActivateStandardMode(TopAbs_EDGE);
Handle(StdSelect_EdgeFilter) EdgeFilter = new
StdSelect_EdgeFilter(StdSelect_Circle);
myAISContext->AddFilter(EdgeFilter);
Application Framework
I - OCAF Overview
What Is OCAF
OCAF is an Application Framework
which increases the productivity of
development significantly.
OCAF provides a solution for structurization
and handling of Application Data, based on
the Application / Document architecture.
Because OCAF can handle data and
algorithms from Open CASCADE libraries, it
is the logical complement of these libraries.




OCAF Advantages
Development task
Geometry creation
Data organization
Saving data in a file
Application
infrastructure
Undo / Redo
Copy / Paste
Without
OCAF
To
To
To
To
With OCAF
do
do
do
do
To do
Simplified
Provided
Provided
To do
To do
Provided
Provided
OCAF Architecture


An OCAF application manages a document
which contains a specific hierarchical
structure.
Application data is attached to this structure
in the form of attributes.
OCAF Services

OCAF assures the following services :






Document management : an OCAF application
manages the creation of documents
Associativity between data, in the sense of
sharing data between objects
Undo / Redo mechanism applied on the
commands
Persistence : saving and restoring documents
Modification of document and recomputation of
data
Library of ready to use basic objects for
CAD/CAM
Basic Concepts



APPLICATION : An application manages the
lifecycle (new, close) and the persistence of
documents (open, save, save as).
DOCUMENT : A document is produced by an
application. It is a container of specobjects. Each
specobject has a unique identifier in the document.
SPECOBJECT : A specobject is a set of
specifications defining one object. For example, a
specobject may contain the form, the name, the
color ... of a single object.



ATTRIBUTE : An attribute is one characteristic
(or view) of an object such as its name, or its
form. A specobject is defined by a set of attributes.
An attribute is defined by a type and a value.
REFERENCE KEY : The reference key is an
invariant reference which may refer to any type of
data used in an application. In its transient form it
is a label in the data framework, and the data is
attached to it in the form of attributes. In its
persistent form it is an entry of the label. The
entry allows you to retrieve data from a previous
session.
LABEL : The label is the identifier of a specobject
within the document. It can be seen as a private
address of a specobject within a document.

GUID or ID : The Global Universal
Identifier is an absolutely unique number.
OCAF uses IDs in several cases. One of
them is to characterize a type of attribute.



COMMAND : A command is a set of
actions which allow to add, to remove or to
modify specobjects in the document. The
commands are specific to a type of
document.
UNDO/REDO : The Undo/Redo
mechanism is applied on the commands.
COPY/PASTE : The Copy/Paste
mechanism allows copying of data within a
document or between documents.
Specobject Representation


A specobject is defined by a set of its attributes,
and is identified by a label in the document.
As soon as you know the label that identifies a
specobect, from that label you can retrieve an
attribute, and from the attribute you can retrieve
the value.

In OCAF, only one attribute with a given ID can be
attached to a single label. To allow several
attributes of the same type in the definition of a
specobject, sub-labels are used. These sub-labels
may contain complementary information,
arguments to construct the specobject, etc. Labels
and sub-labels are organized in the form of a tree :
•As you may see
on the diagram
the "Shape"
attribute is
associated with
the first label and
the first sub-label.
Command Mechanism

In OCAF, the modifications of documents are
made within commands. Commands are based on
transactions mechanism that allows to undo / redo
changes. The following example illustrates the
steps of a command execution :
T = T0 :
The document contains 3
specobjects : A1, A2, A3
T = T1 :
Open a command to modify
some specobjects
Finalizing A Command

At this step, two choices are possible commit the command or abort it :


T = T2 :
Commit the Command
Values generated in the command are validated.
Delta for Undo is generated.

When you commit the command, A’1
becomes the usual value within the
document. A1 gets to the delta which
contains the list of the modifications
associated with the time.



T = T2 :
Abort the Command
Values generated in the command are lost. The
document restores the initial state
When you abort the command, the document gets
back in its initial state (T=T0). This can be useful
if some errors are generated during the
modifications. By aborting the command, the
initial values are recovered.


The undo/redo mechanism is available for a
command :
After the Undo, A1 becomes the usual value
again and A’1 gets to the delta.
II - Components

Overview
Application
Document
Label
Attribute
Data Storage
III - Ready to use attributes

OCAF provides a set of ready-to-use attributes
which represent typical data used in CAD. These
include :




Standard attributes : provide functionality to work
with basic data types, such as numeric values, strings
etc.
Shape attributes : provide functionality to work with
Open CASCADE shapes, such as naming information
and tracking of shape evolution
Presentation attributes : provide functionality to
work with Application Interactive Services (AIS)
Function attributes : implement the function
mechanism of OCAF
Standard Attributes
Shape Attributes

NamedShape

Tracking Shape Evolution
Presentation Attributes
IV - Modification And
Regeneration
Organisation Attribute
Recomputation Attribute
Evaluation Of Selection
Download