This document describes the basic workflow of creating your first console application with IFC SDK.
Before creating, building, and running the application, download and unpack the following archives:
To get detailed information about downloading the IFC SDK archives and choosing an appropriate archive for your platform, please see the Download ODA IFC SDK topic.
If you use trial archive versions, you also need to activate the appropriate ODA products. To get details about obtaining, deploying, and activating trial versions, please see ODA Trial Version Getting Started Guide.
It is assumed that the application source code file will be placed in the Ifc/Examples/ExIfcFirstApp
folder.
The first application provides the following functionality:
ExIfcFirstApp.cpp
) to the project. You can save this file in the
Ifc/Examples/ExIfcFirstApp
folder.
ExIfcFirstApp.cpp
file:
//System includes
#include <iostream>
#include <cstdlib>
//IFC SDK includes
#include <IfcExamplesCommon.h>
#include <IfcCore.h>
#include <OdaCommon.h>
#include <StaticRxObject.h>
#include <RxDynamicModule.h>
#include <ExPrintConsole.h>
#include <daiHeaderSection.h>
#include <daiHeaderEntities.h>
enum AppResult
{
arOk = 0,
arIncorrectUsage,
arFileOpenError,
arEmptySectionHeader,
arInvalidSchema,
arUnsupportedSchema,
arEmptyModel,
arOdError,
arUnexpectedError
};
main()
function definition to the ExIfcFirstApp.cpp
file:
int main(int argc, char* argv[])
{
setlocale(LC_TIME, ""); // set current user locale (not OD_T("C")), for strftime
OdStaticRxObject <MyServices> svcs;
odrxInitialize(&svcs);
odIfcInitialize(false);
svcs.disableProgressMeterOutput(true);
odPrintConsoleString(L"\nIFC SDK First Application. Copyright (c) 2020, Open Design Alliance\n");
odPrintConsoleString(L"\nExIfcFirstApp application developed using %ls ver %ls", svcs.product().c_str(), svcs.versionString().c_str());
if (argc != 2)
{
odPrintConsoleString(L"\n\nusage: ExIfcFirstApp ");
odPrintConsoleString(L"\n a full path to the input IFC file\n Press any key to finish...");
getchar();
return arIncorrectUsage;
}
odIfcUninitialize();
::odrxUninitialize();
return arOk;
}
The initial version of the main()
function contains:
MyServices
class that is defined in the
IfcExamplesCommon.h
header file located in the Ifc/Examples/Common
folder.
For additional information, please see
ODA IFC SDK Sample Applications Reusable Files.
OdExIfcHostAppServices
classes, add
the following header and source files to your project:
Ifc/Extensions/ExServices/ExIfcHostAppServices.h
Ifc/Extensions/ExServices/ExIfcHostAppServices.cpp
Kernel/Extensions/ExServices/ExSystemServices.h
KernelBase/Extensions/ExServices/ExSystemServices.cpp
One more source file should be added to the project to provide ODA Software memory management:
KernelBase/Extensions/alloc/OdAllocOp.cpp
.
{
OdIfcFilePtr pDatabase;
try
{
}
catch (OdError& e)
{
odPrintConsoleString(L"\nError occurred: %ls! Press any key to finish...", e.description().c_str());
pDatabase = NULL;
return arOdError;
}
catch (...)
{
odPrintConsoleString(L"\n\nUnexpected error.");
pDatabase = NULL;
return arUnexpectedError;
}
}
OdIfcFile
class in the
try {} section:
OdString ifcFileName(argv[1]);
pDatabase = svcs.createDatabase(InitialSchema::kScmUndefined);
OdResult res = pDatabase->readFile(ifcFileName);
if (res == eOk)
{
odPrintConsoleString(L"\nFile opened successfully (%s).", ifcFileName.c_str());
}
else
{
odPrintConsoleString(L"\nFile open error (error code: %d). Press any key to finish...", res);
getchar();
pDatabase = NULL;
return arFileOpenError;
}
//get header section
OdDAI::OdHeaderSectionPtr headerSection = pDatabase->getHeaderSection();
if (!headerSection.isNull())
{
//get and check the schema
OdDAI::ApplicationInstancePtr fileSchema = headerSection->getEntityByType(OdDAI::kFileSchema);
OdArray<OdAnsiString> schemas;
if (fileSchema->getAttrCaseInsensitive("schema_identifiers") >> schemas)
{
for (const auto& schemaName : schemas)
{
OdDAI::SchemaPtr schema = oddaiGetSchema(schemaName);
if (schema.isNull())
{
odPrintConsoleString(L"\nUnsupported schema %hs. Press any key to finish...", schemaName.c_str());
getchar();
pDatabase = NULL;
return arUnsupportedSchema;
}
odPrintConsoleString(L"\nIFC File schema: %hs\n", schemaName.c_str());
}
}
}
else
{
odPrintConsoleString(L"\nError getting header section from the %s file! Press any key to finish...", ifcFileName.c_str());
getchar();
pDatabase = NULL;
return arEmptySectionHeader;
}
OdIfc::OdIfcEntityPtr pInst;
OdIfcModelPtr pModel = pDatabase->getModel();
if (pModel.isNull())
{
odPrintConsoleString(L"\nAn unexpected error occurred while opening the IFC file! Press any key to finish...");
getchar();
pDatabase = NULL;
return arEmptyModel;
}
odPrintConsoleString(L"Model entities: \n");
OdDAI::InstanceIteratorPtr it = pModel->newIterator();
unsigned int entIdx;
for (entIdx = 0; !it->done(); it->step(), ++entIdx)
{
//opens an entity
pInst = it->id().openObject();
pInst = it->id().openObject();
if (!pInst.isNull())
{
odPrintConsoleString(L"Entity %d: \n", entIdx);
odPrintConsoleString(L"\tEntity handle (corresponds to the STEP-id) = %d\n", it->id().getHandle());
odPrintConsoleString(L"\tEntity type code = %d\n", pInst->type());
odPrintConsoleString(L"\tEntity type name = %hs\n", pInst->typeName().c_str());
if (pInst->isKindOf(OdIfc::kIfcRepresentationItem) || pInst->isKindOf(OdIfc::kIfcProfileDef))
odPrintConsoleString(L"\tEntity is kind of kGeom\n");
else
odPrintConsoleString(L"\tEntity is kind of kBIM\n");
}
}
odPrintConsoleString(L"Found entities: %d\n", entIdx);
//Finalize the process, OdIfcFile and underlying header section and Model will be released.
pDatabase = NULL;
After finishing the cycle with dumping entities' information to the console window, the program prints the total quantity of entities and destroys the .ifc file, header section, and model objects by assigning the NULL value to the IFC database smart pointer.
For example, if you use Microsoft® Visual Studio® 2019 for 64-bit Windows® dynamic configuration, you can set
the following path for the output directory in the project properties window:
..\..\..\..\..\exe\vc16_amd64dll\
.
It is assumed that the project for this configuration is allocated in the
CMakePlatforms\vc15_amd64dll\Ifc\Examples\ExIfcFirstApp
sub-directory of the IFC SDK installation folder.
KernelBase
KernelBase/Include
Kernel/Include
Kernel/Extensions/ExServices
Ifc/Include
Ifc/Include/Common
Ifc/Include/sdai
Ifc/Include/sdai/daiHeader
Ifc/Extensions/ExServices
Ifc/Examples/Common
ThirdParty
ThirdParty/activation
These options are needed for your compiler to find ODA Software header files. Do not forget to add a relative path for each directory if needed to let the compiler find header files used in the project.
UNICODE
TEIGHA_TRIAL
ODA_LICENSING_ENABLED
IFC_DYNAMIC_BUILD
_TOOLKIT_IN_DLL_
CMAKE_INTDIR="Release"
The TEIGHA_TRIAL
definition should be added only if you are using the IFC SDK trial version.
If using the full version, place the OdActivationInfo
file into the
ThirdParty\activation
directory.
Please see Activating ODA Products for details about getting the activation file.
For example, if you use Microsoft® Visual Studio® 2019 for 64-bit Windows® dynamic configuration, set the following paths for the library directories in the project properties window:
..\..\..\..\..\exe\vc16_amd64dll
..\..\..\..\..\lib\vc16_amd64dll
It is assumed that the project for this configuration is allocated in the
CMakePlatforms\vc15_amd64dll\Ifc\Examples\ExIfcFirstApp
sub-directory of the IFC SDK installation folder.
IfcCore.lib
sdai.lib
TD_Gi.lib
TD_Ge.lib
TD_Root.lib
TD_DbRoot.lib
TD_DbRoot.lib
TD_ExamplesCommon.lib
TD_Alloc.lib
If the first application experiences errors, most likely you are using a trial archive that was not correctly activated. Please see ODA Software Trial Version Getting Started Guide due to get additional information about activating ODA Software trials.
If your application successfully runs, it prints its output to the console.
You also can get the full source code of this first IFC SDK application.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|