OSG_BEGIN_NAMESPACE /***************************************************************************\ * Class variables * \***************************************************************************/ /***************************************************************************\ * Class methods * \***************************************************************************/ /***************************************************************************\ * Instance methods * \***************************************************************************/ bool ApplicationSettings::writeXML(const BoostPath& FilePath) { try { boost::property_tree::xml_parser::write_xml(FilePath.string(), _PropertyTree, std::locale(), boost::property_tree::xml_parser::xml_writer_make_settings<typename boost::property_tree::ptree::key_type::value_type>(' ', 4)); } catch(std::exception& ex) { SWARNING << "Failed to write settings to file: " << FilePath.string() << ", error: " << ex.what() << std::endl; return false; } return true; }
FieldContainerTransitPtr LuaActivity::createLuaActivity( const BoostPath& FilePath ) { LuaActivity* Result = LuaActivity::createEmpty(); FilePathAttachment::setFilePath(Result, FilePath); std::ifstream TheFile; TheFile.exceptions(std::fstream::failbit | std::fstream::badbit); try { TheFile.open(FilePath.string().c_str()); if(TheFile) { std::ostringstream Code; Code << TheFile.rdbuf(); TheFile.close(); Result->setCode(Code.str()); } return FieldContainerTransitPtr(Result); } catch(std::fstream::failure &f) { SWARNING << "LuaActivity::createLuaActivity(): Error reading file" << FilePath.string() << ": " << f.what() << std::endl; return FieldContainerTransitPtr(NULL); } }
boost::any LuaGraphTreeModel::getChild(const boost::any& parent, const UInt32& index) const { try { BoostPath ThePath = boost::any_cast<BoostPath>(parent); if(!ThePath.empty() && boost::filesystem::exists(ThePath)) { boost::filesystem::directory_iterator end_iter; UInt32 Count(0); for ( boost::filesystem::directory_iterator dir_itr(ThePath); dir_itr != end_iter; ++dir_itr ) { if( isValidFile(dir_itr->path()) ) { if(Count == index) { return boost::any(dir_itr->path()); } ++Count; } } } return boost::any(); } catch(boost::bad_any_cast &) { return boost::any(); } }
void LuaDebuggerInterface::handleSplitMenuAction(ActionEventDetails* const details) { try { std::string ValueString = boost::any_cast<std::string>(_SplitButton->getSelectionValue()); BoostPath IconPath; if(ValueString.compare("Horizontal") == 0) { IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-left-right.png")); _CodeTextArea->setIsSplit(true); _CodeTextArea->setSplitOrientation(SplitPanel::HORIZONTAL_ORIENTATION); } else if(ValueString.compare("Vertical") == 0) { IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-top-bottom.png")); _CodeTextArea->setIsSplit(true); _CodeTextArea->setSplitOrientation(SplitPanel::VERTICAL_ORIENTATION); } else { IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-none.png")); _CodeTextArea->setIsSplit(false); } _SplitButton->setImages(IconPath.string()); } catch (boost::bad_lexical_cast &) { //Could not convert to string } }
void MainApplication::loadSettings(const BoostPath& SettingsFile) { ApplicationSettings LoadedSettings; if(!boost::filesystem::exists(SettingsFile)) { SWARNING << "Could not load Settings from: \"" << SettingsFile.string() << "\" because that file does not exist." << std::endl; } else { BoostPath SettingsFullPath(SettingsFile); if(!SettingsFile.is_complete() && !SettingsFile.has_root_directory()) { SettingsFullPath = boost::filesystem::complete(SettingsFile); } SettingsFullPath.normalize(); SLOG << "Loading Settings from: " << SettingsFullPath.string() << std::endl; LoadedSettings.readXML(SettingsFile); } //Apply default settings to any settings that are not defined in loaded settings files applyDefaultSettings(LoadedSettings, false); setSettings(LoadedSettings); }
void MainApplication::initializeLogging(BoostPath KELogFilePath) { if(_EnableLogging) { //Configure the LogBuffer osgLogP->setLogType(LOG_BUFFER, true); //Configure the LogBuffer osgLogP->getLogBuf().setEnabled(true); osgLogP->getLogBuf().setCallback(KELogBufferCallback); if(_LogToFile) { //Make sure the directory is created try { boost::filesystem::create_directories(KELogFilePath.parent_path()); } catch(std::exception& ex) { SWARNING << "Failed to create directory: " << KELogFilePath.parent_path() << ", error: " << ex.what() << std::endl; return; } //If the Log is to a file then set the filev _LogFile.open(KELogFilePath.string().c_str()); } } else { //Disable all logging osgLogP->setLogType(LOG_NONE, true); } }
void SaveProjectAsCommand::execute(void) { std::vector<WindowEventProducer::FileDialogFilter> KEProjectFileFilters; KEProjectFileFilters.push_back(WindowEventProducer::FileDialogFilter("Project File","xml")); KEProjectFileFilters.push_back(WindowEventProducer::FileDialogFilter("All Files","*")); //Project File BoostPath InitialProjectFilePath(MainApplication::the()->getProject()->getFilePath()); if(!boost::filesystem::exists(InitialProjectFilePath)) { const Char8* ProjectName(getName(MainApplication::the()->getProject())); InitialProjectFilePath = BoostPath(std::string("./") + ( ProjectName ? ProjectName : "Project") + ".xml"); } BoostPath ProjectFilePath; ProjectFilePath = MainApplication::the()->getMainWindow()->saveFileDialog("Save Project As ...",KEProjectFileFilters,InitialProjectFilePath.filename(),InitialProjectFilePath.parent_path(), true); if(!ProjectFilePath.empty()) { if(ProjectFilePath.extension().empty()) { ProjectFilePath = ProjectFilePath.string() + ".xml"; } MainApplication::the()->saveProject(ProjectFilePath); } }
ComponentTransitPtr LuaDebuggerInterface::generateSplitOptionListComponent(List* const Parent, const boost::any& Value, UInt32 Index, bool IsSelected, bool HasFocus) { ButtonRecPtr TheComponent = Button::create(); TheComponent->setBackgrounds(NULL); TheComponent->setAlignment(Vec2f(0.0f,0.5f)); std::string ValueString; try { ValueString = boost::any_cast<std::string>(Value); BoostPath IconPath; if(ValueString.compare("Horizontal") == 0) { IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-left-right.png")); } else if(ValueString.compare("Vertical") == 0) { IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-top-bottom.png")); } else { IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-none.png")); } TheComponent->setImages(IconPath.string()); } catch (boost::bad_lexical_cast &) { //Could not convert to string } TheComponent->setText(ValueString); if(IsSelected) { LineBorderRecPtr LabelBorder = LineBorder::create(); LabelBorder->setWidth(1.0f); LabelBorder->setColor(Color4f(0.0f,0.0f,0.0f,1.0f)); TheComponent->setBorders(LabelBorder); } else { TheComponent->setBorders(NULL); } return ComponentTransitPtr(TheComponent); }
bool VideoWrapper::open(const BoostPath& ThePath, Window* const TheWindow) { //Check if the file exists if(boost::filesystem::exists(ThePath)) { return open(ThePath.file_string(), TheWindow); } else { SWARNING << "VideoWrapper::open(): File " << ThePath.file_string() << " could not be opened, because no file with that path exists" << std::endl; return false; } }
TableDOMTransitPtr TableFileHandlerBase::forceRead(const BoostPath& FilePath) { TableDOMRefPtr Result; //Determine if the file exists if(!boost::filesystem::exists(FilePath)) { SWARNING << "TableFileHandlerBase::read(): " << FilePath.string() << " does not exists." << std::endl; return TableDOMTransitPtr(NULL); } //Determine the file extension std::string Extension(boost::filesystem::extension(FilePath)); boost::algorithm::trim_if(Extension,boost::is_any_of(".")); //Get the Parent Directory Path of the file _RootFilePath = FilePath; _RootFilePath.remove_leaf(); //Get the FileType of a "txt" file (Forcing the document to be opened as a txt file) TableFileTypeP TheFileType(getFileType("csv", TableFileType::OSG_READ_SUPPORTED)); //Is that extension supported for reading if(TheFileType == NULL) { SWARNING << "TableFileHandlerBase::read(): Cannot read Field Container file: " << FilePath.string() << ", because no File types support " << Extension << " extension." << std::endl; return TableDOMTransitPtr(NULL); } else { //Open up the input stream of the file std::ifstream InputStream(FilePath.string().c_str(), std::ios::binary); if(!InputStream) { SWARNING << "TableFileHandlerBase::read(): Couldn't open input stream for file " << FilePath.string() << std::endl; return TableDOMTransitPtr(NULL); } else { //Read from the input stream startReadProgressThread(InputStream); Result = TheFileType->read(InputStream, FilePath.string()); stopReadProgressThread(); InputStream.close(); } } return TableDOMTransitPtr(Result); }
bool MainApplication::CompLogFileDates::operator()(const BoostPath& Left, const BoostPath Right) { //Get the filenames std::string LeftName(Left.stem()); std::string RightName(Right.stem()); //Convert the ISO formatted strings into time objects boost::posix_time::ptime LeftTime(boost::posix_time::from_iso_string(LeftName)); boost::posix_time::ptime RightTime(boost::posix_time::from_iso_string(RightName)); //Return time comparison //Oldest to Newest return LeftTime < RightTime; }
void handleTreeNodeExport(ActionEventDetails* const details, Tree* const editorTree) { boost::any SelectedComp(editorTree->getLastSelectedPathComponent()); //Get the tree selection try { FieldContainerTreeModel::ContainerFieldIdPair ThePair(boost::any_cast<FieldContainerTreeModel::ContainerFieldIdPair>(SelectedComp)); if(ThePair._FieldID == 0 && ThePair._Container != NULL) { std::vector<WindowEventProducer::FileDialogFilter> ExportFileFilters; ExportFileFilters.push_back(WindowEventProducer::FileDialogFilter("Field Container File","xml")); ExportFileFilters.push_back(WindowEventProducer::FileDialogFilter("All Files","*")); //Export File BoostPath InitialFilePath("./Export.xml"); WindowEventProducer* MainWindow(editorTree->getParentWindow()->getParentDrawingSurface()->getEventProducer()); BoostPath ExportFilePath; ExportFilePath =MainWindow->saveFileDialog("Save Field Container", ExportFileFilters, InitialFilePath.filename(), InitialFilePath.parent_path(), true); if(!ExportFilePath.empty()) { if(ExportFilePath.extension().empty()) { ExportFilePath = ExportFilePath.string() + ".xml"; } FCFileType::FCPtrStore Containers; Containers.insert(ThePair._Container); FCFileType::FCTypeVector IgnoreTypes; FCFileHandler::the()->write(Containers,ExportFilePath,IgnoreTypes); } } } catch(boost::bad_any_cast &ex) { SWARNING << ex.what() << std::endl; } }
bool ApplicationSettings::readXML(const BoostPath& FilePath) { try { boost::property_tree::xml_parser::read_xml(FilePath.string(), _PropertyTree); } catch(std::exception& ex) { SWARNING << "Failed to read settings from file: " << FilePath.string() << ", error: " << ex.what() << std::endl; return false; } return true; }
FCFileTypeP FCFileHandlerBase::getFileType(const BoostPath& FilePath, UInt32 Flags) { //Determine the file extension std::string Extension(boost::filesystem::extension(FilePath.string())); boost::algorithm::trim_if(Extension,boost::is_any_of(".")); return getFileType(Extension, Flags); }
OSG_BEGIN_NAMESPACE /***************************************************************************\ * Class variables * \***************************************************************************/ /***************************************************************************\ * Class methods * \***************************************************************************/ /***************************************************************************\ * Instance methods * \***************************************************************************/ bool ApplicationSettings::writeXML(const BoostPath& FilePath) { //Make sure the directory is created try { boost::filesystem::create_directories(FilePath.parent_path()); } catch(std::exception& ex) { SWARNING << "Failed to create directory: " << FilePath.parent_path() << ", error: " << ex.what() << std::endl; return false; } //Write the XML try { boost::property_tree::xml_parser::write_xml(FilePath.string(), _PropertyTree, std::locale(), boost::property_tree::xml_parser::xml_writer_make_settings<boost::property_tree::ptree::key_type::value_type>(' ', 4)); } catch(std::exception& ex) { SWARNING << "Failed to write settings to file: " << FilePath.string() << ", error: " << ex.what() << std::endl; return false; } return true; }
void handleSaveButtonAction(ActionEventDetails* const details, WindowEventProducer* const TutorialWindow, TextEditor* const theTextEditor) { std::vector<WindowEventProducer::FileDialogFilter> Filters; Filters.push_back(WindowEventProducer::FileDialogFilter("All","*")); Filters.push_back(WindowEventProducer::FileDialogFilter("Lua Files","lua")); BoostPath SavePath = TutorialWindow->saveFileDialog("Save File Window", Filters, std::string("newFile.lua"), BoostPath(".."), true); if(SavePath.string() != "") { theTextEditor->saveFile(SavePath); } }
void ContentPanel::saveTextFile(BoostPath file) { std::ofstream _OutputFile((file.string()).c_str()); ScrollPanelRefPtr _ToBeSavedScrollPanel = dynamic_cast<ScrollPanel*>(_LeftTabPanel->getTabContents(_LeftTabPanel->getSelectedIndex())); TextAreaRefPtr _ToBeSavedTextArea = dynamic_cast<TextArea*>(_ToBeSavedScrollPanel->getViewComponent()); std::string _TobeSavedText = _ToBeSavedTextArea->getText(); _OutputFile<<_TobeSavedText; _OutputFile.close(); }
boost::any LuaGraphTreeModel::getParent(const boost::any& node) const { try { BoostPath ThePath = boost::any_cast<BoostPath>(node); if((!ThePath.empty() || ThePath == getInternalRoot() || boost::filesystem::equivalent(ThePath, getInternalRoot())) && (boost::filesystem::exists(ThePath) && boost::filesystem::exists(getInternalRoot()))) { return boost::any(ThePath.parent_path()); } } catch(boost::bad_any_cast &) { } return boost::any(); }
UInt32 LuaGraphTreeModel::getIndexOfChild(const boost::any& parent, const boost::any& child) const { try { BoostPath ParentPath = boost::any_cast<BoostPath>(parent); BoostPath ChildPath = boost::any_cast<BoostPath>(child); if(!ParentPath.empty() && boost::filesystem::exists(ParentPath)) { boost::filesystem::directory_iterator end_iter; UInt32 Count(0); for ( boost::filesystem::directory_iterator dir_itr( ParentPath ); dir_itr != end_iter; ++dir_itr ) { try { if(ChildPath == dir_itr->path() || boost::filesystem::equivalent(dir_itr->path(), ChildPath)) { return Count; } } catch(boost::filesystem::filesystem_error &) { return Count; } if(isValidFile(dir_itr->path())) { ++Count; } } } return 0; } catch(boost::bad_any_cast &) { return 0; } }
bool FCFileHandlerBase::write(const FCPtrStore Containers, const BoostPath& FilePath, const FCFileType::FCTypeVector& IgnoreTypes, bool Compress) { //Determine the file extension std::string Extension(boost::filesystem::extension(FilePath)); boost::algorithm::trim_if(Extension,boost::is_any_of(".")); _RootFilePath = FilePath; _RootFilePath.remove_filename(); //Get the FileType for this extension FCFileTypeP TheFileType(getFileType(Extension, FCFileType::OSG_WRITE_SUPPORTED)); //Is that extension supported for reading if(TheFileType == NULL) { SWARNING << "FCFileHandlerBase::write(): Cannot write Field Container file: " << FilePath.string() << ", because no File types support " << Extension << " extension." << std::endl; return false; } else { //Open up the input stream of the file std::ofstream OutputStream(FilePath.string().c_str(), std::ios::binary); if(!OutputStream) { SWARNING << "FCFileHandlerBase::write(): Couldn't open output stream for file " << FilePath.string() << std::endl; return false; } else { bool Result; Result = write(Containers, OutputStream, Extension, IgnoreTypes, Compress); OutputStream.close(); return Result; } } }
void LuaDebuggerInterface::saveScriptButtonAction(void) { std::vector<WindowEventProducer::FileDialogFilter> Filters; Filters.push_back(WindowEventProducer::FileDialogFilter("Lua File Type","lua")); Filters.push_back(WindowEventProducer::FileDialogFilter("All","*")); BoostPath SavePath = _CodeTextArea-> getParentWindow()-> getParentDrawingSurface()-> getEventProducer()-> saveFileDialog("Save Lua Script to?", Filters, std::string("LuaScript.lua"), BoostPath("Data"), true); //Try to write the file std::ofstream OutFile(SavePath.string().c_str()); if(OutFile) { OutFile << _CodeTextArea->getText(); OutFile.close(); } }
DialogWindowTransitPtr loadCreditsWindow(const BoostPath& WindowDefinitionFile) { FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(WindowDefinitionFile); for(FCFileType::FCPtrStore::iterator Itor(NewContainers.begin()) ; Itor!= NewContainers.end() ; ++Itor) { if((*Itor)->getType() == DialogWindow::getClassType()) { return DialogWindowTransitPtr(dynamic_pointer_cast<DialogWindow>(*Itor)); } } SFATAL << "Failed to load Builder Credits Window definition from file: " << WindowDefinitionFile.string() << std::endl; return DialogWindowTransitPtr(NULL); }
FCFileHandlerBase::FCPtrStore FCFileHandlerBase::read(const BoostPath& FilePath) { FCPtrStore Result; //Determine if the file exists if(!boost::filesystem::exists(FilePath)) { SWARNING << "FCFileHandlerBase::read(): " << FilePath.string() << " does not exists." << std::endl; return Result; } std::string filename = initPathHandler(FilePath.string().c_str()); //Determine the file extension std::string Extension(boost::filesystem::extension(FilePath)); boost::algorithm::trim_if(Extension,boost::is_any_of(".")); //Get the Parent Directory Path of the file _RootFilePath = FilePath; _RootFilePath.remove_leaf(); //Get the FileType for this extension FCFileTypeP TheFileType(getFileType(Extension, FCFileType::OSG_READ_SUPPORTED)); //Is that extension supported for reading if(TheFileType == NULL) { SWARNING << "FCFileHandlerBase::read(): Cannot read Field Container file: " << FilePath.string() << ", because no File types support " << Extension << " extension." << std::endl; return Result; } else { //Open up the input stream of the file std::ifstream InputStream(FilePath.string().c_str(), std::ios::binary); if(!InputStream) { SWARNING << "FCFileHandlerBase::read(): Couldn't open input stream for file " << FilePath.string() << std::endl; return Result; } else { //Read from the input stream startReadProgressThread(InputStream); Result = TheFileType->read(InputStream, FilePath.string()); stopReadProgressThread(); InputStream.close(); } } return Result; }
bool VLCVideoWrapper::open(BoostPath ThePath, Window* const TheWindow) { return open(ThePath.string(), TheWindow); }
void ContentPanel::addTabWithText(BoostPath file) { PanelRefPtr _NewLeftTabLabelPanel = Panel::createEmpty(); ButtonRefPtr _NewLeftTabLabelCloseButtonRefPtr = dynamic_pointer_cast<Button>(dynamic_cast<InternalWindow*>(InternalWindow::getClassType().getPrototype())->getTitlebar()->getCloseButton()->shallowCopy()); //ButtonRefPtr _NewLeftTabLabelCloseButtonRefPtr = Button::create(); _NewLeftTabLabelCloseButtonRefPtr->setPreferredSize(Vec2f(100,20)); _NewLeftTabLabelCloseButtonRefPtr->setText("X"); _NewLeftTabLabelCloseButtonRefPtr->addActionListener(&_CloseButtonListener); LabelRefPtr _NewLeftTabLabelLabel=Label::create(); _NewLeftTabLabelLabel->setText(file.leaf()); _NewLeftTabLabelLabel->setBorders(NULL); _NewLeftTabLabelLabel->setBackgrounds(NULL); SpringLayoutRefPtr _NewLeftTabLabelPanelSpringLayout = OSG::SpringLayout::create(); _NewLeftTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _NewLeftTabLabelCloseButtonRefPtr, 2, SpringLayoutConstraints::NORTH_EDGE, _NewLeftTabLabelPanel); _NewLeftTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _NewLeftTabLabelCloseButtonRefPtr, -2, SpringLayoutConstraints::EAST_EDGE, _NewLeftTabLabelPanel); _NewLeftTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, _NewLeftTabLabelCloseButtonRefPtr, -20, SpringLayoutConstraints::EAST_EDGE, _NewLeftTabLabelPanel); _NewLeftTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _NewLeftTabLabelCloseButtonRefPtr, -2, SpringLayoutConstraints::SOUTH_EDGE, _NewLeftTabLabelPanel); _NewLeftTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _NewLeftTabLabelLabel, 2, SpringLayoutConstraints::NORTH_EDGE, _NewLeftTabLabelPanel); _NewLeftTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _NewLeftTabLabelLabel, -5, SpringLayoutConstraints::WEST_EDGE, _NewLeftTabLabelCloseButtonRefPtr); _NewLeftTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, _NewLeftTabLabelLabel, 2, SpringLayoutConstraints::WEST_EDGE, _NewLeftTabLabelPanel); _NewLeftTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _NewLeftTabLabelLabel, -2, SpringLayoutConstraints::SOUTH_EDGE, _NewLeftTabLabelPanel); _NewLeftTabLabelPanel->setPreferredSize(Vec2f(120,20)); _NewLeftTabLabelPanel->pushToChildren(_NewLeftTabLabelLabel); _NewLeftTabLabelPanel->pushToChildren(_NewLeftTabLabelCloseButtonRefPtr); _NewLeftTabLabelPanel->setLayout(_NewLeftTabLabelPanelSpringLayout); std::string sent; std::string para=""; std::ifstream inputFile((file.string()).c_str()); while(std::getline(inputFile,sent))para+=sent+"\n"; inputFile.close(); TextAreaRefPtr _NewLeftTabTextArea = OSG::TextArea::create(); _NewLeftTabTextArea->setText(para); _NewLeftTabTextArea->setEditable(true); ScrollPanelRefPtr _NewLeftTabContent = ScrollPanel::create(); _NewLeftTabContent->setPreferredSize(Vec2f(200,1200)); _NewLeftTabContent->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); _NewLeftTabContent->setViewComponent(_NewLeftTabTextArea); PanelRefPtr _NewRightTabLabelPanel = Panel::createEmpty(); ButtonRefPtr _RightTabLabelCloseButtonRefPtr = dynamic_pointer_cast<Button>(dynamic_cast<InternalWindow*>(InternalWindow::getClassType().getPrototype())->getTitlebar()->getCloseButton()->shallowCopy()); _RightTabLabelCloseButtonRefPtr->setPreferredSize(Vec2f(20,10)); _RightTabLabelCloseButtonRefPtr->setText("X"); _RightTabLabelCloseButtonRefPtr->addActionListener(&_CloseButtonListener); LabelRefPtr _NewRightTabLabel=Label::create(); _NewRightTabLabel->setText(file.leaf()); _NewRightTabLabel->setBorders(NULL); _NewRightTabLabel->setBackgrounds(NULL); SpringLayoutRefPtr _NewRightTabLabelPanelSpringLayout = OSG::SpringLayout::create(); _NewRightTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _RightTabLabelCloseButtonRefPtr, 2, SpringLayoutConstraints::NORTH_EDGE, _NewRightTabLabelPanel); _NewRightTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _RightTabLabelCloseButtonRefPtr, -2, SpringLayoutConstraints::EAST_EDGE, _NewRightTabLabelPanel); _NewRightTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, _RightTabLabelCloseButtonRefPtr, -20, SpringLayoutConstraints::EAST_EDGE, _NewRightTabLabelPanel); _NewRightTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _RightTabLabelCloseButtonRefPtr, -2, SpringLayoutConstraints::SOUTH_EDGE, _NewRightTabLabelPanel); _NewRightTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _NewRightTabLabel, 2, SpringLayoutConstraints::NORTH_EDGE, _NewRightTabLabelPanel); _NewRightTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _NewRightTabLabel, -5, SpringLayoutConstraints::WEST_EDGE, _RightTabLabelCloseButtonRefPtr); _NewRightTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, _NewRightTabLabel, 2, SpringLayoutConstraints::WEST_EDGE, _NewRightTabLabelPanel); _NewRightTabLabelPanelSpringLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _NewRightTabLabel, -2, SpringLayoutConstraints::SOUTH_EDGE, _NewRightTabLabelPanel); _NewRightTabLabelPanel->setPreferredSize(Vec2f(120,20)); _NewRightTabLabelPanel->pushToChildren(_RightTabLabelCloseButtonRefPtr); _NewRightTabLabelPanel->pushToChildren(_NewRightTabLabel); _NewRightTabLabelPanel->setLayout(_NewRightTabLabelPanelSpringLayout); TextAreaRefPtr _NewRightTabTextArea = OSG::TextArea::create(); _NewRightTabTextArea->setText(para); _NewRightTabTextArea->setEditable(true); ScrollPanelRefPtr _NewRightTabContent = ScrollPanel::create(); _NewRightTabContent->setPreferredSize(Vec2f(200,1200)); _NewRightTabContent->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW); _NewRightTabContent->setViewComponent(_NewRightTabTextArea); _RightTabPanel->addTab(_NewLeftTabLabelPanel, _NewLeftTabContent); _RightTabPanel->setSelectedIndex((_RightTabPanel->getMFTabs()->size())-1); _LeftTabPanel->addTab(_NewRightTabLabelPanel, _NewRightTabContent); _LeftTabPanel->setSelectedIndex((_LeftTabPanel->getMFTabs()->size())-1); }
// Initialize GLUT & OpenSG and set up the scene int main(int argc, char **argv) { // OSG init osgInit(argc,argv); // Set up Window TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); TutorialWindow->setDisplayCallback(display); TutorialWindow->setReshapeCallback(reshape); //Add Key Listener TutorialKeyListener TheKeyListener; TutorialWindow->addKeyListener(&TheKeyListener); //Add Mouse Listeners TutorialMouseListener TheTutorialMouseListener; TutorialMouseMotionListener TheTutorialMouseMotionListener; TutorialWindow->addMouseListener(&TheTutorialMouseListener); TutorialWindow->addMouseMotionListener(&TheTutorialMouseMotionListener); // Create the SimpleSceneManager helper mgr = new SimpleSceneManager; // Tell the Manager what to manage mgr->setWindow(TutorialWindow); // open window /* Set up complete, now performing XML import */ BoostPath ExecutableDirectory(argv[0]); ExecutableDirectory.remove_leaf(); BoostPath FilePath; if(argc > 1) { FilePath = BoostPath(argv[1]); } else { FilePath = BoostPath("./Data/mayaExport1.xml"); } if(!boost::filesystem::exists(FilePath)) { std::cerr << "Could not find file by path: " << FilePath.string() << std::endl; osgExit(); return -1; } // parse XML file to get field container data FCFileType::FCPtrStore NewContainers; NewContainers = FCFileHandler::the()->read(FilePath); // find root node from container, attach update listeners to particle systems std::vector<NodeRefPtr> RootNodes; for(FCFileType::FCPtrStore::iterator Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor) { // get root node if( (*Itor)->getType() == Node::getClassType() && dynamic_pointer_cast<Node>(*Itor)->getParent() == NULL) { RootNodes.push_back(dynamic_pointer_cast<Node>(*Itor)); } else if( (*Itor)->getType() == ParticleSystem::getClassType()) //attach update listeners to particle systems present { ParticleSystemRefPtr ExampleParticleSystems = dynamic_pointer_cast<ParticleSystem>(*Itor); ExampleParticleSystems->attachUpdateListener(TutorialWindow); } } // get root node that was extracted from XML file if(RootNodes.size() > 0) { NodeRefPtr scene = RootNodes[0]; // set root node mgr->setRoot(scene); } // Show the whole Scene mgr->showAll(); mgr->setHeadlight(true); mgr->getCamera()->setFar(10000); // main loop //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "15FCFileTypeIO"); //Enter main Loop TutorialWindow->mainLoop(); osgExit(); return 0; }