Пример #1
0
/**Set the xml string from which the dimension will be generated.
 @param dimensionXMLString : xml string to generate the dimension from.
*/
void IMDDimensionFactory::setXMLString(const std::string& dimensionXMLString)
{
  Poco::XML::DOMParser pParser;
  Poco::XML::Document* pDoc = pParser.parseString(dimensionXMLString);
  Poco::XML::Element* pDimensionElement = pDoc->documentElement();
  m_dimensionXML = pDimensionElement;
}
Пример #2
0
    /**
    Execution method to run the extraction.
    @return location string
    */
    std::string vtkDataSetToWsLocation::execute()
    {
      using Mantid::Geometry::MDGeometryXMLDefinitions;
      FieldDataToMetadata convert;
      std::string xmlString = convert(m_dataset->GetFieldData(), XMLDefinitions::metaDataId());

      Poco::XML::DOMParser pParser;
      Poco::XML::Document* pDoc = pParser.parseString(xmlString);
      Poco::XML::Element* pRootElem = pDoc->documentElement();
      Poco::XML::Element* wsLocationElem = pRootElem->getChildElement(MDGeometryXMLDefinitions::workspaceLocationElementName());
      if(wsLocationElem == NULL)
      {
        throw std::runtime_error("The element containing the workspace location must be present.");
      }
      return wsLocationElem->innerText();
    }
Пример #3
0
    /**
    Execution method to run the extraction.
    @return implicit function if one could be found, or a NullImplicitFunction.
    */
    Mantid::Geometry::MDImplicitFunction* vtkDataSetToImplicitFunction::execute()
    {
      using Mantid::MDAlgorithms::NullImplicitFunction;
      using Mantid::Geometry::MDGeometryXMLDefinitions;
      Mantid::Geometry::MDImplicitFunction* function = new NullImplicitFunction;

      FieldDataToMetadata convert;
      std::string xmlString = convert(m_dataset->GetFieldData(), XMLDefinitions::metaDataId()); 
      if (false == xmlString.empty())
      {
        Poco::XML::DOMParser pParser;
        Poco::XML::Document* pDoc = pParser.parseString(xmlString);
        Poco::XML::Element* pRootElem = pDoc->documentElement();
        Poco::XML::Element* functionElem = pRootElem->getChildElement(MDGeometryXMLDefinitions::functionElementName());
        if(NULL != functionElem)
        {
          delete function;
          function = Mantid::API::ImplicitFunctionFactory::Instance().createUnwrapped(functionElem);
        }
      }
      return function;
    }
