Saturday, March 14, 2009

Line is not a driver, but is a function

Yesterday I said that OCAF code is to be replaced. At that moment the code that creates shapes (TopoDS_Shape) was a part of the OCAF tree but right now is removed. The code is mainly the same, and the code is ported to the new infrastructure. I was blocked a bit by a tricky build issue (thanks bxtrx for fix!).

How do you add an extra shape?

Define the dependency that says which data is needed for your shape:
public class LineDependency : DependencyBase
public LineDependency() : base("Line")
AddAttributeType(1, "Geometry");
AddAttributeType(2, "Geometry");

This class say that a line will need two geometry points, defined as children 1 and 2.

The OpenCascade function that defines your shape is the following:

public class LineFunction : FunctionBase
public LineFunction() : base("Line")
Dependency = DependencyFactory.Instance.GetDependency();

public override int Execute()
// Get the values of dimension and position attributes
OCgp_Pnt firstPoint = Dependency.Child(1).Geometry;
OCgp_Pnt secondPoint = Dependency.Child(2).Geometry;

OCTopoDS_Edge aEdge = new OCBRepBuilderAPI_MakeEdge(firstPoint, secondPoint).Edge();
var shape = new OCBRepBuilderAPI_MakeWire(aEdge).Wire();
var shapeInterpreter = Parent.UpdateInterpreter();
shapeInterpreter.Shape = shape;
return 0;

And before using any of them, register them to be known globally:

No comments: