Coming soon…The SDK offers two ways to achieve zooming the active view.
Existing commands
Simply using the runCommand() method of the singleton CFxARESInstance.instance().
The final call looks like: CFxARESInstance.instance().runCommand("_ZOOM\n_FIT\n");
This execution can be linked with a onClickListener() of a simple Button. All existing commands take care about refreshing the GA ( graphics area ) properly.
Code Block |
---|
|
Button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
CFxARESInstance.instance().runCommand("_ZOOM\n_FIT\n");
}
}); |
Hint: The same can be e.g. done with PAN.
Available commands are: -PAN 0,0,0 1,1,1\n , PANUP, PANDOWN, PANLEFT, PANRIGHT
Custom code - Java Native Interface
The other way is to write custom C++ code that requires some more actions but has more potential regarding when and how it is executed. The first step is to specify a native Java method that can be called from the app side but must be implemented on C++ side. This native method can be linked with a onClickListener() of simple Button. When the View is updated programmatically without a core command, it must be executed from the working thread and refreshing of the GA ( graphics area ) must be addressed manually. 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() .
Refreshing the GA can be achieved with a modeless operation. The modeless helper class CModellessOperationHelper is implemented as a guard. When the object is getting destroyed it takes care about refreshing the graphics area.
Code Block |
---|
public static native void ZoomFit(); |
Code Block |
---|
Button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
CFxARESInstance.instance().runOnWorkingThread(new Runnable()
{
@Override
public void run()
{
JNI.ZoomFit();
}
});
}
}); |
Code Block |
---|
#include <EditorImpl.h>
struct CModellessOperationHelper
{
CModellessOperationHelper( CFxDatabase* pDatabase, const CFxString& operationName ) : _operationName( operationName )
{
OdEditorImplPtr pEditor = odedEditor();
pEditor->fire_modelessOperationWillStart( _operationName );
if ( pDatabase )
pDatabase->StartUndoRecord(_operationName );
}
~CModellessOperationHelper()
{
OdEditorImplPtr pEditor = odedEditor();
pEditor->fire_modelessOperationEnded( _operationName );
}
CFxString _operationName;
CFxDatabase* _pDatabase;
}; |
Code Block |
---|
JNIEXPORT void JNICALL Java_com_graebert_dwgeditor_JNI_ZoomFit( JNIEnv * env, jclass clazz );
JNIEXPORT void JNICALL Java_com_graebert_dwgeditor_JNI_ZoomFit( JNIEnv * env, jclass clazz )
{
if ( 0 == ACTIVE_DOCUMENT() )
return;
CFxDatabasePtr pDB = ACTIVE_DOCUMENT()->GetFxDatabase();
if ( pDB.isNull() )
return;
// Start operation, it will be closed automatically.
CModellessOperationHelper operation( pDB, L"OP_ZOOMFIT" );
CFxView* pFxView = ACTIVE_DOCUMENT()->GetActiveFxView();
OdGsView* pView = static_cast<OdGsView*>( pFxView );
OdGeBoundBlock3d block;
if ( pFxView->ViewExtentsWCS( block ) )
pFxView->ZoomExtentsWCS( &block );
pFxView->EndTransaction();
} |