Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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’s main class is the MainActivity.java that has a synergy with a class named ARESDelegate.java . The ARESDelegate.java is derived from CFxARESInstanceDelegate, is the core piece between the host application and the kernel SDK and must be initialized with the singleton CFxARESInstance.instance() from the main class. The kernel SDK starts to render the drawing into the CFxARESDocumentView object that will be accessed by getDocumentView() from the ARESDelegate.java when a document is loaded successfully.

...

Code Block
languagejava
@Override
protected void onCreate(Bundle savedInstanceState)
{
...
m_ARES = new ARESDelegate( this );
m_CommonUI = new CommonUIDelegate();
...
CFxARESInstance.instance().delegate = m_ARES;
CFxARESInstance.instance().start( this , "" , "" );
CFxCommonUI.instance().startWithDelegate( m_CommonUI );
...
m_ARESView = findViewById( R.id.id_aresview )
...
}

...

Code Block
languagejava
private void LoadDrawing(){ 
...
m_ARESView.setVisibility( View.VISIBLE );
...
String fileName = "assets:/Samples/" + sampleDrawings[ which ];
String command = "_OPEN\n" + fileName + "\n";
CFxARESInstance.instance().runCommand( command, false );
...
}

public void DocumentCreated(){...}
public void DocumentActivated(String[] layouts){...}

...

The active drawing is closed with the CLOSE command. When the document is closed the CFxARESDelegate triggers documentDestroyed() , the drawing is removed from the memory and the CFxARESDocumentView  can become invisible. The host application can set up the user interface for a new drawing.

...

Code Block
private void SwitchViewMode( boolean panMode ){
...
CFxARESInstance.instance().runCommand("'2dmode     $M=$(if,$(and,$(getvar,2dmode),1),$(-,$(getvar,2dmode),1),$(+,$(getva    r,2dmode),1))");
}


NoteHint:  The core also provides You can achieve similar results with commands like ZOOM or PAN to achieve similar results.

DWG Viewer - Java Native Interface

Status
titleJAVA
Status
colourYellow
titleC++

Executing core commands is a good approach to quickly achieve results but in some cases it is necessary to access directly the drawing content or system relevant parameters.  The JNI, the Java Native Interface , allows to exchange data between Java and C++ or to directly manipulate drawing content. The synergy works with a combination of native Java methods and a matching C++ implementation that follows the JNI specifications. The C++ code is managed with CMake and compiled with the NDK. The created shared library (*.so) must be loaded using System.loadLibrary(). The JNI supports executing code in both directions.

...

Code Block
languagecpp
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 Viewer - Switch between model and sheets

Status
titleJAVA
Status
colourYellow
titleC++

...