Geometric Modeler

Geometry

How to Read an Attribute

Reading a streamed attribute

Use Case

Abstract

This use case explains how to read a CATCGMStreamAttribute. It is associated with the How to Create an Attribute article. Run this use case after you have run the CAAGobAttributeCreation use case. The file generated by the CAAGobAttributeCreation use case is to be used as input file for the CAAGobAttributeRead use case.


What You Will Learn With This Use Case

The use case explains how to read a CATCGMStreamAttribute. The attribute implementation is defined in the CAAGobAttribute.m module. The way it has to be created is explained in How to Create an Attribute.

[Top]

The CAAGobAttributeRead Use Case

CAAGobAttributeRead is a use case of the CAAGeometricObjects.edu framework that illustrates GeometricObjects framework capabilities.

[Top]

What Does CAAGobAttributeRead Do

This use case loads a file and scans the geometry to search for the attributes of a given type (CAAGobAttributeManagement) on a geometry of a given type (PLineType).

[Top]

How to Launch CAAGobAttributeRead

To launch CAAGobAttributeRead, you will need to set up the build time environment, then compile CAAGobAttributeRead.m and CAAGobAttribute.m along with their prerequisites, set up the run time environment, and then execute the use case [1].

You must type CAAGobAttributeRead with an argument to execute the use case.

With Windows CAAGobCreation e:\AttToBeRead.NCGM

With UNIX CAAGobCreation /u/AttToBeRead.NCGM

AttToBeRead.NCGM is the file generated by CAAGobAttributeCreation.m

[Top]

Where to Find the CAAGobAttributeRead Code

The CAAGobAttributeRead use case is made of a main named CAAGobAttributeRead.cpp located in the CAAGobAttributeRead.m module of the CAAGeometricObjects.edu framework:

Windows InstallRootDirectory\CAAGeometricObjects.edu\CAAGobAttributeRead.m\
Unix InstallRootDirectory/CAAGeometricObjects.edu/CAAGobAttributeRead.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]

Step-by-Step

The main program peforms the following steps:

[Top]

Loading the File to Be Read

The geometry factory (CATGeoFactory) creates and manages all the CATICGMObject (and the curves and surfaces in particular). In this use case, the factory is defined by reading a NCGM file that was previously stored,  the global function ::CATLoadCGMContainer must be used to retrieve the factory.

CATGeoFactory* piGeomFactory = CATLoadCGMContainer(filetoread);

[Top]

Looping through the Geometry

Here are the step to follow in order to read specific attributes in a geometry.

  1. scan the geometry by using the CATICGMContainer::Next method.
  2. for each objects sanned by the loop, retrieve the persistent tag by using the CATGeometry::GetPersistentTag method.
  3. for each geometry, retrieve the CATICGMObject by using the CATGeometry::FindObjectFromTag method
  4. for each CATICGMObject , retrieve the appropriate attribute by using the CATICGMObject ::GetAttribute method.
  5. use the GetValue method applied to the retrieved attribute to read the attribute value.
// (b) --- Loop through the geometry
//
...
for (piCurG = piGeomFactory->Next(NULL,CATPLineType);
piCurG != NULL;
piCurG = piGeomFactory->Next(piCurG)) 
  {
    // Find the PLine from its persistent tag
    //
    curtag = piCurG->GetPersistentTag();
    CATICGMObject * piCGMObj = piGeomFactory->FindObjectFromTag(curtag);
    if (piCGMObj == NULL)
	{
	  cout << "No object with the specified tag" <<endl;
			return 1;
	}

    // Retrieve the CATCGMAttribute from its identifier
    //
    CATCGMAttribute * piActAttr = piCGMObj->
    GetAttribute(UAIDPtr(CAAGobAttributeManagement));

    // No searched attribute found on the PLine 
    //
   if (NULL == piActAttr)
	{
            cout << "------------------------------------------------- " << endl;
	   cout << "PLine with no CAAGobAttributeManagement attribute " << endl;
	}

    // The searched attribute found on the Pline
    //
    else
	{
	   cout << "------------------------------------------------- " << endl;
	   cout << "PLine with CAAGobAttributeManagement attribute    " << endl; 
		
            CAAGobAttributeManagement * iPersAttr = NULL;
	   iPersAttr = (CAAGobAttributeManagement *) piActAttr;

            // Retrieve the attribute value 
            // See the CAAAttributeManagement module
	   // 
		if (iPersAttr)
		{
			long oPersval;
	          	iPersAttr->GetValue(oPersval);
		}
			else return 1;
           		cout << "----------------------------------- " << endl;		
		}
	}
	}

[Top]

Closing the Input File and the CGM Container

The use case ends with the closure of the file and the CGM container (done by the ::CATCloseCGMContainer global function).

filetoread.close();
CATCloseCGMContainer(piGeomFactory);

[Top]


In Short

The use case illustrates how to read attributes.

[Top]


References

[1] Building and Launching a CAA V5 Use Case
[Top]

History

Version: 1 [Apr 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.