#include "StdAfx.h"
#include "shelveTool.h"
bool ShelveTool::FBCreate () {
OnShow.Add (
this, (
FBCallback)&ShelveTool::EventToolShow) ;
OnInput.Add (
this, (
FBCallback)&ShelveTool::EventToolInput) ;
OnResize.Add (
this, (
FBCallback)&ShelveTool::EventToolResize) ;
)) ;
FBConfigFile config ("@Application.txt") ;
const char* defaultPosValue = "20,100";
bool bSuccess = config.GetOrSet( ORTOOL__NAME, "Position", defaultPosValue );
if( bSuccess )
{
if ((
pos.length() == 1) && (
pos[0] ==
'k' )) {
} else {
std::vector<std::string> sts =tokenize (
pos,
',') ;
StartPos [0] =atoi (sts [0].c_str ()) ;
StartPos [1] =atoi (sts [1].c_str ()) ;
}
}
std::vector<std::string> sts =tokenize (
size,
',') ;
StartSize [0] =628 ;
StartSize [1] =83 ;
if ( atoi (sts [0].c_str ()) < 1600 )
StartSize [0] =atoi (sts [0].c_str ()) + TAB_HEIGHT - 9 ;
if ( atoi (sts [1].c_str ()) < 1200 )
StartSize [1] =atoi (sts [1].c_str ()) + TAB_HEIGHT - 2 ;
AddRegion (
"TabPanel", "TabPanel",
) ;
SetControl ("TabPanel", _Tab) ;
_Tab.OnChange.Add (
this, (
FBCallback)&ShelveTool::onTabChanged) ;
std::string path (FBSystem ().TheOne ().UserConfigPath.AsString ()) ;
#if defined(KARCH_ENV_WIN32)
path += _T("\\Shelves.xml") ;
#else
path += _T("/Shelves.xml") ;
#endif
std::ifstream infile(path.c_str());
if (!infile)
{
std::string xml_template (FBSystem ().TheOne ().ApplicationPath.AsString());
#if defined(KARCH_ENV_WIN32)
xml_template += _T("\\..\\..\\OpenRealitySDK\\Samples\\miscellaneous\\motionbuilder_shelf\\Shelves.xml");
#else
xml_template += _T("/../../OpenRealitySDK/Samples/miscellaneous/motionbuilder_shelf/Shelves.xml");
#endif
std::ifstream stream1(xml_template.c_str());
if (!stream1)
{
FBTrace(
"\nCan't find original xml template %s for Motionbuilder shelf.\n", xml_template.c_str());
return (false) ;
}
std::ofstream stream2(path.c_str());
stream2 << stream1.rdbuf();
stream1.close();
stream2.close();
}
infile.close();
if ( !result )
{
FBTrace(
"\nCan't load xml file %s for Motionbuilder shelf.\n", path.c_str());
return (false) ;
}
_Buttons =
new FBButton [shelves.
size ()] ;
_Layouts =
new FBLayout [shelves.
size ()] ;
int iTab =_Tab.Items.GetCount () ;
_LayoutIds.push_back (szLayout) ;
AddRegion (
szLayout.c_str (), szLayout.c_str (),
) ;
SetControl (szLayout.c_str (), _Layouts [iTab]) ;
int iButton =(
int)_ButtonIds.size () ;
_ButtonIds.push_back (szButton) ;
int width =BUTTON_SIZE ;
_Layouts [iTab].AddRegion (
szButton.c_str (), szButton.c_str (),
) ;
if ( width != BUTTON_SIZE )
n +=width - BUTTON_SIZE ;
_Layouts [iTab].SetControl (szButton.c_str (), _Buttons [iButton]) ;
_Buttons [iButton].Caption.SetPropertyValue (inode.
node ().
attribute (
"title").
value ()) ;
}
}
_Buttons [iButton].PropertyList.Find (
"Hint")->SetString (inode.
node ().
attribute (
"hint").
value ()) ;
}
_Buttons [iButton].OnClick.Add (
this, (
FBCallback)&ShelveTool::onButtonClicked) ;
if ( script.size () == 1 ) {
_scripts [szButton] =(*(script.begin ())).node ().text ().as_string () ;
} else {
}
} else {
}
}
}
const char *tab =config.Get (ORTOOL__NAME, "Tab", "-1") ;
int index =_Tab.Items.Find (tab) ;
if ( index == -1 )
index =0 ;
SetControl (_LayoutIds [index].c_str (), _Layouts [index]) ;
return (true) ;
}
void ShelveTool::FBDestroy () {
delete [] _Layouts ;
delete [] _Buttons ;
}
FBEventInput evt (pEvent) ;
}
FBEventShow evt (pEvent) ;
if ( evt.Shown ) {
} else {
}
}
FBEventResize evt (pEvent) ;
FBConfigFile config ("@Application.txt") ;
config.Set (ORTOOL__NAME, "Size", st.c_str ()) ;
}
SetControl (_LayoutIds [_Tab.ItemIndex].c_str (), _Layouts [_Tab.ItemIndex]) ;
FBConfigFile config ("@Application.txt") ;
config.Set (ORTOOL__NAME, "Tab", _Tab.Items[_Tab.ItemIndex]) ;
}
if (lComp == NULL)
return;
int index =0 ;
for ( ; index < _ButtonIds.size () ; index++ ) {
if (_Buttons[index].GetHIObject() == ((FBButton*)lComp)->GetHIObject())
break;
}
if ( index >= _ButtonIds.size () )
return ;
if ( python.empty () ) {
python =_scriptFiles [szButton] ;
bool bRet =FBPython::EvalFile (python.c_str ()) ;
} else {
bool bRet =FBPython::ParseLine ("from pyfbsdk import *") ;
bRet =FBPython::EvalLine () ;
std::vector<std::string> cmds =tokenize (python, '\n') ;
for ( std::vector<std::string>::iterator it =cmds.begin () ; it != cmds.end () ; it++ ) {
bRet =FBPython::ParseLine ((*it).c_str ()) ;
bRet =FBPython::EvalLine () ;
}
}
}