void DebugBreakpointManager::SaveState(const Poco::Path& path) const
{
  Poco::XML::Document* doc = new Poco::XML::Document();
  Poco::XML::Element* breakpoints = doc->createElement(BREAKPOINTS_TAG);
  doc->appendChild(breakpoints)->release();

  for (std::set<unsigned long>::const_iterator i = m_ObjectBreakpoints.begin(); i
      != m_ObjectBreakpoints.end(); ++i)
  {
    Poco::XML::Element* objectBreakpoint = doc->createElement(OBJECT_TAG);
    breakpoints->appendChild(objectBreakpoint)->release();
    std::stringstream ss;
    ss << *i;
    objectBreakpoint->setAttribute(ID_ATTR, ss.str());

    const Object* obj = DebugUtil::GetObject(*i);
    if (obj)
    {
      objectBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName());

    }
  }

  for (Poco::HashMap<int, const Object*>::ConstIterator i =
      m_SmartPointerBreakpoints.begin(); i != m_SmartPointerBreakpoints.end(); ++i)
  {
    Poco::XML::Element* spBreakpoint = doc->createElement(SMARTPOINTER_TAG);
    breakpoints->appendChild(spBreakpoint)->release();
    std::stringstream ss;
    ss << i->first;
    spBreakpoint->setAttribute(ID_ATTR, ss.str());

    const Object* obj = i->second;
    if (i->second)
    {
      spBreakpoint->setAttribute(CLASSNAME_ATTR, obj->GetClassName());
      ss.clear();
      ss << obj->GetTraceId();
      spBreakpoint->setAttribute(OBJECTID_ATTR, ss.str());
    }
  }

  Poco::FileOutputStream writer(path.toString());
  Poco::XML::DOMWriter out;
  out.setOptions(3); //write declaration and pretty print
  out.writeNode(writer, doc);

  doc->release();
}
Пример #5
0
void DebugUtil::SaveState()
{
    Poco::Path path;
    if (!GetPersistencePath(path)) return;

    path.setFileName(DEBUG_UTIL_XML);

    Poco::XML::Document* doc = new Poco::XML::Document();
    Poco::XML::Element* debugutil = doc->createElement(DEBUGUTIL_TAG);
    doc->appendChild(debugutil)->release();

    for (std::set<unsigned int>::const_iterator i = m_TracedObjects.begin();
            i != m_TracedObjects.end(); ++i)
    {
        Poco::XML::Element* traceObject = doc->createElement(TRACEOBJECT_TAG);
        debugutil->appendChild(traceObject)->release();
        std::stringstream ss;
        ss << *i;
        traceObject->setAttribute(ID_ATTR, ss.str());
    }

    for (std::set<std::string>::const_iterator i = m_TracedClasses.begin();
            i != m_TracedClasses.end(); ++i)
    {
        Poco::XML::Element* traceClass = doc->createElement(TRACECLASS_TAG);
        debugutil->appendChild(traceClass)->release();
        traceClass->setAttribute(NAME_ATTR, *i);
    }

    try
    {
        Poco::FileOutputStream writer(path.toString());
        Poco::XML::DOMWriter out;
        out.setOptions(3); //write declaration and pretty print
        out.writeNode(writer, doc);

        doc->release();

        // save BreakpointManager
        path.setFileName(DebugBreakpointManager::BREAKPOINTS_XML);
        GetBreakpointManager()->SaveState(path);
    }
    catch (Poco::FileException& e)
    {
        BERRY_WARN << e.displayText();
    }

}
Пример #6
0
svgtiny_code svgtiny_parse(struct svgtiny_diagram *diagram,
		const char *buffer, size_t size, const char *url,
		int viewport_width, int viewport_height)
{
	
    Poco::XML::Document *document;
	//Poco::XML::Element *svg;
    Poco::XML::Element *svg;
	struct svgtiny_parse_state state;
	float x, y, width, height;
	svgtiny_code code;

	assert(diagram);
	assert(buffer);
	assert(url);
    
    std::string str(buffer);
    
    Poco::XML::DOMParser parser;
    document = parser.parseString(str);

    svg = document->documentElement();
    
    //std::cout << svg->localName() << std::endl;
    
	if (!svg)
		return svgtiny_NOT_SVG;
    if (svg->localName().compare("svg") != 0)
		return svgtiny_NOT_SVG;

	/* get graphic dimensions */
	state.diagram = diagram;
	state.document = document;
	state.viewport_width = viewport_width;
	state.viewport_height = viewport_height;
	svgtiny_parse_position_attributes(svg, state, &x, &y, &width, &height);
	diagram->width = width;
	diagram->height = height;

	/* set up parsing state */
	state.viewport_width = width;
	state.viewport_height = height;
	state.ctm.a = 1; /*(float) viewport_width / (float) width;*/
	state.ctm.b = 0;
	state.ctm.c = 0;
	state.ctm.d = 1; /*(float) viewport_height / (float) height;*/
	state.ctm.e = 0; /*x;*/
	state.ctm.f = 0; /*y;*/
	/*state.style = css_base_style;
	state.style.font_size.value.length.value = option_font_size * 0.1;*/
	state.fill = 0x000000;
	state.stroke = svgtiny_TRANSPARENT;
	state.stroke_width = 1;
	state.linear_gradient_stop_count = 0;

	/* parse tree */
	code = svgtiny_parse_svg(svg, state, diagram);

	/* free XML tree */
	//xmlFreeDoc(document);

	return code;
}
Пример #7
0
  /**
   * Reads detctor ids for groups from an XML grouping file, such as one created by the SpatialGrouping algorithm.
   * @param filename :: path and name of input file
   * @throw FileError is there is a problem with the XML file
   */
  void ReadGroupsFromFile::readXMLGroupingFile(const std::string& filename)
  {
    Poco::XML::DOMParser xmlParser;
    Poco::XML::Document* file;
    try
    {
      file = xmlParser.parse(filename);
    }
    catch ( ... )
    {
      throw Kernel::Exception::FileError("Unable to parse file: ", filename);
    }

    Poco::XML::Element* root = file->documentElement();
  
    if ( ! root->hasChildNodes() )
    {
      throw Kernel::Exception::FileError("No root element in XML grouping file: ", filename);
    }

    Poco::XML::NodeList* groups = root->getElementsByTagName("group");

    if ( groups->length() == 0 )
    {
      throw Kernel::Exception::FileError("XML group file contains no group elements:", filename);
    }

    unsigned int nGroups = static_cast<unsigned int>(groups->length());
    for ( unsigned int i = 0; i < nGroups; i++ )
    {
      // Get the "detids" element from the grouping file
      Poco::XML::Element* elem = static_cast<Poco::XML::Element*>(groups->item(i));
      Poco::XML::Element* group = elem->getChildElement("detids");

      if ( ! group )
      {
        throw Mantid::Kernel::Exception::FileError("XML Group File, group contains no <detids> element:", filename);
      }
  
      std::string ids = group->getAttribute("val");

      Poco::StringTokenizer data(ids, ",", Poco::StringTokenizer::TOK_TRIM);

      if ( data.begin() != data.end() )
      {
        for ( Poco::StringTokenizer::Iterator it = data.begin(); it != data.end(); ++it )
        {
          // cast the string to an int
          int detID;
          try
          {
            detID = boost::lexical_cast<int>(*it);
          } catch ( boost::bad_lexical_cast & )
          {
            throw Mantid::Kernel::Exception::FileError("Could cast string to integer in input XML file", filename);
          }
  
          if ( calibration.find(detID) == calibration.end() )
          {
            // add detector to a group
            calibration[detID] = std::pair<int,int>(i+1, 1);
          }
        }
      }
    }

    progress(0.7);
  }
