...
Viewer object
Load drawing
Close drawing
Change viewing modes
Change layout background color
Switch between model and sheets
DWG Viewer - Viewer object
Status | ||
---|---|---|
|
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 application’s main class is the MainActivity.java that has a synergy with a class named ARESDelegate.java extended by CFxARESInstanceDelegate and is . 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 kernel starts to render the drawing into the CFxARESDocumentView object that will be accessed by getDocumentView() when from the ARESDelegate.java when a document is loaded and activated successfully.
Note: The host application application’s main class may be directly used as CFxARESInstanceDelegate but it is easier to split both parts of the application.
File: content_main.xml
Code Block | ||
---|---|---|
| ||
<com.graebert.aresinstance.CFxARESDocumentView android:id="@+id/id_aresview" android:layout_width="0dp" android:layout_height="0dp" android:visibility="gone" app:layout_constraintBottom_toTopOf="@id/id_bottompanel" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/id_background" /> |
...
Code Block | ||
---|---|---|
| ||
@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 )
...
} |
...
The DWG Viewer reads all drawings from the assets/resources of the APK. This may result in a slower opening and rendering time. It is recommended to load drawings from a local or external folder of the device. The drawing is loaded with the OPEN command using the runCommand() method of the singleton CFxARESInstance.instance() and the CFxARESDocumentView can become visible. Once the drawing is loaded the CFxARESDelegate triggers documentCreated() followed by documentActivated(). This is the time when additional user interfaces can show up or drawing content can be accessed. In general, the CFxARESDelegate informs the host application about all important drawing events.
Note: The framework supports opening DWG, DXF and DWT files.
...
Code Block | ||
---|---|---|
| ||
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 | ||
---|---|---|
|
Status | ||||
---|---|---|---|---|
|
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 | ||
---|---|---|
| ||
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 | ||
---|---|---|
|
Status | ||||
---|---|---|---|---|
|
...