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
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
Code Block |
---|
private void CreateNewDocument()
{
m_ARESView.setVisibility( View.VISIBLE );
String command = "_SMARTNEW\n";
CFxARESInstance.instance().runCommand( command, false );
} |
DWG Editor - Change system variable CECOLOR
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
Code Block |
---|
|
public static native void SetCECOLOR( int color ); |
File: ARES_Simplified_JNI.cpp
Code Block |
---|
JNIEXPORT void JNICALL Java_com_graebert_dwgeditor_JNI_SetCECOLOR( JNIEnv * env, jclass clazz, jint color ){ ... } |
File: ColorPanel.java
Code Block |
---|
|
@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
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
Code Block |
---|
|
@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
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
Code Block |
---|
public static native String[] GetBlockNames(); |
File: ARES_Simplified_JNI.cpp
Code Block |
---|
|
JNIEXPORT jobjectArray JNICALL Java_com_graebert_dwgeditor_JNI_GetBlockNames( JNIEnv * env, jclass clazz )
{
if ( ACTIVE_DOCUMENT() == 0 )
return nullptr;
CFxDatabasePtr pDB = ACTIVE_DOCUMENT()->GetFxDatabase();
if ( pDB.isNull() )
return nullptr;
OdDbBlockTablePtr pBlockTable = pDB->getBlockTableId().openObject(OdDb::kForRead);
if ( pBlockTable.isNull() )
return nullptr;
OdStringArray blockNames;
OdDbSymbolTableIteratorPtr iterator = pBlockTable->newIterator();
for ( ; !iterator->done(); iterator->step() )
{
OdDbBlockTableRecordPtr pBlockTableRecord = iterator->getRecord();
OdString blockName = pBlockTableRecord->getName();
if ( blockName.isEmpty() )
continue;
if ( blockName.getAt(0) == L'*' )
continue;
if ( pBlockTableRecord->isAnonymous() )
continue;
if ( pBlockTableRecord->isLayout() || pBlockTableRecord->isFromExternalReference() )
continue;
blockNames.push_back( blockName );
}
jclass stringClass = GET_JAVA()->FindClass( "java/lang/String" );
CFxJavaObjectArray result( blockNames.size(), stringClass );
jsize index = 0;
for ( const CFxString& name : blockNames )
{
CFxJavaString javaString( name );
result.SetElement( index, javaString.GetStrongJString() );
index++;
}
return reinterpret_cast<jobjectArray >( result.GetStrongJObject() );
} |
File: MainActivity.java
Code Block |
---|
|
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();
} |