Saturday, March 14, 2009

Port is (almost) complete

The porting of OCAF Tree to the NaroData.Node is done. At least works functionally equivalent with old implementation. Some things are missing still, but it starts, and runs (well).

The other achievement is how is the Action2D and Action3D are done. They are use directly the defined Dependency (in past was named as Schema) and they not work against the nodes. This will make that most complex actions to not write nodes that do not belong to their predefined usage.

So this is the new extrude code (which is a pretty complex action):

public static void Extrude(Node L, Node shape, double extrusionHeight, ExtrusionTypes extrusionType)
{
FunctionInterpreter function = L.Update<FunctionInterpreter>();
function.Name = "Extrude";

// Attach the shape on which the Extrusion is applied as the first child label
function.Dependency.Child(1).Reference = shape;
// Add the extrusion height as a second child label
function.Dependency.Child(2).Real = extrusionHeight;
// Add the Extrusion Type as a third child label
function.Dependency.Child(3).Integer = (int)extrusionType;

L.Update<StringInterpreter>().Value = DisplayedShapeNames.Extrude;

if (function.Execute() != 0)
{
// TODO: Handle the error
}

// Attach an integer attribute to L to memorize it's not displayed
L.Update<IntegerInterpreter>().Value = (int)OcafObjectVisibility.ToBeDisplayed;
}

The old code?

public static OCTDF_Label Extrude(OCTDF_Label rootLabel, OCTDF_Label shape, double extrusionHeight, ExtrusionTypes extrusionType)
{
// Create a new child label on which the extrusion Label structure is generated
OCTDF_Label L = OCTDF_TagSource.NewChild(rootLabel);

// Attach the shape on which the Extrusion is applied as the first child label
OCTDF_Reference.Set(L.FindChild(1, true), shape);
// Add the extrusion height as a second child label
OCTDataStd_Real.Set(L.FindChild(2, true), extrusionHeight);
// Add the Extrusion Type as a third child label
OCTDataStd_Integer.Set(L.FindChild(3, true), (int)extrusionType);

// Add the operation name
OCTDataStd_Name.Set(L, new OCTCollection_ExtendedString(DisplayedShapeNames.Extrude));

// Instanciate a TFunction_Function attribute connected to the extrude driver
// and attach it to the data structure as an attribute of the Extrude Label
OCTFunction_Function.Set(L, OCAFExtrudeDriver.Guid);

// Initialize and execute the Extrude driver
OCTFunction_Logbook log = new OCTFunction_Logbook();

OCAFExtrudeDriver extrudeDriver = new OCAFExtrudeDriver();
// Find the ExtrudeDriver in the TFunction_DriverTable using its GUID
if (!OCTFunction_DriverTable.Get().FindDriver(OCAFExtrudeDriver.Guid, extrudeDriver, 0))
return null;

extrudeDriver.Init(L);
if (extrudeDriver.Execute(log) != 0)
{
// TODO: Handle the error
}

// Attach an integer attribute to L to memorize it's not displayed
OCTDataStd_Integer.Set(L, (int)OcafObjectVisibility.ToBeDisplayed);

return L;
}

The difference is in details, but the point is that the code is moved to the new infrastructure.

No comments: