void CCPACSWingRibExplicitPositioning::ReadCPACS(TixiDocumentHandle tixiHandle, const std::string& explicitRibPosXPath)
{
    Cleanup();

    // Get subelement "startReference"
    char* ptrStartReference = NULL;
    if (tixiGetTextElement(tixiHandle, (explicitRibPosXPath + "/startReference").c_str(), &ptrStartReference) != SUCCESS) {
        LOG(ERROR) << "Missing startReference";
        throw CTiglError("Error: Missing startReference in CCPACSWingRibExplicitPositioning::ReadCPACS!", TIGL_XML_ERROR);
    }
    startReference = ptrStartReference;

    // Get subelement "etaStart"
    ReturnCode tixiRet = tixiGetDoubleElement(tixiHandle, (explicitRibPosXPath + "/etaStart").c_str(), &startEta);
    if (tixiRet != SUCCESS) {
        LOG(ERROR) << "Missing etaStart";
        throw CTiglError("Error: Missing etaStart in CCPACSWingRibExplicitPositioning::ReadCPACS!", TIGL_XML_ERROR);
    }

    // Get subelement "endReference"
    char* ptrEndReference = NULL;
    if (tixiGetTextElement(tixiHandle, (explicitRibPosXPath + "/endReference").c_str(), &ptrEndReference) != SUCCESS) {
        LOG(ERROR) << "Missing endReference";
        throw CTiglError("Error: Missing endReference in CCPACSWingRibExplicitPositioning::ReadCPACS!", TIGL_XML_ERROR);
    }
    endReference = ptrEndReference;

    // Get subelement "etaEnd"
    tixiRet = tixiGetDoubleElement(tixiHandle, (explicitRibPosXPath + "/etaEnd").c_str(), &endEta);
    if (tixiRet != SUCCESS) {
        LOG(ERROR) << "Missing etaEnd";
        throw CTiglError("Error: Missing etaEnd in CCPACSWingRibExplicitPositioning::ReadCPACS!", TIGL_XML_ERROR);
    }
}
Beispiel #2
0
// Read wing profile file
void CCPACSWingProfile::ReadCPACS(TixiDocumentHandle tixiHandle)
{
    Cleanup();
    std::string namePath = ProfileXPath + "/name";
    std::string describtionPath = ProfileXPath + "/description";

    try {
        // Get profiles "uid"
        char* ptrUID = NULL;
        if (tixiGetTextAttribute(tixiHandle, ProfileXPath.c_str(), "uID", &ptrUID) == SUCCESS) {
            uid = ptrUID;
        }

        // Get subelement "name"
        char* ptrName = NULL;
        if (tixiGetTextElement(tixiHandle, namePath.c_str(), &ptrName) == SUCCESS) {
            name = ptrName;
        }

        // Get subelement "description"
        char* ptrDescription = NULL;
        if (tixiGetTextElement(tixiHandle, describtionPath.c_str(), &ptrDescription) == SUCCESS) {
            description = ptrDescription;
        }

        // create wing profile algorithm via factory
        profileAlgo=CCPACSWingProfileFactory::Instance().CreateProfileAlgo(tixiHandle, *this, ProfileXPath);
        // read in wing profile data
        profileAlgo->ReadCPACS(tixiHandle);
    }
    catch (...) {
        throw;
    }
}
Beispiel #3
0
// Read CPACS fuselage element
void CCPACSFuselage::ReadCPACS(TixiDocumentHandle tixiHandle, const std::string& fuselageXPath)
{
    Cleanup();

    char*       elementPath;
    std::string tempString;

    // Get subelement "name"
    char* ptrName = NULL;
    tempString    = fuselageXPath + "/name";
    elementPath   = const_cast<char*>(tempString.c_str());
    if (tixiGetTextElement(tixiHandle, elementPath, &ptrName)==SUCCESS) {
        name = ptrName;
    }

    // Get attribue "uID"
    char* ptrUID = NULL;
    tempString   = "uID";
    elementPath  = const_cast<char*>(tempString.c_str());
    if (tixiGetTextAttribute(tixiHandle, const_cast<char*>(fuselageXPath.c_str()), const_cast<char*>(tempString.c_str()), &ptrUID) == SUCCESS) {
        SetUID(ptrUID);
    }

    // Get subelement "parent_uid"
    char* ptrParentUID = NULL;
    tempString         = fuselageXPath + "/parentUID";
    elementPath        = const_cast<char*>(tempString.c_str());
    if (tixiCheckElement(tixiHandle, elementPath) == SUCCESS  && 
        tixiGetTextElement(tixiHandle, elementPath, &ptrParentUID) == SUCCESS ) {

        SetParentUID(ptrParentUID);
    }

    transformation.ReadCPACS(tixiHandle, fuselageXPath);

    // Get subelement "sections"
    sections.ReadCPACS(tixiHandle, fuselageXPath);

    // Get subelement "positionings"
    positionings.ReadCPACS(tixiHandle, fuselageXPath);

    // Get subelement "segments"
    segments.ReadCPACS(tixiHandle, fuselageXPath);

    // Register ourself at the unique id manager
    configuration->GetUIDManager().AddUID(ptrUID, this);

    // Get symmetry axis attribute
    char* ptrSym = NULL;
    tempString   = "symmetry";
    if (tixiGetTextAttribute(tixiHandle, const_cast<char*>(fuselageXPath.c_str()), const_cast<char*>(tempString.c_str()), &ptrSym) == SUCCESS) {
        SetSymmetryAxis(ptrSym);
    }
}
Beispiel #4
0
void CCPACSMaterial::ReadCPACS(TixiDocumentHandle tixiHandle, const std::string &materialXPath)
{
    Cleanup();
    
    // check path
    if ( tixiCheckElement(tixiHandle, materialXPath.c_str()) != SUCCESS) {
        LOG(ERROR) << "Material definition" << materialXPath << " not found in CPACS file!" << std::endl;
        return;
    }
    
    // test whether composite or normal material
    std::string tempstring = materialXPath + "/materialUID";
    char * matUID = NULL;
    if (tixiGetTextElement(tixiHandle, tempstring.c_str(), &matUID) == SUCCESS){
        uid = matUID;
        is_composite = false;
    }
    else if (tixiGetTextElement(tixiHandle, std::string(materialXPath + "/compositeUID").c_str(), &matUID) == SUCCESS){
        uid = matUID;
        is_composite = true;
    }
    else {
        throw CTiglError("Neither Material UID nor Composite UID  specified in " + materialXPath, TIGL_ERROR);
    }
    
    // get thickness (not mandatory)
    tempstring = materialXPath + "/thickness";
    if (tixiCheckElement(tixiHandle, tempstring.c_str())== SUCCESS) {
       if (tixiGetDoubleElement(tixiHandle, tempstring.c_str(), &thickness) != SUCCESS) {
           LOG(ERROR) << "Invalid material thickness in " << materialXPath;
       }
    }
    else if (tixiCheckElement(tixiHandle, std::string(materialXPath + "/thicknessScaling").c_str())== SUCCESS) {
       if (tixiGetDoubleElement(tixiHandle, std::string(materialXPath + "/thicknessScaling").c_str(), &thicknessScaling) != SUCCESS) {
           LOG(ERROR) << "Invalid composite thickness scaling in " << materialXPath;
       }
    }
    else {
        if (!isComposite()) {
            LOG(INFO) << "Thickness of Material " << materialXPath << " not set.";
        }
        else {
            LOG(INFO) << "Thickness scaling of Composite Material " << materialXPath << " not set.";
        }
    }
    
    isvalid = true;
}
// Read CPACS segment elements
void CCPACSFuselagePositioning::ReadCPACS(TixiDocumentHandle tixiHandle, const std::string& positioningXPath)
{
    Cleanup();

    char*       elementPath;
    std::string tempString;

    // Get subelement "length"
    tempString  = positioningXPath + "/length";
    elementPath = const_cast<char*>(tempString.c_str());
    tixiGetDoubleElement(tixiHandle, elementPath, &length);

    // Get subelement "sweepAngle"
    tempString  = positioningXPath + "/sweepAngle";
    elementPath = const_cast<char*>(tempString.c_str());
    tixiGetDoubleElement(tixiHandle, elementPath, &sweepangle);

    // Get subelement "dihedralAngle"
    tempString  = positioningXPath + "/dihedralAngle";
    elementPath = const_cast<char*>(tempString.c_str());
    tixiGetDoubleElement(tixiHandle, elementPath, &dihedralangle);

    // Get subelement "toSectionUID"
    char*         ptrOuterSection = NULL;
    tempString  = positioningXPath + "/toSectionUID";
    elementPath = const_cast<char*>(tempString.c_str());
    if (tixiGetTextElement(tixiHandle, elementPath, &ptrOuterSection) != SUCCESS){
        std::stringstream stream;
        stream << "Error: Can't read element" << tempString << "in CCPACSFuselagePositioning:ReadCPACS";
        throw CTiglError(stream.str(), TIGL_XML_ERROR);
    }
    endSection = ptrOuterSection;

    // Get subelement "fromSectionUID"
    char*         ptrInnerSection = NULL;
    tempString  = positioningXPath + "/fromSectionUID";
    elementPath = const_cast<char*>(tempString.c_str());
    if (tixiCheckElement(tixiHandle, elementPath) == SUCCESS &&
        tixiGetTextElement(tixiHandle, elementPath, &ptrInnerSection) == SUCCESS ) {

        startSection = ptrInnerSection;
    }
    else {
        startSection = "";
    }

    Update();
}
// Read CPACS section elements
void CCPACSFuselageConnection::ReadCPACS(TixiDocumentHandle tixiHandle, const std::string& connectionXPath)
{
    Cleanup();

    char*       elementPath;
    std::string tempString;

    // Get subelement "element"
    char* ptrElementUID = NULL;
    tempString    = connectionXPath;
    elementPath   = const_cast<char*>(tempString.c_str());
    if (tixiGetTextElement(tixiHandle, elementPath, &ptrElementUID) != SUCCESS) {
        throw CTiglError("Error: Can't read element <element/> in CCPACSFuselageConnection::ReadCPACS", TIGL_XML_ERROR);
    }
    elementUID = ptrElementUID;

    // find the corresponding section to this segment
    CCPACSFuselage& fuselage = segment->GetFuselage();
    for (int i=1; i <= fuselage.GetSectionCount(); i++) {
        CCPACSFuselageSection& section = fuselage.GetSection(i);
        for (int j=1; j <= section.GetSectionElementCount(); j++) {
            if (section.GetSectionElement(j).GetUID() == elementUID ) {
                sectionUID = section.GetUID();
                sectionIndex = i;
                elementIndex = j;
            }
        }
    }
}
void CCPACSWingCellPositionChordwise::ReadCPACS(TixiDocumentHandle tixiHandle,  const std::string& xpath)
{
    Reset();

    // Get subelement "xsi1, xsi2" or Spar Uid (choice)
    const std::string sparUIdString  = xpath + "/sparUID";
    const std::string xsi1String     = xpath + "/xsi1";

    if (tixiCheckElement(tixiHandle, xsi1String.c_str()) == SUCCESS) {
        m_inputType = Xsi;
        if (tixiGetDoubleElement(tixiHandle, xsi1String.c_str(), &m_xsi1) != SUCCESS) {
            LOG(ERROR) << "Error during read of <xsi1>";
            throw CTiglError("Error: Error during read of <xsi1> in CCPACSWingCellPositionChordwise::ReadCPACS!", TIGL_XML_ERROR);
        }
        if (tixiGetDoubleElement(tixiHandle, (xpath + "/xsi2").c_str(), &m_xsi2) != SUCCESS) {
            LOG(ERROR) << "Error during read of <xsi2>";
            throw CTiglError("Error: Error during read of <xsi2> in CCPACSWingCellPositionChordwise::ReadCPACS!", TIGL_XML_ERROR);
        }
    }
    else if (tixiCheckElement(tixiHandle, sparUIdString.c_str()) == SUCCESS) {
        m_inputType = Spar;
        char* ptrSUId = NULL;
        if (tixiGetTextElement(tixiHandle, sparUIdString.c_str(), &ptrSUId) != SUCCESS) {
            LOG(ERROR) << "Error during read of <sparUID>";
            throw CTiglError("Error: Error during read of <sparUID> in CCPACSWingCellPositionChordwise::ReadCPACS!", TIGL_XML_ERROR);
        }
        m_sparUID = ptrSUId;

    }
    else {
        LOG(ERROR) << "Missing element <xsi1> or <sparUID>";
        throw CTiglError("Error: Missing element <xsi1> or <sparUID> in CCPACSWingCellPositionChordwise::ReadCPACS!", TIGL_XML_ERROR);
    }
}
void CCPACSControlSurfaceDeviceAirfoil::ReadCPACS(TixiDocumentHandle tixiHandle, const std::string& xpath)
{
    char* tmp = NULL;

    if (tixiGetTextElement(tixiHandle, (xpath + "/airfoilUID").c_str(), &tmp) == SUCCESS) {
        _airfoilUID = tmp;

        // check if airfoil exists by query
        _config->GetWingProfile(_airfoilUID);
    }
    else {
        throw CTiglError("Missing airfoilUID element in path: " + xpath + "!", TIGL_OPEN_FAILED);
    }

    _rotX = 90.0;
    if (tixiCheckElement(tixiHandle, (xpath + "/rotX").c_str()) == SUCCESS) {
        tixiGetDoubleElement(tixiHandle, (xpath + "/rotX").c_str(), &_rotX);
    }

    // check, if yscale != 1. If yes, we show a warning
    double scalY;
    if (tixiCheckElement(tixiHandle, (xpath + "/scalY").c_str()) == SUCCESS) {
        tixiGetDoubleElement(tixiHandle, (xpath + "/scalY").c_str(), &scalY);
        if (fabs(scalY - 1.0) > 1e-10) {
            LOG(WARNING) << "Y scaling in \"" << xpath << "\" ignored. Only 2D profiles supported.";
        }
    }

    _scalZ = 1.0;
    if (tixiCheckElement(tixiHandle, (xpath + "/scalZ").c_str()) == SUCCESS) {
        tixiGetDoubleElement(tixiHandle, (xpath + "/scalZ").c_str(), &_scalZ);
    }
}
TEST_F(UpdateElementTests, updateTextElement_success)
{
    const char* parentPath = "/rootElement/text";
    const char* text = "This is my content.";
    char *text2 = NULL;

    ASSERT_TRUE( tixiUpdateTextElement( documentHandle, parentPath, text ) == SUCCESS );
    ASSERT_TRUE( tixiGetTextElement( documentHandle, parentPath, &text2 ) == SUCCESS );
    ASSERT_TRUE( !strcmp(text2, text ));
}
Beispiel #10
0
// Read CPACS header elements
void CCPACSHeader::ReadCPACS(TixiDocumentHandle tixiHandle)
{
    Cleanup();

    char* ptrName      = NULL;
    char* ptrCreator   = NULL;
    char* ptrTimestamp = NULL;

    if (tixiGetTextElement(tixiHandle, "/cpacs/header/name",      &ptrName) == SUCCESS) {
        name      = ptrName;
    }

    if (tixiGetTextElement(tixiHandle, "/cpacs/header/creator",   &ptrCreator) == SUCCESS) {
        creator   = ptrCreator;
    }

    if (tixiGetTextElement(tixiHandle, "/cpacs/header/timestamp", &ptrTimestamp) == SUCCESS) {
        timestamp = ptrTimestamp;
    }
}
// Read CPACS trailingEdgeDevice elements
void CCPACSControlSurfaceDevice::ReadCPACS(TixiDocumentHandle tixiHandle, const std::string& controlSurfaceDeviceXPath, TiglControlSurfaceType type)
{
    char*       elementPath;
    std::string tempString;

    // Get sublement "outerShape"
    char* ptrName = NULL;
    tempString    = controlSurfaceDeviceXPath + "/outerShape";
    elementPath   = const_cast<char*>(tempString.c_str());
    if (tixiGetTextElement(tixiHandle, elementPath, &ptrName) == SUCCESS) {
        outerShape.ReadCPACS(tixiHandle, elementPath, type);
    }

    // Get Path
    tempString = controlSurfaceDeviceXPath + "/path";
    elementPath = const_cast<char*>(tempString.c_str());
    if (tixiCheckElement(tixiHandle, elementPath) == SUCCESS) {
        path.ReadCPACS(tixiHandle, elementPath);
    }


    char* ptrUID = NULL;
    if (tixiGetTextAttribute(tixiHandle, controlSurfaceDeviceXPath.c_str(), "uID", &ptrUID) == SUCCESS) {
        SetUID(ptrUID);
    }

    // Get WingCutOut
    tempString = controlSurfaceDeviceXPath + "/wingCutOut";
    elementPath = const_cast<char*>(tempString.c_str());
    if (tixiCheckElement(tixiHandle, elementPath) == SUCCESS) {
        wingCutOut = CSharedPtr<CCPACSControlSurfaceDeviceWingCutOut>(new CCPACSControlSurfaceDeviceWingCutOut(*this, *_segment));
        wingCutOut->ReadCPACS(tixiHandle, elementPath);
    }

    _type = type;

    currentDeflection = GetMinDeflection() > 0? GetMinDeflection() : 0;
    currentDeflection = currentDeflection > GetMaxDeflection()? GetMaxDeflection() : currentDeflection;
}
Beispiel #12
0
ReturnCode openExternalFiles(TixiDocument* aTixiDocument, int* number)
{
  int iNode = 0;
  int handle = aTixiDocument->handle;
  xmlNodePtr cur = NULL;
  ReturnCode error = SUCCESS;

  assert(aTixiDocument != NULL);
  *number = 0;

  while(1) {
    // loop until there are no externaldata nodes included

    xmlXPathObjectPtr xpathObject = XPathEvaluateExpression(aTixiDocument->docPtr, "//externaldata");
    xmlNodeSetPtr nodeset = NULL;
    char* externalDataNodeXPath, *externalDataDirectoryXPath, *externalDataDirectory, *resolvedDirectory;
    int externalFileCount = 0;

    if (!xpathObject) {
      // no more external data, stop
      break;
    }

    nodeset = xpathObject->nodesetval;
    if (!nodeset || nodeset->nodeNr < 1) {
      break;
    }

    // goto the first node that is an element
    for (iNode = 0; iNode < nodeset->nodeNr; ++iNode) {
      cur = nodeset->nodeTab[iNode];
      if (cur->type == XML_ELEMENT_NODE) {
        break; // for loop
      }
    }
    if (iNode == nodeset->nodeNr) {
      // no element node found
      xmlXPathFreeObject(xpathObject);
      break; // while loop
    }

    // found external data node
    xmlXPathFreeObject(xpathObject);

    /* get nodes XPath */
    externalDataNodeXPath = (char*) xmlGetNodePath(cur);


    /* now get the subdirectory */
    externalDataDirectoryXPath = buildString("%s/%s", externalDataNodeXPath, EXTERNAL_DATA_NODE_NAME_PATH);

    error = tixiGetTextElement(handle, externalDataDirectoryXPath, &externalDataDirectory);
    free(externalDataDirectoryXPath);
    if (error) {
      printMsg(MESSAGETYPE_ERROR, "Error: openExternalFiles returns %d. No path defined in externaldata node!\n", error);
      xmlFree(externalDataNodeXPath);
      return OPEN_FAILED;
    }

    // resolv data directory (in case of relative paths)
    resolvedDirectory = resolveDirectory(aTixiDocument->dirname, externalDataDirectory);

    /* now get number and names of all external files */
    tixiGetNamedChildrenCount(handle, externalDataNodeXPath, EXTERNAL_DATA_NODE_NAME_FILENAME, &externalFileCount);
    if (externalFileCount == 0) {
      printMsg(MESSAGETYPE_ERROR, "Error: no filename nodes defined in externalData node.\n");
      xmlFree(externalDataNodeXPath);
      free(resolvedDirectory);
      return OPEN_FAILED;
    }

    for (iNode = 1; iNode <= externalFileCount; iNode++) {
      char* externalFileName, *externalFullFileName, *newDocumentString, *fileNameXPath;
      xmlDocPtr xmlDocument = NULL;

      fileNameXPath = buildString("%s/filename[%d]", externalDataNodeXPath, iNode);

      tixiGetTextElement(handle, fileNameXPath, &externalFileName);
      free(fileNameXPath);

      /* Build complete filename */
      externalFullFileName = buildString("%s%s", resolvedDirectory, externalFileName);

      /* open files */
      newDocumentString = loadExternalFileToString(externalFullFileName);
      if (newDocumentString == NULL) {
        printMsg(MESSAGETYPE_ERROR, "\nError in fetching external file \"%s\".\n", externalFullFileName);
        free(externalFullFileName);
        xmlFree(externalDataNodeXPath);
        free(resolvedDirectory);
        return OPEN_FAILED;
      }

      /* now parse the file to DOM */
      xmlDocument = xmlReadMemory(newDocumentString, (int) strlen(newDocumentString), "urlResource", NULL, 0);
      free(newDocumentString);

      if (xmlDocument) {
        xmlNodePtr rootToInsert = xmlDocGetRootElement(xmlDocument);

        xmlNodePtr parent = cur->parent;
        if (parent) {
          xmlChar* nodePathNew = NULL;
          char* dataURI = localPathToURI(externalDataDirectory);
          xmlNodePtr nodeToInsert = xmlDocCopyNode(rootToInsert, aTixiDocument->docPtr, 1);

          /* add metadata to node, to allow saving external node data */
          xmlSetProp(nodeToInsert, (xmlChar*) EXTERNAL_DATA_XML_ATTR_FILENAME, (xmlChar*) externalFileName);

          /* save the sub-directory */
          xmlSetProp(nodeToInsert, (xmlChar*) EXTERNAL_DATA_XML_ATTR_DIRECTORY, (xmlChar*) dataURI);
          free(dataURI);

          /* save the external data node position */
          nodePathNew = xmlGetNodePath(parent);
          xmlSetProp(nodeToInsert, (xmlChar*) EXTERNAL_DATA_XML_ATTR_NODEPATH, nodePathNew);
          xmlFree(nodePathNew);

          /* replace externalData node with xml file's content */
          xmlReplaceNode(cur, nodeToInsert);

          /* file could be loaded and parsed, increase the counter */
          (*number)++;
        }

        xmlFreeDoc(xmlDocument);
      }
      else {
        printMsg(MESSAGETYPE_WARNING,
                 "Document %s will be ignored. No valid XML document!\n",
                 externalFullFileName);

        /* remove external data node */
        xmlUnlinkNode(cur);
      }
      free(externalFullFileName);
    } /* end for files */

    free(resolvedDirectory);
    free(externalDataNodeXPath);
    xmlFreeNode(cur);
  }


  if (*number == 0) {
    printMsg(MESSAGETYPE_WARNING, "WARNING: Unable to load any externaldata files.\n");
  }

  return SUCCESS;
}