Design choice, OCAF data

karim

CAD community veteran
I have many data structures for my fem program. For example, I have a Rectangular section which is defined by Width and Height. and It has several properties such as Area, Ixx, Iyy and so on.

It seems to me that there are two choices that can be used. One is like this

Code:
class IData
{
  private:
   TDF_Label root;
   TDF_Label t2;
   TDF_Label t3;
   TDataStd_RealArray prop; //(A, A2s, A3s, J, I22, I33, S22, S33, R22, R33)
public:
   IData(const TDF_Label& label) : root(label)
   {
     TDataStd_Name::Set(label, "Rectangle");
     t2 = label.FindChild(1);
     t3 = label.FindChild(2);
   }
   IData(const TDF_Label& label, float T2, float T3) : root(label)
   {
     TDataStd_Name::Set(label, "Rectangle");
     t2 = label.FindChild(1);
     t3 = label.FindChild(2);
     TDataStd_Name::Set(t2, "Width");
     TDataStd_Name::Set(t3, "Height");
     TDataStd_Real::Set(t2, double(T2));
     TDataStd_Real::Set(t3, double(T3));
     // also fill in the properities A, ...
   }

   float getT2(){} // get T2
   float getT3(){} // get T3
   double getA() {}
   double getJ() {}
   double getI22() {}
   double getI33() {}
   double getR22() {}
   double getR33() {} // and so on ...
};

The other is to subclass TDF_Attribute:

Code:
class IData : public TDF_attribute
{
...
}

which I dont know exactly how to do.

Which one is better do you think ?
I have a few hundred of these data structures. For example cross section can be rectangle, circular, T shaped, general and so on.
Then there is the material classes, isometric, linear, nonlinear and so on
and many other objects. Which method makes more sense ?
 
Last edited by a moderator:

Quaoar

Administrator
Staff member
@karim Both approaches are fine, but if you have tons of objects like this, it might be reasonable to avoid having too many labels and prefer using custom attributes. I would say, the main metric here is the memory overhead. However, custom attributes come at their own price. They start to be painful for non-primitive types as you'll have to provide storage & retrieval "drivers" to make your attributes work at Save & Open. However, that does not seem to be your case.

Personally, I use custom attributes only when I have to, and follow your 1-st approach most of the time. You may want to start with a simple approach having all scalar types in arrays/sublabels and then check if memory is a real problem or not.
 

Quaoar

Administrator
Staff member
@karim Regarding inheritance, you can inherit interfaces if you want, but at the level of OCAF data chunks, there's no such a thing as a "derived object" as there are no objects. Just like in a relational database, you might have similar tables of data, but they are different tables anyway.
 
Top