Geometric Modeler |
Geometry |
How to Create an AttributeImplementing and creating an attribute |
Use Case |
AbstractAn attribute is a piece of information intended to be added to an object. Prior to adding an attribute to an object you must implement this attribute. |
The use case creates an attribute an add it to objects. The attribute implementation is defined in the CAAGobAttribute.m module.
[Top]
CAAGobAttributeCreation is a use case of the CAAGeometricObjects.edu framework that illustrates GeometricObjects framework capabilities.
[Top]
This use case creates two PLines. An attribute is added to these geometries.
[Top]
To launch CAAGobAttributeCreation, you will need to set up the build time environment, then compile CAAGobAttributeCreation.m and CAAGobAttribute.m along with their prerequisites, set up the run time environment, and then execute the use case [1].
If you simply type CAAGobAttributeCreation with no argument, the use case executes, but doesn't save the result in an NCGM file. If you want to save this result, provide the full pathname of the NCGM file to create. For example:
With Windows CAAGobCreation e:\AttCreation.NCGM
With UNIX CAAGobCreation /u/AttCreation.NCGM
This NCGM file can be displayed using the CAAGemBrowser use case.
[Top]
The CAAGobAttributeCreation use case is made of a main named CAAGobAttributeCreation.cpp located in the CAAGobAttributeCreation.m module of the CAAGeometricObjects.edu framework:
Windows |
InstallRootDirectory\CAAGeometricObjects.edu\CAAGobAttributeCreation.m\ |
Unix |
InstallRootDirectory/CAAGeometricObjects.edu/CAAGobAttributeCreation.m/ |
where InstallRootDirectory
is the directory where the CAA
CD-ROM is installed.
The use case uses a class defined in the CAAGobAttribute.m module.
[Top]
The main program peforms the following steps:
[Top]
The geometry factory (CATGeoFactory) creates and manages all the
CATICGMObject (and the curves and surfaces in particular). This creation is
done by the global function ::CATCreateCGMContainer
. Notice that
the factory can be defined by reading a NCGM file that was previously stored.
In that case, the global function ::CATLoadCGMContainer
must be
used.
CATGeoFactory* piGeomFactory = ::CATCreateCGMContainer() ; if (NULL==piGeomFactory) return (1); |
[Top]
A CATPLine is a line in the space of a surface, whatever the surface is. To create a CATPLine, one must specifies the starting and end points: these points are expressed in terms of parameters on the surface. No assumption must be made on the parameterization of the surface. The ways to define a CATSurParameter are:
CATSurface::GetParam
method (only for canonical
surfaces and a point that is known to be on the surface)CATSurface::GetLimits
)
of the surface: this way is illustrated below.Now, the CATPLines can be created by using the
CATGeoFactory::CreatePLine
method.
// (c) --- Create a first PLine on piGeoPlane (geometric plane // CATPLine * piPline1 = NULL; { CATSurParam iStartParam1 ( 0,0 , piGeoPlane->GetParamReference() ) ; CATSurParam iEndParam1 ( 0,80, piGeoPlane->GetParamReference() ) ; piPline1 = piGeomFactory->CreatePLine(iStartParam1,iEndParam1,piGeoPlane); if (NULL==piPline1 ) { ::CATCloseCGMContainer(piGeomFactory); return (1); } } |
[Top]
This operation is done by the CATCGMAttrId::FindAttrId static method which takes as its arguments the attribute name and the logical name of the load module containing the attribute implementation.
Go to the CAAGobAttribute.m module and take a look at the CAAGobAttributeManagement.cpp file which implements the CAAGobAttributeManagement attribute type. The attribute name is the first argument of the CATCGMImplAttribute macro (i.e. CAAGobAttributeManagement) while the CAAGobAT is a string allowing the system to access the load module which contains your implementation.
CATCGMImplAttribute(CAAGobAttributeManagement, CATCGMStreamAttribute, CAAGobAT, 1); |
Important:
You must declare the domain name (CAAGobAT) both in the dictionary (CAAGeometricObjects.edu.dico) and in the AppDef macro. In the present use case, the AppDef declaration is located in a separate file but you could gather all declarations into CAAGobAttributeManagement.cpp. If you need implement several attribute types, you can choose to gather all declarations in the same file as well and use a single AppDef declaration.
// (a) --- Find the attribute identifier // const char* iAttr = "CAAGobAttributeManagement"; const char* iDomainName = "CAAGobAT"; const CATCGMAttrId* pAttrId = CATCGMAttrId::FindAttrId(iAttr,iDomainName) ; |
[Top]
This operation can be done in two ways:
CAAGobAttributeManagement * piAttr1 =(CAAGobAttributeManagement *) CATCGMAttribute::CreateAttribute(pAttrId); |
[Top]
The attribute is assigned a value. The SetValue method is defined in the attribute implementation. Then the attribute is added to each PLines.
// (c) --- Set its value to 2 // The SetValue method is defined in the CAAGobAttribute.m module // piAttr1->SetValue(2); // (d) --- Add it to the piPline1 and piPline2 CATPlines // piPline1->PutAttribute(piAttr1); piPline2->PutAttribute(piAttr1); |
You can cut the reference to an object by using the ReleaseAttribute method applied to the geometry you want to remove the attribute from. In the extract below, at first the number of objects pointed to by the attribute is 2. We check the new number of references after one reference has been cut.
// (e) --- Retrieve the number of references // cout << "Number of objects pointed to by the attribute: (2 expected)"; cout << piAttr1->GetNbAttrRef() << endl; // (f) --- Release the link between the attribute and piPline2 // piPline2->ReleaseAttribute(piAttr1); // (g) --- Retrieve the new number of references // cout << "---------------------------------- " << endl; cout << "After ReleaseAttribute on piPline2 " << endl; cout << "Number of objects pointed to by the attribute: (1 expected)"; cout << piAttr1->GetNbAttrRef() << endl; |
[Top]
To save the model in a file, the ::CATSaveCGMContainer
global
function is used. Notice that in the use case, the save is conditioned by an
input parameter representing the file inside which the model must be saved.
The use case ends with the closure of the geometry factory, done by the
::CATCloseCGMContainer
global function.
if(1==toStore) { #ifdef _WINDOWS_SOURCE ofstream filetowrite(pfileName, ios::binary ) ; #else ofstream filetowrite(pfileName,ios::out,filebuf::openprot) ; #endif ::CATSaveCGMContainer(piGeomFactory,filetowrite); filetowrite.close(); } // // Closes the container // ::CATCloseCGMContainer(piGeomFactory); |
[Top]
The use case illustrates how to create and use CGM attributes.
[Top]
[1] | Building and Launching a CAA V5 Use Case |
[Top] |
Version: 1 [Apr 2000] | Document created |
[Top] |
Copyright © 2000, Dassault Systèmes. All rights reserved.