open access web page header

Sample Code

Some very simple code is shown below with comments. The sample code is broken into the basic steps - initializing the boolean, initializing the OA region query, opening an OA design and view, setting up the boolean parameters, selecting the operands, defining the type of boolean operation and executing the query that returns the results.

Initialization


oaInt4 ret;

// Initializing the function causes it to get a license.
// should initialization call the error handler and print the error.
if(acsOaShapeQuery::acsOaBoolInit(execPath)){ 
printf(acsOaShapeQuery::acsOaGetLastErr(&ret)); 
return;
}

// Create an object of acsOaShapeQuery
acsOaShapeQuery * shape_query = new acsOaShapeQuery();

// Initialize oaRegionQuery (Open Access Class)
try{
oaString str;
oaRegionQuery::init("oaRQXYTree");
assert( (oaRegionQuery::getPlugInName(str), str) == "oaRQXYTree");

}
catch(oaException e){
printf(e.getMsg());
return;
}

// OA Design Init Function (required by OA)
oaDesignInit(); 
oaLib *myOaLib;
oaTech *myOaTech;

// Open the OA library and OA technology
oaScalarName mySLibName(nameSpace, “inputOAlib”);
try{
myOaLib = oaLib::open(mySLibName, 
                      "./inputOAlib", 
                      "inputOAlib", 
                       oacSharedLibMode);
myOaTech = oaTech::open(mySLibName);
}

catch(oaException e){
printf(e.getMsg());
return;
}

// Get the grid information from oaTech
oaDouble grid = 
  1.0 / myOaTech->getDBUPerUU(oaViewType::get(oacMaskLayout));


Query Set Up

Prior to performing a region query, we need to set up the parameters the boolean will be using. The boolean's default parameters are stored in an object called acsBoolSettings.

// Create an object of acsBoolSettings
// this contains the parameters (except for the operands
// and operator) needed by acsOAbool.
// myBoolSettings contains default parameters ...
acsBoolSettings myBoolSettings;

// Set the Boolean Settings
shape_query->acsOaBoolSetModifiers(myBoolSettings);
shape_query->acsOaSetGrid(grid);

// Set the thread number to 2
// assuming I have two CPU's to use
shape_query->acsOaSetThreadNum(2); 

// Turn the preprocess flag on
shape_query->acsOaSetPreProcess(true);
 


// Define the cellname and viewname we wish to use.
oaScalarName cellName(nameSpace, "top");
oaScalarName viewName (nameSpace, "layout");

// Open the structure’s design from the OA library
oaDesign * design = 
  oaDesign::open(mySLibName, 
                 cellName, 
                 viewName, 
                 oaViewType::get(oacMaskLayout),'r');


Single (Primary) Operand Query

In this first example, we are going to perform a union operation on all the polygons contained within a single layer. If you are using demo8 as your example data we will use the data on layer/purpose pair 1,0. We wish to return the results to layer/purpose pair 101,0. Not all boolean operations can operate on a single operand. For example, operations such as XOR, MINUS, AND all require two operands.

// Create the primary acsOaLayerPurposePair set
oaInt4 layerCount1= 1;
acsOaLayerPurposePair ** 
set1 = (acsOaLayerPurposePair **) 
malloc(sizeof(acsOaLayerPurposePair *) * layerCount1);
set1[0] = new acsOaLayerPurposePair(1, 0);

// Set the target layer/purpose to 101,0
// because I want my results on layer 101 
shape_query->acsOaSetTarget(101, 0); 

// Set the boolean operation to Union (1)
shape_query->acsOaBoolSetOperator(1);

// Set the primary operand
shape_query->acsOaBoolSetPrimary(set1, layerCount1);

// Start the Query (this will pass the queried/booleanized 
// shapes to acsOaQueryShape)
shape_query->query(design, oaBox(-227,-33,1323,376), 0, 0, 10);


Primary and Secondary Operand Query

In this example we have two operands - layer/purpose pair 1,0 and layer/purpose pair 6,0 and we want to perform an XOR operation to get the difference and returning the results on layer/purpose pair 106,0.

// Create primary & secondary acsOaLayerPurposePair sets
oaInt4 layerCount1= 1;
acsOaLayerPurposePair ** 
      set1 = (acsOaLayerPurposePair **) 
      malloc(sizeof(acsOaLayerPurposePair *) * layerCount1);

set1[0] = new acsOaLayerPurposePair(1, 0);


oaInt4 layerCount2= 1;
acsOaLayerPurposePair ** 
       set2 = (acsOaLayerPurposePair **) 
       malloc(sizeof(acsOaLayerPurposePair *) * layerCount2);

set2[0] = new acsOaLayerPurposePair(6, 0);


// Set the target layer/purpose to 101,0
// because I want my results on layer 101 
shape_query->acsOaSetTarget(106, 0); 


// Set the primary/secondary operand
shape_query->acsOaBoolSetPrimary(set1, layerCount1);
shape_query->acsOaBoolSetSecondary(set2, layerCount2);

// Set the boolean operation to XOR (3)
shape_query->acsOaBoolSetOperator(3);

// Start the Query (this will pass the queried/booleanized
// shapes to acsOaQueryShape)
shape_query->query(design, oaBox(-227,-33,1323,376), 0, 0, 10);


Clean Up

// Close the OA library and OA tech
if(myOaLib)
myOaLib->close();
myOaLib = NULL;

if(myOaTech)
myOaTech ->close();
myOaTech = NULL;

// Delete the acsOaShapeQuery object
if(shape_query)
delete shape_query;
shape_query = NULL;

// Return the acsOaBool License
acsOaShapeQuery::acsOaBoolClose();




OA Main Page API Download Revision History Sample Code


ARTWORK CONVERSION SOFTWARE, INC.       Company Profile
417 Ingalls St., Santa Cruz, CA 95060    Tel (831) 426-6163     Fax 426-2824    email: info@artwork.com