Below is an example of a plug-in which does a viewframe on all picked objects. It is a simple example of a momentary plug-in.
;; This file simply gives the defaults for the Scheme variables ;; used in the option box. (ui-symbol "frame" 0) (ui-string "frame" "Frame")
;; This file defines the option box
(ui-editor "frame.options"
(list 'symbols 'frame )
(list 'title "View Frame Options")
(ui-integer-widget "frame"
(list 'range 0 65535)
)
)
#include <AlUniverse.h>
#include <AlViewFrame.h>
#include <AlPickList.h>
#include <AlObject.h>
#include <AlLiveData.h>
#include <AlFunction.h>
#include <AlFunctionHandle.h>
#include <AlIterator.h>
#include <strings.h>
extern char * makeAltPath(const char *dirName, const char *suffix);
// A simple iterator used to pass the frame number
// along when viewing an object.
class viewIterator: public AlIterator
{
public:
viewIterator( double frame = 0.0 )
: frameNum( frame ) {};
virtual ~viewIterator() {};
virtual int func( AlObject* );
private:
double frameNum;
};
// The iterator's one and only method. Does a viewframe
// on the passed in object using the frame number in the
// iterator object.
int viewIterator::func( AlObject* obj )
{
if ( obj == NULL )
return 0;
AlAnimatable* animitem;
AlCurve* curve;
AlSurface* surface;
AlObjectType type = obj->type();
if( animitem = obj->asAnimatablePtr() )
AlViewFrame::viewFrame( animitem, frameNum, AlViewFrame::kObjectAndBelow );
else if( curve = obj->asCurvePtr() )
AlViewFrame::viewFrame( curve, frameNum );
else if( surface = obj->asSurfacePtr() )
AlViewFrame::viewFrame( surface, frameNum );
else
AlPrintf( kPrompt, "Sorry, %s is not a viewable object", obj->name() );
; // a non viewable object
return 0;
}
// The actual plug-in function.
void my_view()
{
int frameNum;
// Get the frame number from the option box.
if( sSuccess == AlGetInteger( "frame", frameNum ) )
{
// Print the number to the promptline.
AlPrintf( kPrompt, "Viewing frame %d.", frameNum );
// Instantiate an iterator and apply it to all picked
// objects.
int rc;
viewIterator* view = new viewIterator( frameNum );
if ( sSuccess != AlPickList::applyIteratorToItems( view, rc ) )
AlPrintf( kPrompt, "Iterator failed." );
if ( rc != 0 )
AlPrintf( kPrompt, "Return code is %d.", rc );
AlPrintf( kPrompt, "Viewing complete." );
}
}
// This handle may have to be global if you wish to remove the
// plug-in from the menu using the h.destroy() method in the
// 'momentary_exit' function.
// The menu entry is automatically removed when Alias exits.
//
AlFunctionHandle h;
AlMomentaryFunction hFunc;
extern "C"
int plugin_init( const char *dirName )
//
// This routine initializes the plugins and attaches it to the menu.
// It returns 0 if there is no initialization error.
//
{
char *dirScm;
// Initialize the universe. This must be done by all
// plug-ins. If the universe is not initialized the plug-in
// will fail.
AlUniverse::initialize( );
dirScm = makeAltPath(dirName,"scm");
// Invoke the scheme file which sets defaults for the scheme
// variables.
AlInvokeSchemeFile( "frame_init.scm", dirScm );
// Allocate a function handle. The first argument is the label on
// the menu and the second is the function to invoke when the
// menu item is selected.
hFunc.create( my_view );
h.create( "View Frame", &hFunc );
// Define the attribute string for the attribute line below
// the prompt line.
h.setAttributeString( "viewframe" );
// Read in the option box. The first argument is the
// option box in $ALIAS_WORKENV, and
// the second argument is the name of the option box given
// in the scheme file. The third argument is a directory
// path(possibly NULL) where to look for the scheme file.
// If a call to this method is omitted, there will be no option box.
if ( sSuccess != h.setOptionBox( "frame.scm", "frame.options", dirScm) ) {
AlPrintf(
kPrompt,
"Frame plug-in unable to find .scm file for option box"
);
return (1);
}
// Indicate which menu to add the plugin to. addToMenu()
// adds the plugin to the bottom of the menu, while
// appendToMenu() will add it to the top of the menu.
h.addToMenu( "mp_objtools" );
h.setIconPath( makeAltPath( dirName, NULL ) );
// Return a success code.
// Returning a non zero indicates an error.
// An error value ( a non-zero ) will be printed on the prompt
// line in Alias.
AlPrintf( kPrompt, "Frame attached to Palette 'Object Edit'");
return 0;
}
extern "C"
int plugin_exit( void )
{
// Remove the plugin from the menu and free the FunctionHandle.
// Note that h.destroy() implicitly calls h.removeFromMenu()
h.deleteObject();
hFunc.deleteObject();
return 0;
}
This example is a skeleton for continuous plug-ins. It echoes all user interaction to stdout.
// cont.plugin
//
// This file implements a simple continuous function plugin, a plugin
// that gets events from Alias and can interact with the user. It can
// be used as a skeleton from which to construct other, more complicated
// continuous functions if desired.
//
#include <AlLiveData.h>
#include <AlFunction.h>
#include <AlFunctionHandle.h>
#include <AlUniverse.h>
#include <AlDagNode.h>
#include <AlPickList.h>
#include <AlPickable.h>
#include <AlWindow.h>
char inbuf[ 256 ];
char text_buf[ 100 ];
const char * my_prompt = "Enter some text: %s";
extern char * makeAltPath(const char *dirName, const char *suffix);
void go_button_pressed( void )
{
AlPrintf( kStdout, "Go button pressed!\n" );
AlContinuousFunction::createGoButton( go_button_pressed );
}
static void init_func( void ) {
AlPrintf( kStdout, "Now entering continuous plugin.\n" );
AlContinuousFunction::createGoButton( go_button_pressed );
}
static void down_func( int input, Screencoord x, Screencoord y )
{
int button;
double dx=-1, dy=-1, dz=-1, ex=-1, ey=-1, ez=-1;
AlWindow * w;
switch( AlContinuousFunction::translateInput( input, button ) ) {
case kInputButton:
w = AlUniverse::currentWindow();
w->mapToWorldSpace( x, y, dx, dy, dz, ex, ey, ez );
AlPrintf( kStdout, "Mousedown at %d,%d [%lf,%lf,%lf %lf,%lf,%lf]. Button
%d.\n",
x,y, dx,dy,dz, ex,ey,ez, button );
delete w;
break;
}
}
static void move_func( int input, Screencoord x, Screencoord y )
{
int button;
double dx=-1, dy=-1, dz=-1, ex=-1, ey=-1, ez=-1;
AlWindow * w;
switch( AlContinuousFunction::translateInput( input, button ) ) {
case kInputButton:
w = AlUniverse::currentWindow();
w->mapToWorldSpace( x, y, dx, dy, dz, ex, ey, ez );
AlPrintf( kStdout, "Mousemove at %d,%d [%lf,%lf,%lf %lf,%lf,%lf]. Button
%d.\n",
x,y, dx,dy,dz, ex,ey,ez, button );
delete w;
break;
case kInputKeyboard:
sscanf( inbuf, "%s", text_buf );
AlPrintf( kStdout, "Text input: %s [%s]\n", text_buf, inbuf );
break;
}
}
static void up_func( int input, Screencoord x, Screencoord y )
{
int button;
double dx=-1, dy=-1, dz=-1, ex=-1, ey=-1, ez=-1;
AlWindow * w;
switch( AlContinuousFunction::translateInput( input, button ) ) {
case kInputButton:
w = AlUniverse::currentWindow();
w->mapToWorldSpace( x, y, dx, dy, dz, ex, ey, ez );
AlPrintf( kStdout, "Mouseup at %d,%d [%lf,%lf,%lf %lf,%lf,%lf]. Button
%d.\n",
x,y, dx,dy,dz, ex,ey,ez, button );
delete w;
break;
}
}
static void cleanup_func() {
AlPrintf( kStdout, "Now leaving continuous plugin.\n" );
AlContinuousFunction::clearGoButton( TRUE );
}
AlFunctionHandle h;
AlContinuousFunction hFunc;
extern "C"
int plugin_init( void )
{
AlUniverse::initialize();
hFunc.create( "Continuous", init_func, down_func, move_func,
up_func, cleanup_func, TRUE );
hFunc.setPrompt( my_prompt, inbuf, kFilterNone );
h.create( "Cont Test", &hFunc );
h.setAttributeString( "cont" );
h.setIconPath( makeAltPath( dirName, NULL ) );
h.addToMenu( "mp_objtools" );
AlPrintf( kPrompt, "Continuous example installed on Palette 'Object Edit.");
return 0;
}
extern "C"
int plugin_exit( void )
{
h.removeFromMenu();
h.deleteObject();
hFunc.deleteObject();
return 0;
}