Example #1
0
// Simplify_Activate():
//  Simplify Object Replacement Plug-In's Activate Function
XCALL_ (int) Simplify_Activate(  long version, GlobalFunc *global,
                                 ObjReplacementHandler *local, void *serverData ) {

  // Version Check
  if( version != 3 )
    return( AFUNC_BADVERSION );

  XCALL_INIT;

  // Fill in the local data
	local->create   = SimplifyCreate;
	local->destroy  = SimplifyDestroy;
	local->load     = SimplifyLoad;
	local->save     = SimplifySave;
	local->copy     = SimplifyCopy;

	local->evaluate = SimplifyEvaluate;
	local->descln   = SimplifyDescribeLine;

  local->useItems = SimplifyUseItems;
  local->changeID = SimplifyChangeID;

  // Get the Camera ID
  if( SimplifyInstance::GetCameraID() == NULL ) {
    LWItemInfo *info = (LWItemInfo *) ( (*global)("LW Item Info", GFUSE_TRANSIENT) );
    SimplifyInstance::SetCameraID( (*info->first)( LWI_CAMERA, NULL ) );
  }

  // Set the Global Functions
  if( SimplifyInstance::GetGlobal() == NULL )
    SimplifyInstance::SetGlobal( global );

  // Load the default config file
  if( !simp_config.WasLoaded() ) {
    DirInfoFunc * dir_func = (DirInfoFunc *) ( (*global)("Directory Info", GFUSE_TRANSIENT) );
    char def_config[ MAX_PATH_LENGTH ];

    // First try the Install Path
    strcpy( def_config, (*dir_func)( "Install" ) );
    DirStrings::AddPathPart( def_config, "Simplify.cfg" );

    if( !DirInfo::Exists( def_config ) ) {
      // Then the Programs Dir
      strcpy( def_config, (*dir_func)( "Install" ) );
      DirStrings::AddPathPart( def_config, "Programs/Simplify.cfg" );

      // Then the Alternate Settings Dir
      if( !DirInfo::Exists( def_config ) ) {
        strcpy( def_config, (*dir_func)( "Settings" ) );
        DirStrings::AddPathPart( def_config, "Simplify.cfg" );

        // Then the Plug-ins Dir
        if( !DirInfo::Exists( def_config ) ) {
          const char * temp = (*dir_func)( "Plugins" );
          if( temp != NULL ) {
            strcpy( def_config, temp );
            DirStrings::AddPathPart( def_config, "Simplify.cfg" );

            // And finally, the Layout Plug-ins Dir
            if( !DirInfo::Exists( def_config ) ) {
              strcpy( def_config, temp );
              DirStrings::AddPathPart( def_config, "Layout/Simplify.cfg" );
            }
          }
        }
      }
    }

    CMessage * message = CMessage::New( (MessageFuncs *) ( (*global)("Info Messages", GFUSE_TRANSIENT) ) );
#ifdef _DEBUG
    message->Info( "Config File Path:", def_config );
#endif
  
    switch( simp_config.Load( def_config ) ) {
    case SIMPCONFIG_OK:                          // Config loaded OK
    case SIMPCONFIG_NOT_FOUND:                   // This is OK; just means use the default settings
      break;

    case SIMPCONFIG_ERROR_OPENING_FILE:          // Error; say so
      message->Error( "Simplify Error:  Error occurred opening the Simplify Config File",
                      def_config );
      break;

    case SIMPCONFIG_ERROR_READING_FROM_FILE:     // Another error; say so
      message->Error( "Simplify Error:  Error occurred reading the Simplify Config File",
                      def_config );
      break;

    case SIMPCONFIG_ERROR_NOT_SIMP_CONFIG:       // Not a config; report an error
      message->Error( "Simplify Error:  This is not a Simplify Config File:",
                      def_config );
      break;
    };

    delete message;
  }

  return AFUNC_OK;
}
Example #2
0
// SimplifyCreate()
XCALL_ (LWInstance) SimplifyCreate( LWError	*err, LWItemID item ) {
  SimplifyInstance *inst = new SimplifyInstance;

  // Make sure the instance was allocated OK
  if( inst == NULL ) {
    const char *string = "Simplify Error:  Unable to create instance!";
    err = &string;
    return NULL;
  }

  // Get the Object Info Functions so we can get the object's filename
  CLWObjectInfo * obj_info = CLWObjectInfo::New( (LWObjectInfo *) (*SimplifyInstance::GetGlobal())("LW Object Info", GFUSE_TRANSIENT ) );
  CMessage * message = CMessage::New( (MessageFuncs *) (*SimplifyInstance::GetGlobal())("Info Messages", GFUSE_TRANSIENT) );

  if( !obj_info ) {
    message->Error( "Simplify Error:  Unable to get LW Object Info!" );
    return false;
  }

  // Set the Defauit Nominal Camera Zoom, in case the auto-load fails
  LWItemInfo *iteminfo = (LWItemInfo *)(*SimplifyInstance::GetGlobal())( "LW Item Info", GFUSE_TRANSIENT );
  LWItemID cam_id = (*iteminfo->first)( LWI_CAMERA, NULL );
  LWCameraInfo *camerainfo = (LWCameraInfo *)(*SimplifyInstance::GetGlobal())( "LW Camera Info", GFUSE_TRANSIENT );

  double default_zoom_factor = (*camerainfo->zoomFactor)( cam_id, 0 );
  inst->SetLODNominalCameraZoom( (float)default_zoom_factor );

  // See if an Auto-Load SDF exists
  char def_sdf[ MAX_PATH_LENGTH ];
  if( simp_global.autoload ) {
    // Get DirFuncs so we can get the Content Dir
    DirInfoFunc * dir_func = (DirInfoFunc *) (*SimplifyInstance::GetGlobal())("Directory Info", GFUSE_TRANSIENT );
    strcpy( def_sdf, obj_info->Filename( item ) );
    DirStrings::ChangeExtension( def_sdf, ".SDF" );
    inst->SetSDF( def_sdf );

    strcpy( def_sdf, (*dir_func)( "Content" ) );
    DirStrings::AddPathPart( def_sdf, inst->GetSDF() );

    if( DirInfo::Exists( def_sdf ) ) {
      char * error;
      if( !inst->LoadFromFile( def_sdf, error ) ) {
        // Error loading default instance; create a clean one
        delete inst;
        inst = new SimplifyInstance;
        message->Error( error_buffer );
        message->Error( "Simplify Error: Unable to auto-load default instance data for ", obj_info->Filename( inst->GetItemID() ) );
      }

      delete message;
    } else if( simp_config.GetDefaultSDF() != NULL ) {
      // Default SDF not found; load the default one from the user config, if it exists
      if( DirInfo::Exists( simp_config.GetDefaultSDF() ) ) {
        char * error;
        if( !inst->LoadFromFile( simp_config.GetDefaultSDF(), error ) ) {
          // Error loading default instance; create a clean one
          delete inst;
          inst = new SimplifyInstance;
          message->Error( error_buffer );
          message->Error( "Simplify Error: Unable to auto-load deafult instance data from",
                          simp_config.GetDefaultSDF() );
        }

        delete message;
      }
    }
  }

  // Set the item used by the instance
  inst->SetItemID( item );

  // Set the Render Filename to the object's filename, if needed
  if( inst->GetRender()[0] == '\0' )
    inst->SetRender( obj_info->Filename( inst->GetItemID() ) );

  // Free obj_info
  delete obj_info;

  // Instance OK; return it
  instances.Add( inst );
  err = NULL;
  return inst;
}