int DirToArray(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; XString filename((CKSTRING) beh->GetInputParameterReadDataPtr(0)); XString Mask((CKSTRING) beh->GetInputParameterReadDataPtr(1)); int rec; beh->GetInputParameterValue(2,&rec); if( beh->IsInputActive(0) ){ beh->ActivateInput(0,FALSE); flist.erase(flist.begin(),flist.end()); CKDirectoryParser MyParser(filename.Str(),Mask.Str(),rec); char* str = NULL; while(str = MyParser.GetNextFile()) flist.push_back(XString(str)); counter = 0; beh->ActivateInput(1,TRUE); } if( beh->IsInputActive(1) ){ beh->ActivateInput(1,FALSE); if ( counter < flist.size() ){ XString entry = flist.at(counter); CKParameterOut * pout = beh->GetOutputParameter(0); pout->SetStringValue(entry.Str() ); counter++; beh->SetOutputParameterValue(1,&counter); beh->ActivateOutput(1); }else{ beh->SetOutputParameterValue(1,&counter); counter = 0 ; beh->ActivateOutput(0); } } return 0; }
int FTPLogin(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; if( beh->IsInputActive(0)){ beh->ActivateInput(0,FALSE); HWND win = (HWND)ctx->GetMainWindow(); FtpInit(win); //HFILE hLogFile = _lcreat (LOG_FILE, 0); //FtpLogTo (hLogFile); FtpSetDefaultTimeOut (30); FtpSetPassiveMode(TRUE); FtpSetAsynchronousMode(); int Port; beh->GetInputParameterValue(3,&Port); XString Host((CKSTRING) beh->GetInputParameterReadDataPtr(0)); XString User((CKSTRING) beh->GetInputParameterReadDataPtr(1)); XString Pw((CKSTRING) beh->GetInputParameterReadDataPtr(2)); int Login = FtpLogin(Host.Str(),User.Str(),Pw.Str(),win,0); beh->SetOutputParameterValue(0,&Login); if (Login == 0)beh->ActivateOutput(0); else{ beh->ActivateOutput(2); return CKBR_OK; } return CKBR_ACTIVATENEXTFRAME; } if( beh->IsInputActive(1)){ beh->ActivateInput(1,FALSE); FtpCloseConnection(); FtpRelease (); beh->ActivateOutput(1); return CKBR_OK; } return CKBR_ACTIVATENEXTFRAME; }
int GetFile(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; int Length=0; // Start by In0 if( beh->IsInputActive(0)){ beh->ActivateInput(0,FALSE); XString RemoteFile((CKSTRING) beh->GetInputParameterReadDataPtr(0)); XString LocalFile((CKSTRING) beh->GetInputParameterReadDataPtr(1)); char *Type = "Type_B"; int Get = FtpRecvFile ( RemoteFile.Str(),LocalFile.Str(),*Type, FALSE,NULL,NULL); Length = FtpBytesToBeTransferred(); if ( Get !=0 ){ beh->SetOutputParameterValue(3,&Get); beh->ActivateOutput(2); return CKBR_OK; } beh->SetOutputParameterValue(0,&Length); beh->ActivateOutput(0); return CKBR_ACTIVATENEXTFRAME; } beh->GetOutputParameterValue(0,&Length); int down=FtpBytesTransferred(); beh->SetOutputParameterValue(1,&down); float progress=(float)(down*100.0f/Length); // percentage of file downloaded progress /=100.0f; beh->SetOutputParameterValue(2,&progress); if ( down == Length){ beh->ActivateOutput(1); return CKBR_OK; } return CKBR_ACTIVATENEXTFRAME; }
int SetCIConnectionDetails(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; GBLConfigurationManager* cman=(GBLConfigurationManager*)ctx->GetManagerByGuid(CONFIGURATION_MAN_GUID); CGBLSyncInterface *CINetworkInterface = cman->GetSynInterface(); /************************************************************************/ /* check interface : */ /* */ if (!CINetworkInterface->isValidInterface()) { //try to init the network interface : if (!CINetworkInterface->Init(ctx)) { return CKBR_BEHAVIORERROR; } } /************************************************************************/ /* process building block events : */ /* */ if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); XString message((CKSTRING) beh->GetInputParameterReadDataPtr(0)); int connectionID = -1; beh->GetInputParameterValue(1,&CINetworkInterface->connectionID); CKAttributeManager *aMan = static_cast<CKAttributeManager*>(ctx->GetAttributeManager()); ////////////////////////////////////////////////////////////////////////// //store connection details in the scipt dummies attribute : CKAttributeType gblNetworkAtt = aMan->GetAttributeTypeByName( GBL_API_ENTRY("NetworkDetails")); if (!CINetworkInterface->messageDummy->HasAttribute(gblNetworkAtt) ) { CINetworkInterface->messageDummy->SetAttribute(gblNetworkAtt); } GBLCommon::ParameterTools::SetParameterStructureValue<int>(CINetworkInterface->messageDummy->GetAttributeParameter(gblNetworkAtt),0,CINetworkInterface->connectionID); GBLCommon::ParameterTools::SetParameterStructureValue<CKSTRING>(CINetworkInterface->messageDummy->GetAttributeParameter(gblNetworkAtt),1,CINetworkInterface->messageName.Str()); ////////////////////////////////////////////////////////////////////////// //activate and execute the script : behcontext.CurrentScene->Activate(CINetworkInterface->synchronizeScript,true); behcontext.CurrentScene->Activate(CINetworkInterface->messageDummy,FALSE); CINetworkInterface->synchronizeScript->Execute(1); beh->ActivateOutput(0); } return CKBR_OK; }
CKERROR CallPythonFuncCB2(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior *beh = behcontext.Behavior; CKContext* ctx = beh->GetCKContext(); CKParameterManager *pm = static_cast<CKParameterManager*>(ctx->GetParameterManager()); /************************************************************************/ /* process virtools callbacks : */ /* */ switch(behcontext.CallbackMessage) { case CKM_BEHAVIOREDITED: case CKM_BEHAVIORSETTINGSEDITED: { assert(beh && ctx); int p_count = beh->GetOutputParameterCount(); /*while( (BEH_OUT_MIN_COUNT ) < p_count ) { CKDestroyObject( beh->RemoveOutputParameter( --p_count) ); }*/ XString name("PyFuncX: "); name << ((CKSTRING) beh->GetInputParameterReadDataPtr(1)); if ( strlen(((CKSTRING) beh->GetInputParameterReadDataPtr(1))) ==0) { XString name("PyFileX: "); name << ((CKSTRING) beh->GetInputParameterReadDataPtr(0)); beh->SetName(name.Str()); break; } beh->SetName(name.Str()); break; } case CKM_BEHAVIORATTACH: case CKM_BEHAVIORLOAD : { XString name("PyFuncX: "); name << ((CKSTRING) beh->GetInputParameterReadDataPtr(1)); beh->SetName(name.Str()); if ( strlen(((CKSTRING) beh->GetInputParameterReadDataPtr(1))) ==0) { XString name("PyFileX: "); name << ((CKSTRING) beh->GetInputParameterReadDataPtr(0)); beh->SetName(name.Str()); break; } } } return CKBR_OK; }
int SetCIConnectionDetails(const CKBehaviorContext& behcontext) { /************************************************************************/ /* collecting data : */ /* */ CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; MeasuredObjectiveControllerMgr* mman=(MeasuredObjectiveControllerMgr*)ctx->GetManagerByGuid(MeasuredObjectiveControllerMgrGUID); CGBLSyncInterface * syninterface = CGBLLOArrayHandler::Instance()->GetSynInterface(); /************************************************************************/ /* check interface : */ /* */ if (!syninterface->isValidInterface()) { Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"interface wrong"); //try to init the network interface : if (!syninterface->Init(ctx)) { Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"not loaded"); return CKBR_BEHAVIORERROR; } } /************************************************************************/ /* process building block events : */ /* */ if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); XString message((CKSTRING) beh->GetInputParameterReadDataPtr(0)); int connectionID = -1; beh->GetInputParameterValue(1,&syninterface->connectionID); CKAttributeManager *aMan = static_cast<CKAttributeManager*>(ctx->GetAttributeManager()); ////////////////////////////////////////////////////////////////////////// //store connection details in the scipt dummies attribute : CKAttributeType gblNetworkAtt = aMan->GetAttributeTypeByName( GBL_API_ENTRY("NetworkDetails")); if (!syninterface->messageDummy->HasAttribute(gblNetworkAtt) ) { syninterface->messageDummy->SetAttribute(gblNetworkAtt); } GBLCommon::ParameterTools::SetParameterStructureValue<int>(syninterface->messageDummy->GetAttributeParameter(gblNetworkAtt),0,syninterface->connectionID); GBLCommon::ParameterTools::SetParameterStructureValue<CKSTRING>(syninterface->messageDummy->GetAttributeParameter(gblNetworkAtt),1,syninterface->messageName.Str()); ////////////////////////////////////////////////////////////////////////// //activate and execute the script : behcontext.CurrentScene->Activate(syninterface->synchronizeScript,true); behcontext.CurrentScene->Activate(syninterface->messageDummy,FALSE); syninterface->synchronizeScript->Execute(1); beh->ActivateOutput(0); } return CKBR_OK; }
/* ******************************************************************* * Function: int BehaviourFunction() * * Description : Returns the number of plugins in this DLL * * Paramters : * CKBehaviorContext& r The virtools behaviour context * * Returns : One of the many virtools return values * ******************************************************************* */ int CGBLFileSystem::BehaviourFunction(const CKBehaviorContext& behContext) { BOOL error = FALSE; // Quick bit of error checking CKBehavior* beh = behContext.Behavior; CKBeObject* beObject = beh->GetTarget(); int fileSystemBrowseMode = 0; if (!beObject) { error = TRUE; } if (!error) { // Reset On input, if active if (beh->IsInputActive(eBehInputOn)) { beh->ActivateInput(eBehInputOn, FALSE); // Clear error message output beh->SetOutputParameterValue(eParamOutputErrorMsg, EMPTY_STRING); } // see which mode we are in beh->GetInputParameterValue(eParamInputMode, &fileSystemBrowseMode); } if (!error) { // See if we have the special case char *currentFolder = NULL; currentFolder = (char*)(beh->GetInputParameterReadDataPtr(eParamInputCurrentFolder)); XString scannedFolder = currentFolder; if (currentFolder) { // special case takes priority over FILES / FOLDER mode if (strcmp(currentFolder,SPECIAL_CASE)==0) { beh->SetOutputParameterValue(eParamOutputScannedFolder, scannedFolder.CStr(),scannedFolder.Length()+1 ); if (fileSystemBrowseMode == eFolder) { if (GetLogicalDrives(beh)) { // Everythings gone ok we have a list of the logical drives beh->ActivateOutput(eBehOutputDone, TRUE); } else { // Something went wrong beh->SetOutputParameterValue(eParamOutputErrorMsg, "Failed To Scan The Logical Drives"); beh->ActivateOutput(eBehOutputError, TRUE); } } else { // Cant scan for files in the SPECIAL_CASE // Get the destination data array and clear it out CKDataArray* dataArray = static_cast<CKDataArray*>(beh->GetInputParameterObject(eParamInputDataArray)); if (!dataArray) { CGBLWidget::OutputBBErrorMsg(beh, "Please attatch an array to the BB"); } else { dataArray->Clear(); dataArray->AddRow(); int currentRow = dataArray->GetRowCount()-1; // 0 index dataArray->SetElementStringValue(currentRow,NAME_COLUMN,NOT_FOUND); beh->ActivateOutput(eBehOutputDone, TRUE); } } } else { // add a "\" to the end, it makes the ouput consistent. int len = strlen (scannedFolder.CStr()); if ((scannedFolder[len-1])!=SINGLE_SEPERATOR) { scannedFolder << SINGLE_SEPERATOR; } // Try to scan the passed folder if (GetData(beh,fileSystemBrowseMode)==FALSE) { // Error Handling we can handle errors here // We most likely got here because the user doesnt have access to the folder. if (fileSystemBrowseMode == eFile) { beh->SetOutputParameterValue(eParamOutputErrorMsg, "Failed To Scan Files"); } else { beh->SetOutputParameterValue(eParamOutputErrorMsg, "Failed To Scan Folders"); } beh->ActivateOutput(eBehOutputDone, TRUE); // Handleable, recoverable errors, so dont set the error flag //beh->ActivateOutput(eBehOutputError, TRUE); } else { // No errors beh->SetOutputParameterValue(eParamOutputScannedFolder, scannedFolder.CStr(), scannedFolder.Length() + 1); beh->ActivateOutput(eBehOutputDone, TRUE); } } } else { // Dont think we can ever get here becuase "" is a valid folder. // Just in case though. beh->SetOutputParameterValue(eParamOutputErrorMsg, "Please Supply a Folder To Scan"); beh->ActivateOutput(eBehOutputError, TRUE); } } return CKBR_OK; }
int LogEntry(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKMessageManager* mm = behcontext.MessageManager; CKContext* ctx = behcontext.Context; CKParameterManager *pam = static_cast<CKParameterManager *>(ctx->GetParameterManager()); XString File((CKSTRING) beh->GetInputParameterReadDataPtr(0)); if (GetPMan()->GetLastLogEntry().Length()) { CKParameterOut *pout = beh->GetOutputParameter(0); pout->SetStringValue(GetPMan()->GetLastLogEntry().Str()); GetPMan()->SetLastLogEntry(""); vtTools::BehaviorTools::SetOutputParameterValue<int>(beh,1,xLogger::GetInstance()->lastTyp); int descriptionS = xLogger::GetInstance()->getItemDescriptions().size(); int compo = xLogger::GetInstance()->lastComponent; XString compoStr; /*if(compo<= xLogger::GetInstance()->getItemDescriptions().size() ) compoStr.Format("%s",xLogger::GetInstance()->getItemDescriptions().at(compo));*/ beh->ActivateOutput(0,TRUE); switch (xLogger::GetInstance()->lastTyp) { case ELOGERROR: beh->ActivateOutput(1,TRUE); case ELOGWARNING: beh->ActivateOutput(2,TRUE); case ELOGINFO: beh->ActivateOutput(3,TRUE); case ELOGTRACE: beh->ActivateOutput(4,TRUE); case ELOGDEBUG: beh->ActivateOutput(5,TRUE); default: beh->ActivateOutput(0,TRUE); } } // Steering if( beh->IsInputActive(1) ) { beh->ActivateOutput(0,FALSE); return 1; } return CKBR_ACTIVATENEXTFRAME; }
/* ******************************************************************* * Function: int BehaviourFunction() * * Description : * * Paramters : * CKBehaviorContext& r The virtools behaviour context * * Returns : One of the many virtools return values * ******************************************************************* */ int CGBLLOStringBuilder::BehaviourFunction(const CKBehaviorContext& behContext) { CKBehavior* beh = behContext.Behavior; CKBeObject* beObject = beh->GetTarget(); CKBOOL error = FALSE; XString outString = NULL; // error check to ensure virtools is working ok if (!beObject) { error = TRUE; CKParameterOut *parameterOutError = beh->GetOutputParameter(EGBLStringBuilderParamOutputs::eParamGetError); TGBLError::SetTGBLError(parameterOutError,CGBLCOError::EGBLCOErrorType::GBLCO_FATAL,LOI_ERROR_NO_BEHAVIOUR_STATE,LOI_ERROR_NO_BEHAVIOUR_DESC); beh->SetOutputParameterValue(eParamGetError, parameterOutError); beh->ActivateOutput(eBehOutputError, TRUE); } int lengthOfSource = 0; int lengthOfInsert = 0; int insertPosition = 0; if (!error) { // Reset On input, if active if (beh->IsInputActive(eBehInputOn)) { beh->ActivateInput(eBehInputOn, FALSE); } // get the BB params into variables to work with XString sourceString = NULL; sourceString = (CKSTRING)(beh->GetInputParameterReadDataPtr(eParamSetSourceString)); XString insertString = NULL; insertString = (CKSTRING)(beh->GetInputParameterReadDataPtr(eParamSetInsertString)); beh->GetInputParameterValue(eParamSetInsertPosition,&insertPosition); lengthOfSource = strlen(sourceString.Str()); lengthOfInsert = strlen(insertString.Str()); // Simple bounds checking and error recovery if (insertPosition<0) { insertPosition=0; } if (insertPosition>lengthOfSource) { outString = sourceString; outString += insertString; } else { // a little more error checking and simple recovery // deal with the special cases first if (lengthOfSource<=0) { // an empty source outString = insertString; } else if (insertPosition == 0) { outString = insertString; outString += sourceString; } else { // build up the new string XString start = NULL; XString end = NULL; start = sourceString.Substring(0,insertPosition); end = sourceString.Substring(insertPosition,lengthOfSource); outString = start ; outString += insertString; outString += end; } } } if (!error) { int newCartPos = insertPosition+lengthOfInsert; beh->SetOutputParameterValue(eParamGetCarretPosition,&newCartPos); beh->SetOutputParameterValue(eParamGetNewText, outString.CStr(), outString.Length() + 1); beh->ActivateOutput(eBehOutputDone, TRUE); } return CKBR_OK; }
int CallPythonFunc2(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; XString File((CKSTRING) beh->GetInputParameterReadDataPtr(0)); XString Func((CKSTRING) beh->GetInputParameterReadDataPtr(1)); int reload=false; //= BehaviorTools::GetInputParameterValue<bool>(beh,2); beh->GetInputParameterValue(2,&reload); vt_python_man *pm = (vt_python_man*)ctx->GetManagerByGuid(INIT_MAN_GUID); CKParameterManager *pam = static_cast<CKParameterManager *>(ctx->GetParameterManager()); Python *py = pm->py; if (!pm->pLoaded) { pm->m_Context->OutputToConsoleEx("You must load Python before !"); beh->ActivateOutput(1,false); return CKBR_BEHAVIORERROR; } ////////////////////////////////////////////////////////////////////////// if( beh->IsInputActive(0) ) { try { PyObject *module = pm->InsertPModule(beh->GetID(),File,reload); PyObject* val = PyInt_FromLong(beh->GetID()); PyObject_SetAttrString( module , "bid", val); pm->CallPyModule(beh->GetID(),Func); } catch (Python_exception ex) { pm->m_Context->OutputToConsoleEx("PyErr : \t %s",(CKSTRING)ex.what()); std::cout << ex.what() << "pyexeption in beh : " << beh->GetName(); PyErr_Clear(); beh->ActivateOutput(1,false); } beh->ActivateInput(0,false); } ////////////////////////////////////////////////////////////////////////// else { for (int i = 1 ; i < beh->GetOutputCount() ; i++ ) { try { PyObject *module = pm->GetPModule(beh->GetID()); if(module) pm->CallPyModule(beh->GetID(),Func); } catch (Python_exception ex) { pm->m_Context->OutputToConsoleEx("PyErr : \t %s",(CKSTRING)ex.what()); std::cout << ex.what() << "pyexeption in beh : " << beh->GetName(); beh->ActivateOutput(1,TRUE); return CKBR_BEHAVIORERROR; } beh->ActivateInput(i,false); } } return CKBR_OK; }
int PlayFFEffect(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx2 = behcontext.Context; ctx = ctx2; HWND mWin = (HWND )ctx->GetMainWindow(); //init and load effect if( beh->IsInputActive(0) ){ beh->ActivateInput(0,FALSE); HRESULT result = InitDirectInput(mWin); HRESULT sa = S_OK; if (InitDirectInput(mWin) == S_OK) { XString filename((CKSTRING) beh->GetInputParameterReadDataPtr(0)); OnReadFile(mWin,filename.Str()); beh->ActivateOutput(0); return CKBR_OK; }else{ beh->ActivateOutput(4); return CKBR_OK; } } //play if( beh->IsInputActive(1) ){ beh->ActivateInput(1,FALSE); if (OnPlayEffects2(NULL) != S_OK ){ beh->ActivateOutput(4); return CKBR_OK; } beh->ActivateOutput(1); return CKBR_OK; } //stop the effect if( beh->IsInputActive(2) ){ beh->ActivateInput(2,FALSE); // Stop all previous forces g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ); beh->ActivateOutput(2); return CKBR_OK; } // [11/7/2004] //save device release if( beh->IsInputActive(3) ){ beh->ActivateInput(3,FALSE); if ( g_pFFDevice) g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ); FreeDirectInput2(); beh->ActivateOutput(3); return CKBR_OK; } return CKBR_OK; }