Build applications

The following include files from the include folder of the EDM installation, %EDM_HOME%\include, have to be included:
extern "C" {
#include "sdai.h"
#include "cpp10_EDM_interface.h"
}
#include "container.h"

If you shall build an application using the "in memory" object option, you shall link with the following two libraries:

  • cpp10.lib – the cpp10 library
  • edmikit600.lib – EDM database interface


And in the application source you declare
using namespace OIM;

If you will build the "in database" object version you compile with preprocessor directive USE_EDMI set and link with the following libraries

  • cpp10_edmi.lib
  • edmikit600.lib


And in the application source declare
using namespace OID;
For both memory models compile and build with 64bits option.

Appendix A – OIM example
This example makes use of the Objects In Memory pattern.
The example is based on the AP209 schema and to prepare for running the example, one must perform the following use the EDMSupervisor:

  • Create a database by means

Database->Create

  • Compile the AP209 schema.

Schemata->DefineSchema

  • Generate C++ classes for the AP209 schema (files to be included in the VS project)

Schemata->GenerateInterface->Cpp2010 (specify namespace ap209)

  • Create a model (with name myModel)

Data->Create->Model

  • Close the database

Database->Close
Contents of the stdafx.h file:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
extern "C" {
#include "sdai.h"
#include "cpp10_EDM_interface.h"
}
#include "container.h"
using namespace OIM;
#include "ap209_multidisciplinary_analysis_and_design_mim_lf_entityTypes.h"
#include "ap209_multidisciplinary_analysis_and_design_mim_lf.hpp"
using namespace ap209;
// TestCppexpressApi_OIM.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#define newObject(className) new(m)className(m)
int _tmain(int argc, _TCHAR* argv[])
{
try{
EdmiError rstat;
SdaiInteger nbWarnings;
SdaiInteger nbErrors;
SdaiErrorCode sdaiError;
Database db("C:/edm/EDMinterface AP209-CPP/db","d","d");
db.open();
Repository cRepository(&db, "DataRepository");
ap209_Schema my_Schema = ap209_multidisciplinary_analysis_and_design_mim_lf_SchemaObject;
CMemoryAllocator ma(1000000);
Model myModel(&cRepository, &ma, &my_Schema);
myModel.open("myModel", sdaiRW);
Model *m = &myModel;
printf("\nMEMORY_MODEL : objects in memory.\n");
// Create product object and set its attributes
product* p1 = newObject(product);
p1->put_id("Aircraft 1");
p1->put_name("Aircraft propeller map");
p1->put_description("Aircraft 1");
printf("\nProduct Aircraft 1 created.");
// Create product_definition_formation object
product_definition_formation* pdf = newObject(product_definition_formation);
pdf->put_description("Aircraft with two front doors and wheel landing gear");
pdf->put_id("1");
// Link product_definition_formation object to product object
pdf->put_of_product(p1);
printf("\nVersion 1 for Product Aircraft 1 created.");
// Create product_definition object
product_definition* pd = newObject(product_definition);
pd->put_description("description");
// Link product_definition object to
// product_definition_formation object
pd->put_formation(pdf);
pd->put_id("pd-1");
printf("\nProduct definition pd-1 for Version 1 created.");
// Create a property
property_definition *prop_def_1= newObject(property_definition);
prop_def_1->put_name("Prop1");
// set the definition attribute beeing the product definition from above
prop_def_1->put_definition(pd);
// Retrieve the proprty definition and exemplify how is processed
// based on the retrieved type.
entityType objectType;
void* obj = prop_def_1->get_definition(&objectType);
if(objectType == et_product_definition){
product_definition mypd = (product_definition)obj;
product *myp = mypd->get_formation()->get_of_product();
printf("\nProperty 1 is connected to product: %s",myp->get_id());
} else if(objectType == et_characterized_object){
// handle characterized_object
} else if(objectType == et_product_definition_shape){
// handle product_definition_shape
} else if(objectType == et_shape_aspect){
// handle shape_aspect
} else if(objectType == et_shape_aspect_relationship){
// handle shape_aspect_relationship
} else if(objectType == et_product_definition_relationship){
// handle product_definition_relationship
} else {
throw new CedmError(sdaiETYPEUNDEF);
}
// Create another property and attach it to a characterized_object
property_definition *prop_def_2= newObject(property_definition);
prop_def_2->put_name("Prop2");
characterized_object *co = newObject(characterized_object);
co->put_name("co1");
prop_def_2->put_definition(co);
// Retrieve the proprty definition and exemplify how is processed
// based on the retrieved type. obj = prop_def_2->get_definition(&objectType);
if(objectType == et_product_definition){
// handle product_definition
} else if(objectType == et_characterized_object){
characterized_object myco = (characterized_object)obj;
printf("\nProperty 2 is connected to characterized_object: %s",myco->get_name());
} else if(objectType == et_product_definition_shape){
// handle product_definition_shape
} else if(objectType == et_shape_aspect){
// handle shape_aspect
} else if(objectType == et_shape_aspect_relationship){
// handle shape_aspect_relationship
} else if(objectType == et_product_definition_relationship){
// handle product_definition_relationship
}else {
throw new CedmError(sdaiETYPEUNDEF);
}
// The code below shows how to create curve_element_freedom selects
// and put then into the attribute release_freedom of //_curve_element_end_release_packet objects
// By new(m), the selects are created in memory controlled Models
// The m after enumerated_curve_element_freedom_X_ROTATION is necessary
// beacause enumerated_curve_element_freedom_X_ROTATION must be translated
// to the corresponding instance identifier in the underlying database.
curve_element_freedom *cef1;
cef1 = new(m)curve_element_freedom(enumerated_curve_element_freedom_X_ROTATION, m);
curve_element_freedom *cef2;
cef2 = new(m)curve_element_freedom("application defined degree of fredom",m);
curve_element_end_release_packet * ceerp1;
ceerp1 = newObject(curve_element_end_release_packet);
ceerp1->put_release_freedom(cef1);
curve_element_end_release_packet * ceerp2;
ceerp2 = newObject(curve_element_end_release_packet);
ceerp2->put_release_freedom(cef2);
// SET example
// First create another product
product* p2 = newObject(product);
p2->put_id("Aircraft 2");
p2->put_name("Aircraft propeller map");
p2->put_description("Aircraft 2");
printf("\nProduct Aircraft 2 created.");
// Allocate SET OF products
Set<action_items> prodSet = new(&ma) Set<action_items*>(&ma, sdaiINSTANCE, 2);
// Add the two products already created
prodSet->add(p1,&ma);
prodSet->add(p2,&ma);
// Assign set to attribute items of applied_action_assignment
applied_action_assignment *aaa = newObject(applied_action_assignment);
aaa->put_items(prodSet);
// ITERATORS :
// Iterator for the set of products
printf("\n\nProducts in set:");
Iterator<product*, entityType> prodIter(prodSet);
int i =0;
for(product *prod = prodIter.first(); prod; prod = prodIter.next()){
++i;
printf("\nElement : %d - %s",i,prod->get_id());
}
// References iterator
// Create a second product_definition_formation object
product_definition_formation* pdf2 = newObject(product_definition_formation);
pdf2->put_description("Aircraft with two front doors and wheel landing gear");
pdf2->put_id("2");
// Link product_definition_formation object to product object
pdf2->put_of_product(p1);
printf("\nVersion 2 for Product Aircraft 1 created.\n");
// Find product_definition_formation objects that are refering to product p1
printf("\nFind product_definition_formation objects that are refering to product p1");
ReferencesIterator<product_definition_formation*, entityType> pdfIter(p1,et_product_definition_formation);
product_definition_formation *mypdf;
for(mypdf = pdfIter.first(); mypdf; mypdf = pdfIter.next()){
printf("\nVersion %s for product %s",mypdf->get_id(),mypdf->get_of_product()->get_id());
}
// Find first referencing of type product_definition_formation
mypdf = (product_definition_formation*)p1->getFirstReferencing(et_product_definition_formation);
printf("\nFirst referencing version for product %s is version %s\n",mypdf->get_of_product()>get_id(),mypdf>get_id());
// AllReferencesIterator iterator
// Create a product catgory and connect the products to it
product_related_product_category *prpc = newObject(product_related_product_category);
prpc->put_name("Product category 1");
prpc->put_products_element(p1);
prpc->put_products_element(p2);
// Find all referencing
printf("\nFind all referencing product p1");
entityType myType;
AllReferencesIterator <entityType> productRefs(p1);
for (void *obj = productRefs.first(&myType); obj; obj = productRefs.next(&myType)) {
if(myType == et_product_definition_formation){
product_definition_formation pdf = (product_definition_formation)obj;
printf("\nReferencing : version %s for product %s",pdf->get_id(),pdf->get_of_product()->get_id());
}
if(myType == et_product_related_product_category){
product_related_product_category cat = (product_related_product_category)obj;
printf("\nCategory : %s",cat->get_name());
}
}
// LIST example
List<STRING> theWeekDays(&ma, sdaiSTRING, 7);
theWeekDays.add("Sunday", &ma);
theWeekDays.add("Monday", &ma);
theWeekDays.add("Tuesday", &ma);
theWeekDays.add("Wednesday", &ma);
// ARRAY Examples
// Declare array of int with min index 5 and max index 15
Array<EDMLONG> arr(&ma, sdaiINTEGER, 5, 15);
// Initialize the array
for (EDMLONG i=5; i <= 15; i++) arr[i] = 100 + i;
// Print the array values
printf("\n\nInteger array :\n");
for (EDMLONG i=5; i <= 15; i++) {
printf("arr[%d] = %d\n", i, arr[i]);
}
// An example using ap209 euler_angles
parametric_volume_3d_element_coordinate_system *pv3d = newObject(parametric_volume_3d_element_coordinate_system);
Array<double>angles (&ma, sdaiREAL, 1, 3);
angles[1] = 2.71; angles[2] = 3.14; angles[3] = 6.58;
euler_angles *euang = newObject(euler_angles);
euang->put_angles(&angles);
pv3d->put_eu_angles(euang);
// The entity euler_angles have an array that is retrieved
// by the method ea->get_angles();
euler_angles *ea = pv3d->get_eu_angles();
Array<double> *myangles = ea->get_angles();
double angle1 = myangles->get(1);
double angle2 = myangles->get(2);
double angle3 = myangles->get(3);
printf("\n\nEuler angles : %f,%f,%f",angle1,angle2,angle3);
// Write objects in memory to database
m->writeAllObjectsToDatabase();
// Export the resulting population to step file.
rstat = edmiWriteStepFile("DataRepository",NULL,"myModel","C:/Temp/myStepFile.stp",NULL,NULL,0,8,&nbWarnings,&nbErrors,&sdaiError);
// Apply the next statement if you want to run more than one time.
//rstat = edmiDeleteModelContentsBN("DataRepository","myModel");
myModel.close();
} catch (CedmError *e) {
if (e->message) {
printf(e->message);
} else {
printf(edmiGetErrorText(e->rstat));
}
} catch (int thrownRstat) {
printf(edmiGetErrorText(thrownRstat));
}
printf("\n\nPress return to exit.");
char c = getchar();
return 0;
}

