int AddNodalLink(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; CKAttributeManager* attman = ctx->GetAttributeManager(); beh->ActivateInput(0,FALSE); beh->ActivateOutput(0); CKGroup* group = (CKGroup*)beh->GetInputParameterObject(0); CKParameterOut* param = group->GetAttributeParameter(attman->GetAttributeTypeByName(Network3dName)); if(!param) throw "Given Group isn't a Network"; N3DGraph* graph; param->GetValue(&graph); CK3dEntity* s = (CK3dEntity*)beh->GetInputParameterObject(1); CK3dEntity* e = (CK3dEntity*)beh->GetInputParameterObject(2); float b; beh->GetInputParameterValue(3,&b); graph->InsertEdge(s,e,b); beh->ActivateOutput(0); return CKBR_OK; }
//************************************ // Method: RegisterAttributeType // FullName: RegisterAttributeType // Access: public // Returns: int // Qualifier: // Parameter: const CKBehaviorContext& behcontext //************************************ int RegisterAttributeType(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; CKContext* ctx = behcontext.Context; PhysicManager *pm = GetPMan(); CKAttributeManager* attman = ctx->GetAttributeManager(); CKParameterManager *pMan = ctx->GetParameterManager(); using namespace vtTools::BehaviorTools; if( beh->IsInputActive(0) ) { beh->ActivateInput(0,FALSE); CKSTRING name = GetInputParameterValue<CKSTRING>(beh,bbI_Name); CKSTRING category = GetInputParameterValue<CKSTRING>(beh,bbI_Category); CKSTRING defValue = GetInputParameterValue<CKSTRING>(beh,bbI_DefValue); int pType = GetInputParameterValue<int>(beh,bbI_PType); CK_CLASSID classId = GetInputParameterValue<CK_CLASSID>(beh,bbI_Class); int attFlags = 0 ; int user = GetInputParameterValue<int>(beh,bbI_User); int save = GetInputParameterValue<int>(beh,bbI_Save); if(user) attFlags|=CK_ATTRIBUT_USER; if(save) attFlags|=CK_ATTRIBUT_TOSAVE; attFlags|=CK_ATTRIBUT_CAN_DELETE; CKAttributeType aIType = attman->GetAttributeTypeByName(name); if (aIType!=-1) { beh->ActivateOutput(1); } int att = attman->RegisterNewAttributeType(name,pMan->ParameterTypeToGuid(pType),classId,(CK_ATTRIBUT_FLAGS)attFlags); if (strlen(category)) { attman->AddCategory(category); attman->SetAttributeCategory(att,category); } if (strlen(defValue)) { attman->SetAttributeDefaultValue(att,defValue); } } pm->populateAttributeFunctions(); pm->_RegisterAttributeCallbacks(); beh->ActivateOutput(0); return 0; }
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; }
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:Init() * * Description : For using virtools network functionalities from SDK, you need to add your wished packet here. The building block HIDDEN_PacketIterator will pass all entries to the virtools network building blocks in the GBLCustomisationNetDummy.nmo - script * * Parameters : CKContext *ctx, r : the virtools context * Returns : CKBOOL = True, if a valid script was loaded. ******************************************************************* */ CKBOOL CGBLSyncInterface::Init(CKContext *ctx) { assert(ctx); context = ctx; CKBOOL result = false; //get the handle to this dll : HMODULE resourceModule = GBLCommon::ResourceTools::GetParentModule(CKPLUGIN_MANAGER_DLL,MeasuredObjectiveControllerMgrGUID); if(!resourceModule) { Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"MOController : wrong dll handle for sync script "); return result; }else { //loads the schematic script as dynamic : CK_LOAD_FLAGS loadoptions = CK_LOAD_FLAGS(CK_LOAD_DEFAULT|CK_LOAD_AUTOMATICMODE|CK_LOAD_AS_DYNAMIC_OBJECT); CKObjectArray *loadedObjects = CreateCKObjectArray(); /* The Loading by self : Remarks : + for debuging purposes, you can load the script from a file as follows : if(GBLCommon::ResourceTools::LoadFromFile(ctx,"c:\\yourFile.nmo",false,loadoptions,loadedObjects)) + you should save a new script as hidden inside virtools */ //if(GBLCommon::ResourceTools::LoadFromFile(ctx,"C:\\NetworkScriptDebug.nmo",true,loadoptions,loadedObjects)) if(GBLCommon::ResourceTools::LoadFromResource ( resourceModule, context, GBLDebugBuild ? RES_MOCONTROLLER_NETSCRIPT_DEBUG : RES_MOCONTROLLER_NETSCRIPT , //loads a hidden script or not true, loadoptions, loadedObjects) ) { //we iterate through the loaded objects to get the dummy and also the script : for( loadedObjects->Reset() ; !loadedObjects->EndOfList() ; ) { CKObject *tmpObj = loadedObjects->GetData( ctx ); // is the script ? : if( tmpObj->GetClassID() == CKCID_BEHAVIOR ) { synchronizeScript = static_cast<CKBehavior*>(tmpObj); } //is the script holder ? : CK3dEntity *tmpEnt = static_cast<CK3dEntity*>(tmpObj); if (tmpEnt && (tmpEnt->GetFlags()&CK_3DENTITY_FRAME)) { messageDummy = tmpEnt; //adds the GBLConnectionDetails : CKAttributeManager *aMan = static_cast<CKAttributeManager*>(ctx->GetAttributeManager()); CKAttributeType gblNetworkAtt = aMan->GetAttributeTypeByName(GBL_API_ENTRY("NetworkDetails")); if (!messageDummy->HasAttribute(gblNetworkAtt) ) { messageDummy->SetAttribute(gblNetworkAtt); } GBLCommon::ParameterTools::SetParameterStructureValue<int>(messageDummy->GetAttributeParameter(gblNetworkAtt),0,connectionID); GBLCommon::ParameterTools::SetParameterStructureValue<CKSTRING>(messageDummy->GetAttributeParameter(gblNetworkAtt),1,messageName.Str()); //yo, everything is gone fine : result = true; } loadedObjects->Next(); } if( !messageDummy || !synchronizeScript) { Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"MOController : script dosnt contains any valid object \n\t Please check virtools network connection !"); return false; } DeleteCKObjectArray(loadedObjects); }else { Logger::ShowDebugMessage(ctx,Logger::ELOGERROR,"MOController: couldn't load script"); return false; } } return result; }