...
Note: The framework supports opening DWG, DXF and DWT files.
File: ARESDelegate.java
Code Block |
---|
@Override |
...
public void documentCreated(){...} |
...
@Override |
...
public void documentActivated(){...} |
File: MainActivity.java
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){...} |
3.1.3. DWG Viewer - Close active drawing Java
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 application can set up the user interface for a new drawing.
File: ARESDelegate.java
Code Block |
---|
@Override |
...
public void documentDestroyed(){...} |
File: MainActivity.java
Code Block |
---|
private void LoadDrawing(){ |
...
... |
...
if ( m_DocumentOpened ) |
...
{ |
...
String command = "_CLOSE\n"; |
...
CFxARESInstance.instance().runCommand( command, false ); |
...
return; |
...
} |
...
... |
...
} |
...
public void DocumentClosed(){ |
...
... |
...
m_ARESView.setVisibility( View.GONE ); |
...
} |
3,1,4, DWG Viewer - Change viewing modes Java
...
It is not necessary to implement viewing gestures. The framework comes with a set of basic finger gestures to change the active view of the drawing. It supports zooming in and out but has to know if it runs in Pan or Orbit mode. The viewing mode can be switched with a Diesel expression that can be executed with the runCommand() method of the singleton CFxARESInstance.instance().
File: MainActivity.java
Code Block |
---|
private void SwitchViewMode( boolean panMode ){ |
...
... |
...
CFxARESInstance.instance().runCommand("'2dmode $M=$(if,$(and,$(getvar,2dmode),1),$(-,$(getvar,2dmode),1),$(+,$(getva r,2dmode),1))"); |
...
} |
Note: The core also provides commands like ZOOM or PAN to achieve similar results.
3.1.5. DWG Viewer - Java Native Interface Java C++
...
All necessary C++ files ( headers or source files ) as well as native libraries are treated within a nested structure of files named CMakeLists.txt. Subprojects may have their own CMakeLists.txt to reduce the complexity of all C++ parts. Including an additional block like externalNativeBuild inside the build.gradle of the project takes over the configuration and manages the compilation of the C++ code if everything is set up correctly.
JNI specification: https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/jniTOC.html
...
Note: More details can be found in the topics “Java and C++ synergy” and “C++ modules”.
3.1.6. DWG Viewer - Change layout background color Java C++
...
The DWG Viewer uses a native method SetBackgroundColor() to change the background color of the active model or sheet. The offered color indexes are linked to a button. The native method is called when the button is tapped. The native method SetBackgroundColor() manipulates the C++ part of the application and must be executed from the working thread. A suitable method runOnWorkingThread() is provided by CFxARESInstance.instance().
File: MainActivity.java
Code Block |
---|
private void SetBackground( @BackgroundColor final int color ) |
...
{ |
...
CFxARESInstance.instance().runOnWorkingThread(new Runnable() |
...
{ |
...
@Override |
...
public void run() |
...
{ |
...
JNI.SetBackgroundColor( color ); |
...
} |
...
}); |
...
} |
File: JNI.java
Code Block |
---|
public static native void SetBackgroundColor( int color ); |
File: ARES_Simplified_JNI.cpp
Code Block |
---|
JNIEXPORT void JNICALL Java_com_graebert_aressimplified_JNI_SetBackgroundColor( JNIEnv * env, jclass clazz, jint color ){ ... } |
3,1,7. DWG Vewer - Switch between model and sheets Java C++
...
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 method runOnUiThread() is provided by CFxARESInstance.instance().
File: JNI.java
Code Block |
---|
public static native String[] GetLayoutNames(); |
File: ARES_Simplified_JNI.cpp
Code Block |
---|
JNIEXPORT jobjectArray JNICALL Java_com_graebert_aressimplified_JNI_GetLayoutNames( JNIEnv * env, jclass clazz ){ ... } |
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 ); |
...
} |
...
}); |
...
} |
File: MainActivity.java
Code Block |
---|
public void DocumentActivated(String[] layouts) |
...
{ |
...
for ( final String layout : layouts ) |
...
{ |
...
Button layoutActivateButton = new Button( this ); |
...
layoutActivateButton.setText( layout ); |
...
layoutActivateButton.setOnClickListener(new View.OnClickListener() |
...
{ |
...
@Override |
...
public void onClick(View v) |
...
{ |
...
String command = "_SHEET_CONTROL\n_ACTIVATE\n" + layout + "\n"; |
...
CFxARESInstance.instance().runCommand( command ); |
...
} |
...
}); |
...
m_Layouts.addView( layoutActivateButton, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT ) ); |
...
} |
...
} |