/
Android: C++ Modules

Android: C++ Modules

The Android sample project includes multiple samples of how custom commands or database related features can be used inside a Java hosted application. The project provides the following samples:

  • DrawCirclesCommand

  • CustomEntity

  • CreateText

  • DrawTemporaryEntities

  • SelectObjects

  • DocumentCommands

  • GetClosestOsnap

  • DatabaseReactor

  • DrawableOverrule

  • DrawLinesCommand

Note: Additional samples will be included in further updates.

Module

Short Description

Module

Short Description

DrawCirclesCommand

The sample DrawCirclesCommand introduces the most important technique: the command. A command name must be unique and can be executed by runCommand(). The command (DrawCircleCommand) shows how to access the document database, invoke user prompts and create entities using a custom tracker (CDrawCircleTracker). For more details please also check the comments in the source and header files.

CustomEntity

The sample SpecialEntity demonstrates how a custom entity is created,registered and used. The custom entity inherits from base class OdDbCircle and is transformed visually by overwriting the entity's subWorldDraw() method. For more details please also check the comments in the source and header files.

CreateText

The sample CreateText creates a new OdDbText and appends it to the active documents database.

DrawTemporaryEntities

The sample DrawTemporaryEntities creates, installs and operates with a CFxTracker. The tracker renders geometry without the need adding entities to the database.

SelectObjects

The sample SelectObjects shows how to let the user select entities with methods like DoSSGet(), manually select entities by layer name or type, and work with a CFxSelectionSet.

DocumentCommands

The sample DocumentCommands has custom commands to close or save the active document. Closing the active document can be achieved with method CloseDocument() from CFxDocumentManager. Saving the file can be done with method SaveFile() from OdDbDatabase.

GetClosestOsnap

The sample GetClosestOsnap shows how to access entities osnap points using getOsnapPoints() and analyzes the closest osnap point to a specified location.

DatabaseReactor

The sample DatabaseReactor emphasizes all necessary steps to register a DbDatabaseReactor database reactor to the active documents database. This database reactor will inform about all database transactions like objectAppended() or objectErased().

DrawableOverule

A OdGiDrawableOverrule is a nice way to specify how a certain entity type will be rendered. A overrule will be processed only once ( or run rebuild ) except you specify OdGiDrawable::kDrawableRegenDraw as overrule attribute; this will redraw all necessary enttiy types any time the view changes. This approach might be useful if you want to apply a special scaling.

DrawLinesCommand

The sample DrawLinesCommand shows how to develop a command that inserts a line with continuous segments. It also explains how to assign a linetype to a temporary entity. Important: Linetypes must be available as assets. Load module with odrxDynamicLinker()->loadApp( L"DrawLinesCommand" );

image-20240613-103235.png

 

C++ Modules - OdRxModule and CFxCommand
This is a short summary about how a C++ module can be created, compiled and loaded into the host appliaction. All necessary steps are based on DrawCirclesCommand.

 

  1. Java: Create a nativ method

  2. C++: Create a matching implementation

  3. Store the C++ implementation inside a shared library

  4. Create C++ module

  5. Load C++ module

  6. Compile the shared library and module with CMake

  7. Load the shared library with System.LoadLibrary()

  8. Call native method to load C++ module inside Java host application

 

1. C++ Modules - Java: Create a nativ method

JNI.java

public static native void LoadJNI();

 

2. C++ Modules - C++: Create a matching implementation

ARESSimplified_JNI.cpp

JNIEXPORT void JNICALL Java_com_graebert_aressimplified_JNI_LoadJNI( JNIEnv * env, jclass clazz ){...}

 

3. C++ Modules - Store the C++ implementation inside a shared library

Check file CFx/AndroidSimplified_JNI/app/CMakeLists.txt for more details.
Check file CFx/DrawCirclesCommand/CMakeLists.txt for more details.
Check file CFx/CMakeLists.txt for more details.


4. C++ Modules - Create C++ module

See inside folder CFx/DrawCirclesCommand for more details.

A OdRxModule has two essential methods. The first method InitApp() is called when the module is loaded. InitApp() may be also used for further initialization purposes. The second method UnitApp() is called when the module is unloaded , you may clean up your pointers, references and objects carefully.

 

A CFxCommand  must be registered before being used. It is recommended to register any command inside InitApp() and to remove any command inside UninitApp(). The command can be registered with odedRegCmds()->addCommand() and removed with odedRegCmds()->removeCnd().

 

5. C++ Modules - Load C++ module

The module architecture is handled on C++ side and will be called inside the native method. All C++ modules will be loaded with odrxDynamicLinker()->loadApp().

ARESSimplified_JNI.cpp

JNIEXPORT void JNICALL Java_com_graebert_aressimplified_JNI_LoadJNI( JNIEnv * env, jclass clazz ) {    odrxDynamicLinker()->loadApp( L"DrawCircleCommandModule" ); }

 

6. C++ Modules - Compile the shared library and module with CMake

See topic “Compile the shared library with CMake” for more information.
Android: Java and C++ synergy

 

7. C++ Modules - Load the shared library with System.LoadLibrary()

See topic “Load the shared library with System.LoadLibrary()” for more information.
Android: Java and C++ synergy

 

8. C++ Modules - Call native method to load C++ module inside Java host application

It is necessary to load all C++ modules before any features become active.

JNI.java



Related content