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 the 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);
}
Initialization and Deinitialization.
Work with Header Sections and Models.
Library Dependencies of IFC SDK
Basic Concepts of IFC SDK Usage
Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.
|