Appendix B – OID example
This example makes use of the Objects In Database pattern.
Apply the same steps as in Appendix A to prepare the database.
Contents of the stdafx.h file:
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
extern "C" {
#include "sdai.h"
#include "cpp10_EDM_interface.h"
}
#include "container.h"
using namespace OID;
#include "ap209_multidisciplinary_analysis_and_design_mim_lf_entityTypes.h"
#include "ap209_multidisciplinary_analysis_and_design_mim_lf.hpp"
using namespace ap209;
// TestCppexpressApi_OID.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
try{
EdmiError rstat;
SdaiInteger nbWarnings;
SdaiInteger nbErrors;
SdaiErrorCode sdaiError;
Database db("C:/edm/EDMinterface AP209-CPP/db","d","d");
db.open();
Repository cRepository(&db, "DataRepository");
ap209_Schema my_Schema = ap209_multidisciplinary_analysis_and_design_mim_lf_SchemaObject;
CMemoryAllocator ma(1000000);
Model myModel(&cRepository, &ma, &my_Schema);
myModel.open("myModel", sdaiRW);
Model *m = &myModel;
printf("\nMEMORY_MODEL : objects in database.\n");
product p1(m);
p1.put_id("Aircraft 1");
p1.put_name("Aircraft propeller map");
p1.put_description("Aircraft 1");
printf("\nProduct Aircraft 1 created.");
// Create product_definition_formation object
product_definition_formation pdf(m);
pdf.put_description("Aircraft with two front doors and wheel landing gear");
pdf.put_id("1");
// Link product_definition_formation object to product object
printf("\nVersion 1 for Product Aircraft 1 created.");
pdf.put_of_product(&p1);
// Create product_definition object
product_definition pd(m);
pd.put_description("description");
// Link product_definition object to
// product_definition_formation object
pd.put_id("pd-1");
pd.put_formation(&pdf);
printf("\nProduct definition pd-1 for Version 1 created.");
// Create a property
property_definition prop_def_1(m);
prop_def_1.put_name("Prop1");
// set the definition attribute beeing the product definition from above
prop_def_1.put_definition(&pd);
// Retrieve the proprty definition and exemplify how is processed
// based on the retrieved type.
entityType objectType;
void* obj = prop_def_1.get_definition(&objectType);
if(objectType == et_product_definition){
product_definition mypd = (product_definition)obj;
product *myp = mypd->get_formation()->get_of_product();
printf("\nProperty 1 is connected to product: %s",myp->get_id());
} else if(objectType == et_characterized_object){
// handle characterized_object
} else if(objectType == et_product_definition_shape){
// handle product_definition_shape
} else if(objectType == et_shape_aspect){
// handle shape_aspect
} else if(objectType == et_shape_aspect_relationship){
// handle shape_aspect_relationship
} else if(objectType == et_product_definition_relationship){
// handle product_definition_relationship
} else {
throw new CedmError(sdaiETYPEUNDEF);
}
// Create another property and attach it to a characterized_object
property_definition prop_def_2(m);
prop_def_2.put_name("Prop2");
characterized_object co(m);
co.put_name("co1");
prop_def_2.put_definition(&co);
// Retrieve the proprty definition and exemplify how is processed
// based on the retrieved type.
obj = prop_def_2.get_definition(&objectType);
if(objectType == et_product_definition){
// handle product_definition
} else if(objectType == et_characterized_object){
characterized_object myco = (characterized_object)obj;
printf("\nProperty 2 is connected to characterized_object: %s",myco->get_name());
} else if(objectType == et_product_definition_shape){
// handle product_definition_shape
} else if(objectType == et_shape_aspect){
// handle shape_aspect
} else if(objectType == et_shape_aspect_relationship){
// handle shape_aspect_relationship
} else if(objectType == et_product_definition_relationship){
// handle product_definition_relationship
}else {
throw new CedmError(sdaiETYPEUNDEF);
}
// The code below shows how to create curve_element_freedom selects
// and put then into the attribute release_freedom of //_curve_element_end_release_packet objects
// By new(m), the selects are created in memory controlled Models
// The m after enumerated_curve_element_freedom_X_ROTATION is necessary
// beacause enumerated_curve_element_freedom_X_ROTATION must be translated
// to the corresponding instance identifier in the underlying database.
curve_element_freedom *cef1;
cef1 = new(m)curve_element_freedom(enumerated_curve_element_freedom_X_ROTATION, m);
curve_element_freedom *cef2;
cef2 = new(m)curve_element_freedom("application defined degree of fredom",m);
curve_element_end_release_packet ceerp1(m);
ceerp1.put_release_freedom(cef1);
curve_element_end_release_packet ceerp2(m);
ceerp2.put_release_freedom(cef2);
// SET example
// First create another product
product p2(m);
p2.put_id("Aircraft 2");
p2.put_name("Aircraft propeller map");
p2.put_description("Aircraft 2");
printf("\nProduct Aircraft 2 created.");
// Allocate SET OF products
Set<action_items> prodSet = new(&ma) Set<action_items*>(m, sdaiINSTANCE, 2);
// Assign set to attribute items of applied_action_assignment
applied_action_assignment aaa(m);
aaa.put_items(prodSet);
// Add the two products already created
prodSet->add(&p1);
prodSet->add(&p2);
// ITERATORS
// Iterator for the set of products
printf("\n\nProducts in set:");
product *prod1 = NULL;
product *prod2 = NULL;
entityType mytype;
int i = 0;
Iterator<product*, entityType> prodIter(aaa.get_items());
for(product *prod = prodIter.first(); prod; prod = prodIter.next()){
printf("\nElement : %s",prod->get_id());
++i;
if(i ==1)
// A clone that is present after the loop
prod1 = (product)m->clone(prod,(int)&mytype);
if(i ==2)
// A clone that is present after the loop
prod2 = (product)m->clone(prod,(int)&mytype);
}
printf("\nProduct 1 after iteration: %s",prod1->get_id());
printf("\nProduct 2 after iteration: %s",prod2->get_id());
// ReferencesIterator
// Create a second product_definition_formation object
product_definition_formation pdf2(m);
pdf2.put_description("Aircraft with two front doors and wheel landing gear");
pdf2.put_id("2");
// Link product_definition_formation object to product object
pdf2.put_of_product(&p1);
printf("\nVersion 2 for Product Aircraft 1 created.\n");
// Find product_definition_formation objects that are refering to product p1
printf("\nFind product_definition_formation objects that are refering to product p1");
ReferencesIterator<product_definition_formation*, entityType> pdfIter(&p1,et_product_definition_formation);
product_definition_formation *mypdf;
for(mypdf = pdfIter.first(); mypdf; mypdf = pdfIter.next()){
printf("\nVersion %s for product %s",mypdf->get_id(),mypdf->get_of_product()->get_id());
}
// Find first referencing of type product_definition_formation
mypdf = (product_definition_formation*)p1.getFirstReferencing(et_product_definition_formation);
printf("\nFirst referencing version for product %s is version %s\n",mypdf->get_of_product()>get_id(),mypdf>get_id());
// AllReferencesIterator iterator
// Create a product catgory and connect the products to it
product_related_product_category prpc(m);
prpc.put_name("Product category 1");
prpc.put_products_element(&p1);
prpc.put_products_element(&p2);
// Find all referencing
printf("\nFind all referencing product p1");
entityType myType;
AllReferencesIterator <entityType> productRefs(&p1);
for (void *obj = productRefs.first(&myType); obj; obj = productRefs.next(&myType)) {
if(myType == et_product_definition_formation){
product_definition_formation pdf = (product_definition_formation)obj;
printf("\nReferencing : version %s for product %s",pdf->get_id(),pdf->get_of_product()->get_id());
}
if(myType == et_product_related_product_category){
product_related_product_category cat = (product_related_product_category)obj;
printf("\nCategory : %s",cat->get_name());
}
}
// ARRAY Examples
// An example using ap209 euler_angles
parametric_volume_3d_element_coordinate_system pv3d(m);
Array<double>angles (m, sdaiREAL, 1, 3);
euler_angles euang(m);
euang.put_angles(&angles);
pv3d.put_eu_angles(&euang);
// Please note that the assignment of values to angles must occur after array has been
// assigned to an instance already created in the database.
angles.put(1,2.71);
angles.put(2,3.14);
angles.put(3,6.58);
// The entity euler_angles have an array that is retrieved
// by the method ea->get_angles();
euler_angles *ea = pv3d.get_eu_angles();
Array<double> *myangles = ea->get_angles();
double angle1 = myangles->get(1);
double angle2 = myangles->get(2);
double angle3 = myangles->get(3);
printf("\n\nEuler angles : %f,%f,%f",angle1,angle2,angle3);
// INHERITANCE example :
// First create a representation_context and three objects that all are subtypes of
// representation namely a node, fea_model_3d and explicit_element_representation
printf("\n\nInheritance:");
representation_context rep_ctx(m);
rep_ctx.put_context_identifier("Context1");
node n(m);
n.put_name("Node 1");
n.put_context_of_items(&rep_ctx);
fea_model_3d feam(m);
feam.put_name("Feam 1");
feam.put_creating_software("Lorentz developed the software");
feam.put_context_of_items(&rep_ctx);
explicit_element_matrix elm(m);
matrix_property_type mpt;
mpt.setString("Property type");
elm.put_property_type(&mpt);
explicit_element_representation eep(m);
eep.put_name("explicit_element_representation 1");
eep.put_matrix(&elm);
eep.put_context_of_items(&rep_ctx);
// Then get the representations attached to the context
// and handle them separately
Set<representation*> *reps;
reps = rep_ctx.get_representations_in_context();
entityType repType;
Iterator<representation*, entityType> repIter(reps);
for (representation* rep = repIter.first(&repType); rep; rep = repIter.next(&repType)) {
printf("\nObject name : %s",rep->get_name());
if (repType == et_node) {
node mynode = (node)rep;
printf("\nNode : %s",rep->get_name());
}
if (repType == et_fea_model_3d) {
fea_model_3d myfeam = (fea_model_3d)rep;
printf("\nfea_model_3d : %s",rep->get_name());
printf("\nfea_model_3d software: %s",myfeam->get_creating_software());
}
if (repType == et_explicit_element_representation) {
explicit_element_representation myeet = (explicit_element_representation)rep;
printf("\nexplicit_element_representation : %s",rep->get_name());
explicit_element_matrix *myeem = myeet->get_matrix();
matrix_property_type *mympt = myeem->get_property_type();
char *mychar = mympt->getString();
printf("\nMatrix property type : %s",mychar);
}
}
// Export the resulting population to step file.
rstat = edmiWriteStepFile("DataRepository",NULL,"myModel","C:/Temp/myStepFile.stp",NULL,NULL,0,8,&nbWarnings,&nbErrors,&sdaiError);
// Apply the next statement if you want to run more than one time.
//rstat = edmiDeleteModelContentsBN("DataRepository","myModel");
myModel.close();
} catch (CedmError *e) {
if (e->message) {
printf("\n%s",e->message);
} else {
printf("\n%s",edmiGetErrorText(e->rstat));
}
} catch (int thrownRstat) {
printf("\n%s",edmiGetErrorText(thrownRstat));
}
printf("\n\nPress return to exit.");
char c = getchar();
return 0;
}