Пример #8
0
svgtiny_code svgtiny_parse(svgInfo &info,struct svgtiny_diagram *diagram, const char *buffer,int viewport_width, int viewport_height){
	
    Poco::XML::Document *document;
    Poco::XML::Element *svg;
	struct svgtiny_parse_state state;
	float x, y, width, height;
	svgtiny_code code;

    
    
    
	assert(diagram);
	assert(buffer);

    
    string rawXMLstring(buffer);
    
    //info.rawXML = rawXMLstring;
    
    //parser is statically allocated
    Poco::XML::DOMParser parser;
    
    /*
     Why does this upset the internal SVG parser?
     */
    //parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false);
    
    document = parser.parseString(rawXMLstring);
    

    svg = document->documentElement();
    
    
    
    //std::cout << svg->localName() << std::endl;
    
	if (!svg){
		code = svgtiny_NOT_SVG;
        return code;
    }else if(svg->localName().compare("svg") != 0){
		code= svgtiny_NOT_SVG;
        return code;
    }else{
    
    
	/* get graphic dimensions */
	state.diagram = diagram;
	state.document = document;
	state.viewport_width = viewport_width;
	state.viewport_height = viewport_height;
	svgtiny_parse_position_attributes(svg, state, &x, &y, &width, &height);
	diagram->width = width;
	diagram->height = height;

	/* set up parsing state */
	state.viewport_width = width;
	state.viewport_height = height;
	state.ctm.a = 1; /*(float) viewport_width / (float) width;*/
	state.ctm.b = 0;
	state.ctm.c = 0;
	state.ctm.d = 1; /*(float) viewport_height / (float) height;*/
	state.ctm.e = 0; /*x;*/
	state.ctm.f = 0; /*y;*/
	/*state.style = css_base_style;
	state.style.font_size.value.length.value = option_font_size * 0.1;*/
	state.fill = 0x000000;
	state.stroke = svgtiny_TRANSPARENT;
	state.stroke_width = 1;
	state.linear_gradient_stop_count = 0;
        
        
        //borg
    state.info = &info;

	/* parse tree */

    ofPtr<svgNode> rootnode(new svgNode());
    rootnode->type = SVG_TAG_TYPE_DOCUMENT;
    info.rootnode = rootnode;
        
        
        
        //store root svg info
        
        info.width = ofToString(svg->getAttribute("width").c_str());
        info.height = ofToString(svg->getAttribute("height").c_str());
        info.x = ofToString(svg->getAttribute("x").c_str());
        info.y = ofToString(svg->getAttribute("y").c_str());
        info.viewbox = ofToString(svg->getAttribute("viewBox").c_str());
        info.id = ofToString(svg->getAttribute("id").c_str());
        info.xmlns = ofToString(svg->getAttribute("xmlns").c_str());
        info.version = ofToString(svg->getAttribute("version").c_str());
        info.preserveAspectRatio = ofToString(svg->getAttribute("preserveAspectRatio").c_str());
               
        
	code = svgtiny_parse_svg(info,svg, state,rootnode);

    }
    
        
    
	/* free XML tree */
	//xmlFreeDoc(document);
    
    
    //return without namespace
    //parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false);
    //document = parser.parseString(rawXMLstring);

	return code;
}
void DebugBreakpointManager::RestoreState(const Poco::Path& path)
{
  try
  {
    Poco::XML::DOMParser parser;

    Poco::FileInputStream reader(path.toString());
    Poco::XML::InputSource source(reader);

    //source.setSystemId(baseDir);
    Poco::XML::Document* doc = parser.parse(&source);
    Poco::XML::Element* breakpoints = doc->documentElement();

    if (breakpoints)
    {
      // restore object breakpoints
      Poco::XML::NodeList* elementList = breakpoints->getElementsByTagName(
          OBJECT_TAG);
      for (std::size_t i = 0; i < elementList->length(); i++)
      {
        Poco::XML::Element* elem =
            dynamic_cast<Poco::XML::Element*> (elementList->item(i));

        if (!elem->hasAttribute(ID_ATTR))
          continue;

        const std::string& attr = elem->getAttribute(ID_ATTR);

        int traceId = 0;
        try
        {
          traceId = Poco::NumberParser::parse(attr);
        } catch (const Poco::SyntaxException& e)
        {
          BERRY_WARN << e.displayText();
        }

        DebugUtil::GetBreakpointManager()->AddObjectBreakpoint(traceId);
      }
      elementList->release();

      // restore smartpointer breakpoints
      elementList = breakpoints->getElementsByTagName(SMARTPOINTER_TAG);
      for (std::size_t i = 0; i < elementList->length(); i++)
      {
        Poco::XML::Element* elem =
            dynamic_cast<Poco::XML::Element*> (elementList->item(i));

        if (!elem->hasAttribute(ID_ATTR))
          continue;

        const std::string& attr = elem->getAttribute(ID_ATTR);

        int spId = 0;
        try
        {
          spId = Poco::NumberParser::parse(attr);
        } catch (const Poco::SyntaxException& e)
        {
          BERRY_WARN << e.displayText();
        }

        DebugUtil::GetBreakpointManager()->AddSmartpointerBreakpoint(spId);
      }
      elementList->release();
    }

    doc->release();
  } catch (Poco::XML::SAXParseException& e)
  {
    BERRY_WARN << e.displayText();
  }
  catch (Poco::FileNotFoundException& /*e*/)
  {

  }
  catch (Poco::FileException& e)
  {
    BERRY_WARN << e.displayText();
  }
}
Пример #10
0
void DebugUtil::RestoreState()
{
    Poco::Path path;
    if (!GetPersistencePath(path)) return;

    path.setFileName(DEBUG_UTIL_XML);

    try
    {
        Poco::XML::DOMParser parser;

        Poco::FileInputStream reader(path.toString());
        Poco::XML::InputSource source(reader);

        //source.setSystemId(baseDir);
        Poco::XML::Document* doc = parser.parse(&source);
        Poco::XML::Element* debugutil = doc->documentElement();

        if (debugutil)
        {
            // restore traced objects
            Poco::XML::NodeList* elementList = debugutil->getElementsByTagName(TRACEOBJECT_TAG);
            for (std::size_t i = 0; i < elementList->length(); i++)
            {
                Poco::XML::Element* elem =
                    dynamic_cast<Poco::XML::Element*> (elementList->item(static_cast<unsigned long>(i)));

                if (!elem->hasAttribute(ID_ATTR)) continue;

                const std::string& attr = elem->getAttribute(ID_ATTR);

                int traceId = 0;
                try
                {
                    traceId = Poco::NumberParser::parse(attr);
                }
                catch (const Poco::SyntaxException& e)
                {
                    BERRY_WARN << e.displayText();
                }

                DebugUtil::TraceObject(traceId);
            }
            elementList->release();

            // restore traced classes
            elementList = debugutil->getElementsByTagName(TRACECLASS_TAG);
            for (std::size_t i = 0; i < elementList->length(); i++)
            {
                Poco::XML::Element* elem =
                    dynamic_cast<Poco::XML::Element*> (elementList->item(static_cast<unsigned long>(i)));

                if (!elem->hasAttribute(NAME_ATTR)) continue;

                const std::string& traceClass = elem->getAttribute(NAME_ATTR);
                if (!traceClass.empty())
                    DebugUtil::TraceClass(traceClass);
            }
            elementList->release();
        }

        doc->release();
    }
    catch (Poco::XML::SAXParseException& e)
    {
        BERRY_WARN << e.displayText();
    }
    catch (Poco::FileNotFoundException&)
    {

    }
    catch (Poco::FileException& e)
    {
        BERRY_WARN << e.displayText();
    }

    // restore BreakpointManager
    path.setFileName(DebugBreakpointManager::BREAKPOINTS_XML);
    GetBreakpointManager()->RestoreState(path);
}
Пример #11
0
/**
 * save XML grouping file
 */
