The DWG Editor carries the basic features and extends the creation and editing capabilities of entities.
Features
Create new drawings
Change system variable CECOLOR
Offer basic drawing and editing tools
List and insert existing block definitions
DWG Editor - Create new drawings JAVA
The DWG Editor uses the command SMARTNEW to create a new document. The command is executed with runCommand() method of CFxARESInstance.instance(). Once the drawing is loaded the CFxARESDelegate triggers documentCreated() followed by documentActivated().
Note: Templates can be opened with command NEW. A possible command expressions will work like this "_NEW\n" + fileName + "\n";
File: MainActivity.java
private void CreateNewDocument() { m_ARESView.setVisibility( View.VISIBLE ); String command = "_SMARTNEW\n"; CFxARESInstance.instance().runCommand( command, false ); }
DWG Editor - Change system variable CECOLOR JAVA C++
The DWG Editor uses a native method to change the database variable CECOLOR, the current entity color when created. The offered color indexes are provided by a custom color panel. The necessary JNI method SetCECOLOR() is called when the dedicated color button is tapped. The JNI method accesses the C++ part of the application and must be executed within the working thread. A suitable method runOnWorkingThread() is provided by CFxARESInstance.instance() .
File: JNI.java
public static native void SetCECOLOR( int color );
File: ARES_Simplified_JNI.cpp
JNIEXPORT void JNICALL Java_com_graebert_dwgeditor_JNI_SetCECOLOR( JNIEnv * env, jclass clazz, jint color ){ ... }
File: ColorPanel.java
@Override public void onClick(View v) { int color = 0; ... final int finalColor = color; CFxARESInstance.instance().runOnWorkingThread(new Runnable() { @Override public void run() { JNI.SetCECOLOR( finalColor ); } }); }
DWG Editor - Offer basic drawing and editing tools JAVA
The DWG Editor resorts to commands like LINE, CIRCLE and POINT to provide basic 2D drawing tools and commands like MOVE, SCALE and DELETE for basic editing features. The commands can be easyly executed with the runCommand() method of CFxARESInstance.instance().The Commands to choose are offered by a custom command panel. All commands require user actions to complete. User actions are controlled by the default user input interface.
Note: The DWG Expert explains how to overwrite the default user input and create a custom feature that fits better inside the host application.
File: CommandPanel.java
@Override public void onClick(View v) { String command = ""; if ( v == m_Point ) command = "_POINT\n"; else if ( v == m_Line ) command = "_LINE\n"; else if ( v == m_Circle ) command = "_CIRCLE\n"; else if ( v == m_Delete ) command = "_DELETE\n"; else if ( v == m_Move ) command = "_MOVE\n"; else if ( v == m_Scale ) command = "_SCALE\n"; CFxARESInstance.instance().runCommand( command ); }
DWG Editor - List and insert existing block definitions JAVA C++
The DWG Editor uses a native method GetBlockNames() to get all available block definitions of the drawing when the delegate CFxARESDelegate triggers documentActivated(). All block definition names are passed to the method DocumentActivated() of the main activity and are stored temporarily while the drawing is opened. The DWG Editor provides a button that can list all available blocks with a simple AlertDialog. When a block is chosen , a suitable command expression using the command -INSERTBLOCK is created and executed with runCommand().
File: JNI.java
public static native String[] GetBlockNames();
File: ARES_Simplified_JNI.cpp
JNIEXPORT jobjectArray JNICALL Java_com_graebert_dwgeditor_JNI_GetBlockNames( JNIEnv * env, jclass clazz ){ ... }
File: MainActivity.java
String m_Blocks[] = null; public void DocumentActivated( String[] layouts, String[] blocks ) { m_Blocks = blocks; ... } private void InsertBlock() { if ( m_Blocks == null || m_Blocks.length == 0 ) { AlertDialog.Builder warningMessage = new AlertDialog.Builder( this ); warningMessage.setTitle( getResources().getString( R.string.app_name ) ); warningMessage.setMessage( "No blocks to insert in this drawing." ); warningMessage.create().show(); return; } AlertDialog.Builder builder = new AlertDialog.Builder( this ); builder.setTitle("Select block"); builder.setItems( m_Blocks, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String command = "_-INSERTBLOCK\n\"" + m_Blocks[which] + "\"\n\\1.0\n1.0\n0.0\n"; CFxARESInstance.instance().runCommand(command); } }); builder.setNegativeButton("Cancel", null); AlertDialog dialog = builder.create(); dialog.show(); }