Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 2 Next »

The SDK offers two ways to achieve zooming the active view. The miscellaneous topics refer to all described sample apps and do not specify 100% executable source code. Please read topics about DWG Viewer, DWG Editor and DWG Expert first.

Existing commands JAVA

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.

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 JAVA C++

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 the refresh 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.

public static native void ZoomFit();

Button.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View v)
    {
      CFxARESInstance.instance().runOnWorkingThread(new Runnable()
    {
      @Override
        public void run()
        {
          JNI.ZoomFit();
        }
    });
}
});

#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;
};

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();
}

  • No labels