This document describes the basic concepts of using IFC SDK.
As usual for ODA products, before starting to use IFC SDK functionality, you need to initialize it.
To initialize IFC SDK, use the odIfcInitialize();
function which is declared in the
Include/IfcCore.h
header file.
This function loads the appropriate modules that provide IFC SDK functionality.
It accepts two parameters:
bInitIfcGeomResource
— A flag that determines whether geometry functionality should be initialized as well.
Required to work with geometry objects.
modelerType
— Determines which type of geometry is supported. By default, facet geometry is supported.
Before calling the odIfcInitialize();
function, sequentially call the odrxInitialize()
function
to get access to Rx-functionality and the odDbRootInitialize()
function to initialize drawing database functionality:
odrxInitialize(&svcs);
odDbRootInitialize();
odIfcInitialize(true);
To clear up the environment before finishing an IFC SDK based application, call the odIfcUnnitialize()
function.
If you called the odrxInitialize()
or (and) the odDbRootInitialize()
function previously, don't forget to
call the odrxUninitialize()
or (and) the odDbRootUninitialize()
functions.
Please note that you have to keep the calling sequence when de-initializing IFC functionality:
odIfcUninitialize();
odDbRootUninitialize();
odrxUninitialize();
To create a new IFC database, call the createDatabase()
method of the customer service class instance declared in the
Ifc/Examples/Common/IfcExamplesCommon.h
header file.
The MyServices
class is based on ExSystemServices
and OdExIfcHostAppServices
classes, which implement platform-based functionality for
IFC SDK based applications:
class MyServices : public ExSystemServices, public OdExIfcHostAppServices
{
protected:
ODRX_USING_HEAP_OPERATORS(ExSystemServices);
OdGsDevicePtr gsBitmapDevice(OdRxObject* /*pViewObj*/ = NULL,
OdDbBaseDatabase* /*pDb*/ = NULL,
OdUInt32 /*flags*/ = 0)
{
try
{
OdGsModulePtr pGsModule = ::odrxDynamicLinker()->loadModule(OdWinBitmapModuleName);
return pGsModule->createBitmapDevice();
}
catch(const OdError&)
{
}
return OdGsDevicePtr();
}
public:
virtual OdString findFile(
const OdString& filename,
OdDbBaseDatabase* pDb,
FindFileHint hint)
{
return filename;
}
virtual const OdString program()
{
return OdString::kEmpty;
}
virtual const OdString product()
{
return OdString::kEmpty;
}
virtual const OdString companyName()
{
return OdString::kEmpty;
}
virtual bool ttfFileNameByDescriptor(
const OdTtfDescriptor& description,
OdString& filename)
{
return false;
}
virtual OdString getAlternateFontName() const
{
return OdString::kEmpty;
}
virtual OdString getFontMapFileName() const
{
return OdString::kEmpty;
}
virtual OdString getPreferableFont(
const OdString& fontName,
OdFontType fontType)
{
return OdString::kEmpty;
}
virtual OdString getSubstituteFont(
const OdString& fontName,
OdFontType fontType)
{
return OdString::kEmpty;
}
};
The createDatabase()
method returns a smart pointer to the OdIfcFile
object.
Using this smart pointer, call the readFile()
method to load the contents of an .ifc file to the created object.
OdStaticRxObject< MyServices > svcs;
OdString ifcFileName(argv[1]);
OdIfc::OdIfcFilePtr pDatabase = svcs.createDatabase(kScmUndefined);
OdResult res = pDatabase->readFile(ifcFileName);
if (res == eOk)
{
odPrintConsoleString(L"\nFile opened successfully.");
}
else
{
odPrintConsoleString(L"\nFile open error.");
}
To write the contents of an IFC file object, use the writeFile()
method of the OdIfcFile
object:
OdStaticRxObject < MyServices > svcs;
OdIfc::OdIfcFilePtr pDb = svcs.createDatabase();
if (!pDb.isNull())
{
//Add here some functionality for filling the header section and model objects
pDb->writeFile(szTargetFileName, true);
}
When you have a valid instance of the OdIfcFile
class, you can manage the header section and model objects of the IFC database.
To get access to the IFC database header section:
OdDAI::RepositoryPtr pRepository = pDb->getRepository();
OdDAI::OdHeaderSectionPtr headerSection = pRepository->getHeaderSection();
if (headerSection.isNull())
{
ODA_ASSERT(0 && "Header is not valid.");
throw OdError(eNullEntityPointer);
}
headerSection->initialize();
OdDAI::OdFileDescriptionAuto* fileDescription = getHeaderFromSection(headerSection);
OdArray descriptionCollection;
descriptionCollection.push_back("ViewDefinition [CoordinationView]");
fileDescription->setDescriptionAggr(descriptionCollection);
fileDescription->setImplementationLevel("2;1");
OdDAI::OdFileNameAuto* fileName = getHeaderFromSection(headerSection);
fileName->setName("TestFile.ifc");
fileName->setTimeStamp("2019-02-23T12:17:26");
OdDAI::OdFileSchemaAuto* fileSchema = getHeaderFromSection(headerSection);
OdArray schemCollection;
schemCollection.push_back("IFC2X3");
fileSchema->setSchemaIdentifiersAggr(schemCollection);
To proceed with any operation with an IFC model, you need to have a smart pointer to its object within an IFC database.
To get it, use a model provider object from the OdDAI
interface:
OdDAI::Utils::ModelProviderRO modelProvider(pDb->getRepository());
OdIfc::OdIfcModelPtr model = modelProvider.model();
if (model.isNull() || model->underlyingSchemaName().find("IFC2X3") != 0)
{
ODA_ASSERT(0 && "Model is not valid.");
throw OdError(eNullEntityPointer);
}
Using the smart pointer returned by the model()
method of the repository object, you are able to handle the IFC model the way you want through the OdDAI
interface.
Library Dependencies of IFC SDK
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|