The DWG Viewer explains emphasizes how to embed the framework into a stand alone application and covers basic viewing and editing capabilities.
...
The most important step is to embed the viewer object and connect it with the host application. The viewer object com.graebert.aresinstance.CFxARESDocumentView can be used and configured in a layout file. The next step is to bind the layout object with a property of type CFxARESDocumentView using findViewById(). This object is a member of the host application. The host application is connected to a class ARESDelegate.java extended by CFxARESInstanceDelegate and is initialized with the singleton CFxARESInstance.instance(). The core SDK kernel starts to render the drawing into the CFxARESDocumentView object that will be accessed by getDocumentView() when a document is loaded and activated successfully.
...
Code Block | ||
---|---|---|
| ||
JNIEXPORT void JNICALL Java_com_graebert_aressimplified_JNI_SetBackgroundColor( JNIEnv * env, jclass clazz, jint color ) { ... ODCOLORREF background = 0; switch ( color ) { case 1: background = 0; break; case 2: background = ODRGB( 255, 255, 255 ); break; case 3: background = ODRGB( 255, 0, 255 ); break; } OdEditorImplPtr pEditor = odedEditor(); pEditor->fire_modelessOperationWillStart( L"BACKGROUND_COLOR" ); ACTIVE_DOCUMENT()->GetFxDisplayDevice()->SetBackground( background ); pEditor->fire_modelessOperationEnded( L"BACKGROUND_COLOR" ); } |
DWG Vewer - Switch between model and sheets
Status | ||
---|---|---|
|
Status | ||||
---|---|---|---|---|
|
...
The DWG Viewer uses a native method GetLayoutNames() to get all available sheets of the drawing when documentActivated() is triggered. All layouts are passed to the method DocumentActivated() of the main activity and a corresponding button is created for each layout. The button is linked with a command expression that is executed when tapped. The command _SHEET_CONTROL handles the layout switch. The native method GetLayoutNames() manipulates the UI of the application and must be executed from the ui thread of the host application. A suitable A suitable method runOnUiThread() is provided by CFxARESInstance.instance().
...
Code Block | ||
---|---|---|
| ||
JNIEXPORT jobjectArray JNICALL Java_com_graebert_aressimplified_JNI_GetLayoutNames( JNIEnv * env, jclass clazz ) { CFxDatabasePtr pDB = ACTIVE_DOCUMENT()->GetFxDatabase(); if ( pDB.isNull() ) return nullptr; OdDbDictionaryPtr layoutDictionary = pDB->getLayoutDictionaryId().openObject(); int iLayoutCount = 0; OdDbDictionaryIteratorPtr iterator = layoutDictionary->newIterator(); std::map<int, CFxString> layouts; while( !iterator->done() ) { OdDbLayoutPtr pLayout = iterator->object(); layouts[ pLayout->getTabOrder() ] = pLayout->getLayoutName(); iterator->next(); } jclass stringClass = GET_JAVA()->FindClass( "java/lang/String" ); CFxJavaObjectArray result( layouts.size(), stringClass ); jsize index = 0; for ( const auto& it : layouts ) { CFxJavaString javaString( it.second ); result.SetElement( index, javaString.GetStrongJString() ); index++; } return reinterpret_cast<jobjectArray >( result.GetStrongJObject() ); } |
File: ARESDelegate.java
Code Block |
---|
@Override public void documentActivated() { final String layouts[] = JNI.GetLayoutNames(); CFxARESInstance.instance().runOnUiThread(new Runnable() { @Override public void run() { m_Host.DocumentActivated( layouts ); } }); } |
...