void DotSceneLoader::compileResource(const char* fileName, std::map<std::string, std::string>& options) { staticObjects.clear(); dynamicObjects.clear(); try { TiXmlDocument xmlDoc; TiXmlElement *xmlRoot; xmlDoc.LoadFile(fileName); if(xmlDoc.Error()) { return; } xmlRoot = xmlDoc.RootElement(); if(std::string(xmlRoot->Value()) != "scene") { return; } scene = new Scene(file::getFilename(fileName), manager); rootNode = scene->getRoot(); processScene(xmlRoot); scene->createSceneTree(); std::string outputName = file::getPath(fileName) + "/" + file::getFilename(fileName) + ".scene"; FileStream fileStream(outputName); ResourceBinStream resourceStream(fileStream); SceneUtils::write(resourceStream, *manager, scene); } catch(...) { } delete scene; }
US_USE_NAMESPACE void resourceExample() { //! [1] // Get this module's Module object Module* module = GetModuleContext()->GetModule(); ModuleResource resource = module->GetResource("config.properties"); if (resource.IsValid()) { // Create a ModuleResourceStream object ModuleResourceStream resourceStream(resource); // Read the contents line by line std::string line; while (std::getline(resourceStream, line)) { // Process the content std::cout << line << std::endl; } } else { // Error handling } //! [1] }
void StateProvider::writeResourceTree(Resources::Object *resource, Common::WriteStream *stream, bool current) { // Explicit scope to control the lifespan of the memory stream { Common::MemoryWriteStreamDynamic resourceStream(DisposeAfterUse::YES); ResourceSerializer serializer(nullptr, &resourceStream, kSaveVersion); // Serialize the resource to a memory stream if (current) { resource->saveLoadCurrent(&serializer); } else { resource->saveLoad(&serializer); } // Write the resource to the target stream stream->writeByte(resource->getType().get()); stream->writeByte(resource->getSubType()); stream->writeUint32LE(resourceStream.size()); stream->write(resourceStream.getData(), resourceStream.size()); } // Serialize the resource children Common::Array<Resources::Object *> children = resource->listChildren<Resources::Object>(); for (uint i = 0; i < children.size(); i++) { writeResourceTree(children[i], stream, current); } }
mitk::pa::PropertyCalculator::PropertyCalculator() { us::ModuleResource resource = us::GetModuleContext()->GetModule()->GetResource("spectralLIB.dat"); if (resource.IsValid()) { us::ModuleResourceStream resourceStream(resource); std::string line; int wavelength = 300; int counter = 0; while (std::getline(resourceStream, line, '\t')) { int currentLineIdx = counter % 6; if (currentLineIdx == 0) wavelength = std::stoi(line); else { std::istringstream lineStream(line); double tempDouble; lineStream >> tempDouble; m_SpectralLibMap[currentLineIdx][wavelength] = tempDouble; } ++counter; } }
Resource* ImageKey::loadResource(ResourceManager& manager) const { std::string textureName = getName(); FileStream fileStream("resources/images/" + textureName + ".texture"); ResourceBinStream resourceStream(fileStream); return ImageUtils::read(resourceStream, manager); }
///---------------------------------------------------------- /// ///---------------------------------------------------------- XMLNode CreateXMLDocumentFromXMLFile( const JazzPath& xmlFile, const std::string& optionalExpectedRootNodeName ) { // const double startSeconds = Clock::GetAbsoluteTimeSeconds(); ResourceStream resourceStream( xmlFile ); // const double secondsAfterResourceStream = Clock::GetAbsoluteTimeSeconds(); XMLNode xmlDocumentRootNode = CreateXMLDocumentFromResourceStream( resourceStream, optionalExpectedRootNodeName ); // const double secondsAfterXMLDocumentCreated = Clock::GetAbsoluteTimeSeconds(); // const double secondsToCreateResourceStream = (secondsAfterResourceStream - startSeconds); // const double secondsToCreateXMLDocument = (secondsAfterXMLDocumentCreated - secondsAfterResourceStream); // const double secondsTotal = (secondsAfterXMLDocumentCreated - startSeconds); // const float fractionSpentCreatingXMLDocument = secondsTotal > 0.0 ? (float)( secondsToCreateXMLDocument / secondsTotal ) : 0.f; // const std::string xmlDocumentType = optionalExpectedRootNodeName.empty() ? "generic" : optionalExpectedRootNodeName; // ConsolePrintf( Rgba::GREY, "Created %s XML document from file \"%s\" in %.0fms (%.0f%% for XML construction)\n", xmlDocumentType.c_str(), xmlFile..c_str(), 1000.0 * secondsTotal, 100.f * fractionSpentCreatingXMLDocument ); return xmlDocumentRootNode; }
void QmitkToolSelectionBox::RecreateButtons() { if (m_ToolManager.IsNull()) return; /* // remove all buttons that are there QObjectList *l = Q3ButtonGroup::queryList( "QButton" ); QObjectListIt it( *l ); // iterate over all buttons QObject *obj; while ( (obj = it.current()) != 0 ) { ++it; QButton* button = dynamic_cast<QButton*>(obj); if (button) { Q3ButtonGroup::remove(button); delete button; } } delete l; // delete the list, not the objects */ // mmueller Qt impl QList<QAbstractButton *> l = m_ToolButtonGroup->buttons(); // remove all buttons that are there QList<QAbstractButton *>::iterator it; QAbstractButton * btn; for(it=l.begin(); it!=l.end();++it) { btn = *it; m_ToolButtonGroup->removeButton(btn); //this->removeChild(btn); delete btn; } // end mmueller Qt impl mitk::ToolManager::ToolVectorTypeConst allPossibleTools = m_ToolManager->GetTools(); mitk::ToolManager::ToolVectorTypeConst allTools; typedef std::pair< std::string::size_type, const mitk::Tool* > SortPairType; typedef std::priority_queue< SortPairType > SortedToolQueueType; SortedToolQueueType toolPositions; // clear and sort all tools // step one: find name/group of all tools in m_DisplayedGroups string. remember these positions for all tools. for ( mitk::ToolManager::ToolVectorTypeConst::const_iterator iter = allPossibleTools.begin(); iter != allPossibleTools.end(); ++iter) { const mitk::Tool* tool = *iter; std::string::size_type namePos = m_DisplayedGroups.find( std::string("'") + tool->GetName() + "'" ); std::string::size_type groupPos = m_DisplayedGroups.find( std::string("'") + tool->GetGroup() + "'" ); if ( !m_DisplayedGroups.empty() && namePos == std::string::npos && groupPos == std::string::npos ) continue; // skip if ( m_DisplayedGroups.empty() && std::string(tool->GetName()).length() > 0 ) { namePos = static_cast<std::string::size_type> (tool->GetName()[0]); } SortPairType thisPair = std::make_pair( namePos < groupPos ? namePos : groupPos, *iter ); toolPositions.push( thisPair ); } // step two: sort tools according to previously found positions in m_DisplayedGroups MITK_DEBUG << "Sorting order of tools (lower number --> earlier in button group)"; while ( !toolPositions.empty() ) { SortPairType thisPair = toolPositions.top(); MITK_DEBUG << "Position " << thisPair.first << " : " << thisPair.second->GetName(); allTools.push_back( thisPair.second ); toolPositions.pop(); } std::reverse( allTools.begin(), allTools.end() ); MITK_DEBUG << "Sorted tools:"; for ( mitk::ToolManager::ToolVectorTypeConst::const_iterator iter = allTools.begin(); iter != allTools.end(); ++iter) { MITK_DEBUG << (*iter)->GetName(); } // try to change layout... bad? //Q3GroupBox::setColumnLayout ( m_LayoutColumns, Qt::Horizontal ); // mmueller using gridlayout instead of Q3GroupBox //this->setLayout(0); if(m_ButtonLayout == NULL) m_ButtonLayout = new QGridLayout; /*else delete m_ButtonLayout;*/ int row(0); int column(-1); int currentButtonID(0); m_ButtonIDForToolID.clear(); m_ToolIDForButtonID.clear(); QToolButton* button = 0; MITK_DEBUG << "Creating buttons for tools"; // fill group box with buttons for ( mitk::ToolManager::ToolVectorTypeConst::const_iterator iter = allTools.begin(); iter != allTools.end(); ++iter) { const mitk::Tool* tool = *iter; int currentToolID( m_ToolManager->GetToolID( tool ) ); ++column; // new line if we are at the maximum columns if(column == m_LayoutColumns) { ++row; column = 0; } button = new QToolButton; button->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); // add new button to the group MITK_DEBUG << "Adding button with ID " << currentToolID; m_ToolButtonGroup->addButton(button, currentButtonID); // ... and to the layout MITK_DEBUG << "Adding button in row/column " << row << "/" << column; m_ButtonLayout->addWidget(button, row, column); if (m_LayoutColumns == 1) { //button->setTextPosition( QToolButton::BesideIcon ); // mmueller button->setToolButtonStyle( Qt::ToolButtonTextBesideIcon ); } else { //button->setTextPosition( QToolButton::BelowIcon ); // mmueller button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); } //button->setToggleButton( true ); // mmueller button->setCheckable ( true ); if(currentToolID == m_ToolManager->GetActiveToolID()) button->setChecked(true); QString label; if (m_GenerateAccelerators) { label += "&"; } label += tool->GetName(); QString tooltip = tool->GetName(); MITK_DEBUG << tool->GetName() << ", " << label.toLocal8Bit().constData() << ", '" << tooltip.toLocal8Bit().constData(); if ( m_ShowNames ) { /* button->setUsesTextLabel(true); button->setTextLabel( label ); // a label QToolTip::add( button, tooltip ); */ // mmueller Qt button->setText( label ); // a label button->setToolTip( tooltip ); // mmueller QFont currentFont = button->font(); currentFont.setBold(false); button->setFont( currentFont ); } us::ModuleResource iconResource = tool->GetIconResource(); if (!iconResource.IsValid()) { button->setIcon(QIcon(QPixmap(tool->GetXPM()))); } else { us::ModuleResourceStream resourceStream(iconResource, std::ios::binary); resourceStream.seekg(0, std::ios::end); std::ios::pos_type length = resourceStream.tellg(); resourceStream.seekg(0, std::ios::beg); char* data = new char[length]; resourceStream.read(data, length); QPixmap pixmap; pixmap.loadFromData(QByteArray::fromRawData(data, length)); QIcon* icon = new QIcon(pixmap); delete[] data; button->setIcon(*icon); if (m_ShowNames) { if (m_LayoutColumns == 1) button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); else button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); button->setIconSize(QSize(24, 24)); } else { button->setToolButtonStyle(Qt::ToolButtonIconOnly); button->setIconSize(QSize(32,32)); button->setToolTip(tooltip); } } if (m_GenerateAccelerators) { QString firstLetter = QString( tool->GetName() ); firstLetter.truncate( 1 ); button->setShortcut( firstLetter ); // a keyboard shortcut (just the first letter of the given name w/o any CTRL or something) } mitk::DataNode* dataNode = m_ToolManager->GetReferenceData(0); if (dataNode != NULL && !tool->CanHandle(dataNode->GetData())) button->setEnabled(false); m_ButtonIDForToolID[currentToolID] = currentButtonID; m_ToolIDForButtonID[currentButtonID] = currentToolID; MITK_DEBUG << "m_ButtonIDForToolID[" << currentToolID << "] == " << currentButtonID; MITK_DEBUG << "m_ToolIDForButtonID[" << currentButtonID << "] == " << currentToolID; tool->GUIProcessEventsMessage += mitk::MessageDelegate<QmitkToolSelectionBox>( this, &QmitkToolSelectionBox::OnToolGUIProcessEventsMessage ); // will never add a listener twice, so we don't have to check here tool->ErrorMessage += mitk::MessageDelegate1<QmitkToolSelectionBox, std::string>( this, &QmitkToolSelectionBox::OnToolErrorMessage ); // will never add a listener twice, so we don't have to check here tool->GeneralMessage += mitk::MessageDelegate1<QmitkToolSelectionBox, std::string>( this, &QmitkToolSelectionBox::OnGeneralToolMessage ); ++currentButtonID; } // setting grid layout for this groupbox this->setLayout(m_ButtonLayout); //this->update(); }