Developer's Guide > Get Started with Civil SDK > Create Your First Application with Civil SDK
Create Your First Application with Civil SDK

This article describes the development of a basic application demonstrating how to access alignments in civil drawings and change their properties.

Prerequisites

This document describes the basic workflow of creating your first application with ODA Civil SDK. The application is developed for the Win32 platform with Microsoft® Visual Studio® 2015 (Visual C++ 14) using the following archives:

  • Kernel SDK
  • Drawings SDK
  • Architecture SDK
  • Civil SDK

First Application Creation Routine

1. Start Visual Studio and create a new solution or open an existing one.

2. Add a new project to the solution. Optionally set your project as the startup project.

3. Add the necessary include directives, at least:

  • OdaCommon.h
  • DbDatabase.h
  • RxDynamicModule.h
  • ExSystemServices.h
  • ExHostAppServices.h
  • AECBase.h
  • AECCVBase.h
  • AECCLand.h
  • and headers containing definitions for classes you need to work with

4. For convenience, create a custom services class.

/************************************************************************/
/* Define a Custom Services class.                                      */
/*                                                                      */
/* Combines the platform dependent functionality of                     */
/* ExSystemServices and ExHostAppServices                               */ 
/************************************************************************/
class MyServices : public ExSystemServices, public ExHostAppServices
{
protected:
  ODRX_USING_HEAP_OPERATORS(ExSystemServices);
};

Then in the main() function:

5. Initialize system services using the odInitialize function.

  OdStaticRxObject<MyServices> svcs;
  odInitialize(&svcs);

6. Load the necessary modules using the ::odrxDynamicLinker()->loadApp function.

  ::odrxDynamicLinker()->loadApp( OD_T( "AeccLand" ) );
  ::odrxDynamicLinker()->loadApp( OD_T( "AeccvBase" ) );
  ::odrxDynamicLinker()->loadApp( OD_T( "AecBase" ) );

7. Initialize databases using the OdDbDatabasePtr ExHostAppServices::readFile function.

OdDbDatabasePtr pDb;
pDb = svcs.readFile(inFile.c_str());

AECCVBaseDatabase( pDb ).Init();
AECCLandDatabase cBase( pDb );
cBase.Init();

8. Now you can access civil objects and their methods. For example, to print names and descriptions for alignments and change their names:

OdDbObjectIdArray alignmentIds = cBase.GetAlignmentIds();
for ( OdUInt32 i = 0; i < alignmentIds.size(); ++i )
{
  OdDbObjectId alignmentId = alignmentIds[ i ];
  AECCDbAlignmentPtr pAlignment = AECCDbAlignment::cast( alignmentId.openObject( OdDb::OpenMode::kForWrite ) );
  std::cout << "Alignment# " << i << "Name: " << pAlignment->GetName() << ", Description: " << pAlignment->GetDescription() << std::endl;
  pAlignment->SetName( OD_T( "New Name" ) );
}

Then you can save the updated file:

      OdRxObjectImpl<OdWrFileBuf> fb;
      fb.open(dwgOutFile.c_str());
      pDb->writeFile(&fb, OdDb::kDwg, OdDb::kDHL_CURRENT, false );
      std::cout<<"File saved as "<<dwgOutFile<<std::endl;

9. And finally, you must call the odUninitialize function to correctly unload modules.

10. The application requires preprocessor definitions and *.lib dependencies definitions to compile and run correctly. You can refer to one of the sample applications, for example ExTcSurfaceTin, to copy all the required definitions.

See Also

ExTcSurfaceTin Sample Application

Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.