256 lines
7.4 KiB
C++
256 lines
7.4 KiB
C++
#include "StdAfx.h"
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// functions prototypes
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
CKERROR CreateLoadSelectionSetProto(CKBehaviorPrototype **pproto);
|
|
int LoadSelectionSetBB(const CKBehaviorContext& behcontext);
|
|
CKERROR LoadSelectionSetBBCallBack(const CKBehaviorContext& behcontext);
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// enums
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
enum INS
|
|
{
|
|
eINS_IN,
|
|
};
|
|
|
|
enum OUTS
|
|
{
|
|
eOUTS_SUCCESS,
|
|
eOUTS_FAILED,
|
|
};
|
|
|
|
enum PINS
|
|
{
|
|
ePINS_SET,
|
|
//ePINS_PATH=0,
|
|
ePINS_DYNAMIC,
|
|
};
|
|
|
|
enum POUTS
|
|
{
|
|
ePOUTS_GROUP,
|
|
};
|
|
|
|
enum PSETTINGS
|
|
{
|
|
//ePSETTINGS_TARGETBYNAME=0, //use group instead of name
|
|
ePSETTINGS_BYPATH,
|
|
ePSETTINGS_WEBHANDLE,
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// behavior
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
CKObjectDeclaration* FillBehaviorLoadSelectionSet()
|
|
{
|
|
CKObjectDeclaration *od = CreateCKObjectDeclaration(NAME_LOADSELECTIONSET);
|
|
od->SetDescription("Load a Selection Set.");
|
|
|
|
/* rem:
|
|
<SPAN CLASS=in>On : </SPAN>Activates the Progression Bar.<BR>
|
|
<SPAN CLASS=in>Off : </SPAN>Deactivates the Progression Bar.<BR>
|
|
<SPAN CLASS=in>Pause/Resume : </SPAN>Pause/Resume the Progression Bar.<BR>
|
|
<BR>
|
|
<SPAN CLASS=out>Exit On : </SPAN>This output is activated after entering by 'On'.<BR>
|
|
<SPAN CLASS=out>Exit Off : </SPAN>This output is activated after entering by 'Off'.<BR>
|
|
<SPAN CLASS=out>Exit Off : </SPAN>This output is activated after entering by 'Pause/Resume'.<BR>
|
|
<BR>
|
|
<SPAN CLASS=setting>Size Mode : </SPAN> - <BR>
|
|
<SPAN CLASS=setting>Orientation : </SPAN> - <BR>
|
|
<BR>
|
|
*/
|
|
/* Note:
|
|
Activate the "on" entry each time the target of the behavior is modified.
|
|
*/
|
|
od->SetType( CKDLL_BEHAVIORPROTOTYPE);
|
|
od->SetGuid(BBGUID_LOADSELECTIONSET);
|
|
od->SetAuthorGuid(VIRTOOLS_GUID);
|
|
od->SetAuthorName("Virtools");
|
|
od->SetVersion(0x00010000);
|
|
od->SetCreationFunction(CreateLoadSelectionSetProto);
|
|
od->SetCompatibleClassId(CKCID_BEOBJECT);
|
|
od->SetCategory("Selection Set");
|
|
return od;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
CKERROR CreateLoadSelectionSetProto(CKBehaviorPrototype **pproto)
|
|
{
|
|
CKBehaviorPrototype *proto = CreateCKBehaviorPrototype(NAME_LOADSELECTIONSET);
|
|
if(!proto) return CKERR_OUTOFMEMORY;
|
|
|
|
proto->DeclareInput("Load");
|
|
proto->DeclareOutput("Success");
|
|
proto->DeclareOutput("Failed");
|
|
|
|
proto->DeclareInParameter(STR_SELECTIONSET, CKPGUID_SELECTIONSET,0);
|
|
//proto->DeclareInParameter("Path", CKPGUID_STRING,"");
|
|
proto->DeclareInParameter("Dynamic",CKPGUID_BOOL,"FALSE");
|
|
|
|
proto->DeclareOutParameter("Group",CKPGUID_GROUP,0);
|
|
|
|
//proto->DeclareSetting(STR_BYNAME,CKPGUID_BOOL,FALSE);
|
|
proto->DeclareSetting(STR_BYPATH,CKPGUID_BOOL,FALSE);
|
|
proto->DeclareLocalParameter("",CKPGUID_INT,0);
|
|
|
|
proto->SetFunction(LoadSelectionSetBB);
|
|
proto->SetBehaviorCallbackFct(LoadSelectionSetBBCallBack);
|
|
proto->SetBehaviorFlags(BBFLAGS);
|
|
|
|
*pproto = proto;
|
|
return CK_OK;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
int LoadSelectionSetBB(const CKBehaviorContext& behcontext)
|
|
{
|
|
CKBehavior* beh = behcontext.Behavior;
|
|
SelectionSetManager* setmgr = (SelectionSetManager*)behcontext.Context->GetManagerByGuid(SELECTIONSETMANAGER_GUID);
|
|
|
|
int webhandle = 0;
|
|
beh->GetLocalParameterValue(ePSETTINGS_WEBHANDLE,&webhandle);
|
|
if (webhandle>0) //webdownload
|
|
{
|
|
CKGroup* setresult = 0;
|
|
ESetLoadResult res = setmgr->GetWebDownloadSetState(webhandle,setresult);
|
|
switch(res)
|
|
{
|
|
case eSetLoad_WebDownload:
|
|
return CKBR_ACTIVATENEXTFRAME;
|
|
default:
|
|
{
|
|
webhandle = 0;
|
|
beh->SetLocalParameterValue(ePSETTINGS_WEBHANDLE,&webhandle);
|
|
beh->SetOutputParameterObject(ePOUTS_GROUP,setresult);
|
|
if (res==eSetLoad_Success)
|
|
beh->ActivateOutput(eOUTS_SUCCESS);
|
|
else
|
|
beh->ActivateOutput(eOUTS_FAILED);
|
|
return CKBR_OK;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(beh->IsInputActive(eINS_IN))
|
|
{
|
|
BOOL bypath=FALSE;
|
|
beh->GetLocalParameterValue(ePSETTINGS_BYPATH,&bypath);
|
|
|
|
BOOL dynamic = FALSE;
|
|
beh->GetInputParameterValue(ePINS_DYNAMIC,&dynamic);
|
|
CKGroup* setresult = 0;
|
|
ESetLoadResult res;
|
|
|
|
if (bypath)
|
|
//if (path[0]!=0) //not empty string
|
|
{ //open by filename
|
|
char* path = (char*)beh->GetInputParameterReadDataPtr(ePINS_SET);
|
|
if (path[0]==0) //empty string
|
|
{
|
|
beh->ActivateOutput(eOUTS_FAILED);
|
|
return CK_OK;
|
|
}
|
|
|
|
SelectionSetData* data = new SelectionSetData;
|
|
//check if extension, if not add .nmo
|
|
//data->m_Path.Format("%s\\%s.nmo",path,name);
|
|
data->m_Path = path;
|
|
int dotindex = data->m_Path.RFind('.');
|
|
int slashindex = data->m_Path.RFind(DIRECTORY_SEP_CHAR);
|
|
int dot2index = data->m_Path.RFind(':');
|
|
if (dotindex==XString::NOTFOUND || dotindex<slashindex) //no extension in path
|
|
{ //check if something after '\',
|
|
//if not, add name then extension, otherwise extension only
|
|
data->m_Path += ".nmo";
|
|
}
|
|
//data->m_Name = name;
|
|
res = setmgr->LoadSelectionSet(setresult,data,dynamic);
|
|
}
|
|
else //open existing set
|
|
{
|
|
//BOOL byname=FALSE;
|
|
setresult = GetSetTarget();//(beh,setmgr,byname);
|
|
res = setmgr->LoadSelectionSet(setresult,dynamic);
|
|
}
|
|
|
|
if (res==eSetLoad_Success)
|
|
{
|
|
beh->SetOutputParameterObject(ePOUTS_GROUP,setresult);
|
|
beh->ActivateOutput(eOUTS_SUCCESS);
|
|
}
|
|
else
|
|
{
|
|
beh->SetOutputParameterObject(ePOUTS_GROUP,0);
|
|
if (res==eSetLoad_WebDownload)
|
|
{
|
|
int webhandle = setmgr->GetLastWebDownloadSetHandle();
|
|
if (webhandle>0)
|
|
{
|
|
beh->SetLocalParameterValue(ePSETTINGS_WEBHANDLE,&webhandle);
|
|
return CKBR_ACTIVATENEXTFRAME;
|
|
}
|
|
}
|
|
beh->ActivateOutput(eOUTS_FAILED);
|
|
}
|
|
}
|
|
return CKBR_OK;
|
|
}
|
|
|
|
CKERROR LoadSelectionSetBBCallBack(const CKBehaviorContext& behcontext)
|
|
{
|
|
//CKERROR er = TargetableSelectionSetBBCallBack(behcontext); //obsolete, no more "byname"
|
|
CKBehavior* beh = behcontext.Behavior;
|
|
switch( behcontext.CallbackMessage )
|
|
{
|
|
case CKM_BEHAVIORLOAD:
|
|
case CKM_BEHAVIORSETTINGSEDITED:
|
|
{
|
|
//change pin type according to setting
|
|
CKParameterIn* pin = beh->GetInputParameter(ePINS_SET);
|
|
BOOL bypath=FALSE;
|
|
beh->GetLocalParameterValue(ePSETTINGS_BYPATH,&bypath);
|
|
BOOL change = FALSE;
|
|
if (bypath && pin->GetGUID()==CKPGUID_SELECTIONSET)
|
|
{
|
|
pin->SetName(STR_SELECTIONSETPATH);
|
|
pin->SetGUID(CKPGUID_STRING);
|
|
change = TRUE;
|
|
}
|
|
else if (!bypath && pin->GetGUID()==CKPGUID_STRING)
|
|
{
|
|
pin->SetName(STR_SELECTIONSET);
|
|
pin->SetGUID(CKPGUID_SELECTIONSET);
|
|
change = TRUE;
|
|
}
|
|
if (change)
|
|
{
|
|
CKParameter* psource = pin->GetDirectSource();
|
|
if (psource)//if source, update source type & name if possible & value
|
|
{
|
|
//update direct source name if names are identical
|
|
char* psourceName = psource->GetName();
|
|
if (psourceName)
|
|
{
|
|
if (stricmp(psourceName,pin->GetName())!=0)
|
|
psource->SetName(pin->GetName());
|
|
}
|
|
//update source guid
|
|
psource->SetGUID(pin->GetGUID());
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
return CK_OK;
|
|
}
|