void saveGroupingTabletoXML(Ui::MuonAnalysis& m_uiForm, const std::string& filename)
{
  std::ofstream outFile(filename.c_str());
  if (!outFile)
  {
    throw Mantid::Kernel::Exception::FileError("Unable to open file:", filename);
  }

  DOMWriter writer;
  writer.setNewLine("\n");
  writer.setOptions(XMLWriter::PRETTY_PRINT);

  Poco::XML::Document* mDoc = new Document();
  Element* rootElem = mDoc->createElement("detector-grouping");
  rootElem->setAttribute("description", m_uiForm.groupDescription->text().toStdString());
  mDoc->appendChild(rootElem);

  // loop over groups in table

  std::vector<int> groupToRow;
  whichGroupToWhichRow(m_uiForm, groupToRow);

  int num = static_cast<int>(groupToRow.size());
  for (int i = 0; i < num; i++)
  {
    Element* gElem = mDoc->createElement("group");
    gElem->setAttribute("name", m_uiForm.groupTable->item(groupToRow[i],0)->text().toStdString());
    rootElem->appendChild(gElem);
    Element* idsElem = mDoc->createElement("ids");
    idsElem->setAttribute("val", m_uiForm.groupTable->item(groupToRow[i],1)->text().toStdString());
    gElem->appendChild(idsElem);
  }

  // loop over pairs in pair table

  num = m_uiForm.pairTable->rowCount();
  for (int i = 0; i < num; i++)
  {
    QTableWidgetItem *itemName = m_uiForm.pairTable->item(i,0);
    if (!itemName)
      break;
    if ( itemName->text().isEmpty() )
      break;
    QTableWidgetItem *itemAlpha = m_uiForm.pairTable->item(i,3);
    if (!itemAlpha)
      break;
    if ( itemAlpha->text().isEmpty() )
      break;

    QComboBox* qw1 = static_cast<QComboBox*>(m_uiForm.pairTable->cellWidget(i,1));
    QComboBox* qw2 = static_cast<QComboBox*>(m_uiForm.pairTable->cellWidget(i,2));

    Element* gElem = mDoc->createElement("pair");
    gElem->setAttribute("name", itemName->text().toStdString());
    rootElem->appendChild(gElem);
    Element* fwElem = mDoc->createElement("forward-group");
    fwElem->setAttribute("val", qw1->currentText().toStdString());
    gElem->appendChild(fwElem);
    Element* bwElem = mDoc->createElement("backward-group");
    bwElem->setAttribute("val", qw2->currentText().toStdString());
    gElem->appendChild(bwElem);
    Element* alphaElem = mDoc->createElement("alpha");
    alphaElem->setAttribute("val", itemAlpha->text().toStdString());
    gElem->appendChild(alphaElem);
  } 

  // save default

  Element* gElem = mDoc->createElement("default");
  gElem->setAttribute("name", m_uiForm.frontGroupGroupPairComboBox->currentText().toStdString());
  rootElem->appendChild(gElem);

  writer.writeNode(outFile, mDoc);
}