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);
    }
}
Example #3
0
TEST_F(OtherTests, checkElement_failed)
{
    const char* elementPath1 = "/plane/wingss";
    const char* elementPath2 = "/plane/wings/wing[]";
    ASSERT_TRUE( tixiCheckElement( inDocumentHandle, elementPath1 ) == ELEMENT_NOT_FOUND);
    ASSERT_TRUE( tixiCheckElement( inDocumentHandle, elementPath2 ) == INVALID_XPATH);
}
Example #4
0
TEST_F(OtherTests, checkElement_success)
{
    const char* elementPath1 = "/plane/wings";
    const char* elementPath2 = "/plane/wings/wing";
    ASSERT_TRUE( tixiCheckElement( inDocumentHandle, elementPath1 ) == SUCCESS);
    ASSERT_TRUE( tixiCheckElement( inDocumentHandle, elementPath2 ) == SUCCESS);
}
Example #5
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;
}
Example #6
0
void CCPACSWingProfiles::ImportCPACS(TixiDocumentHandle tixiHandle)
{
    const std::string xpath = "/cpacs/vehicles/profiles";
    std::vector<CCPACSWingProfile*> children;
    if (tixiCheckElement(tixiHandle, (xpath + "/wingAirfoils").c_str()) == SUCCESS) {
        ReadContainerElement(tixiHandle, xpath, "wingAirfoil", 0, children);
    }
    if (tixiCheckElement(tixiHandle, (xpath + "/rotorAirfoils").c_str()) == SUCCESS) {
        ReadContainerElement(tixiHandle, xpath, "rotorAirfoil", 0, children);
    }
    for (std::size_t i = 0; i < children.size(); i++) {
        CCPACSWingProfile* child = children[i];
        if (profiles.find(child->GetUID()) != profiles.end()) {
            delete profiles[child->GetUID()];
        }
        profiles[child->GetUID()] = child;
    }
}
Example #7
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);
    }
}
Example #8
0
// Read CPACS guide curves
void CCPACSGuideCurveProfiles::ReadCPACS(TixiDocumentHandle tixiHandle)
{
    Cleanup();
    const std::string xpath = "/cpacs/vehicles/profiles/guideCurveProfiles";
    std::vector<CCPACSGuideCurveProfile*> children;
    if (tixiCheckElement(tixiHandle, xpath.c_str()) == SUCCESS) {
        ReadContainerElement(tixiHandle, xpath, "guideCurveProfile", 1, children);
        for (std::size_t i = 0; i < children.size(); i++) {
            guideCurves[children[i]->GetUID()].reset(children[i]);
        }
    }
}
// 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;
}
Example #10
0
void CCPACSWingCSStructure::ReadCPACS(TixiDocumentHandle tixiHandle, const std::string &structureXPath)
{
    Cleanup();
    
    // check path
    if ( tixiCheckElement(tixiHandle, structureXPath.c_str()) != SUCCESS) {
        LOG(ERROR) << "Wing structure " << structureXPath << " not found in CPACS file!" << std::endl;
        return;
    }
    
    // lower shell
    std::string shellPath;
    shellPath = structureXPath + "/upperShell";
    if ( tixiCheckElement(tixiHandle, shellPath.c_str()) == SUCCESS){
        upperShell.ReadCPACS(tixiHandle, shellPath.c_str());
    }
    
    shellPath = structureXPath + "/lowerShell";
    if ( tixiCheckElement(tixiHandle, shellPath.c_str()) == SUCCESS){
        lowerShell.ReadCPACS(tixiHandle, shellPath.c_str());
    }
    
    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();
}
Example #12
0
// Read CPACS wings element
void CCPACSWings::ReadCPACS(TixiDocumentHandle tixiHandle, const char* configurationUID)
{
    Cleanup();
    char *tmpString = NULL;

    if (tixiUIDGetXPath(tixiHandle, configurationUID, &tmpString) != SUCCESS) {
        throw CTiglError("XML error: tixiUIDGetXPath failed in CCPACSWings::ReadCPACS", TIGL_XML_ERROR);
    }

    std::string wingXPath= tmpString;
    wingXPath += "[@uID=\"";
    wingXPath += configurationUID;
    wingXPath += "\"]/wings";

    // Read wing profiles
    profiles.ReadCPACS(tixiHandle);

    if (tixiCheckElement(tixiHandle, wingXPath.c_str()) != SUCCESS) {
        return;
    }

    /* Get wing element count */
    int wingCount;
    if (tixiGetNamedChildrenCount(tixiHandle, wingXPath.c_str(), "wing", &wingCount) != SUCCESS) {
        throw CTiglError("XML error: tixiGetNamedChildrenCount failed in CCPACSWings::ReadCPACS", TIGL_XML_ERROR);
    }

    // Loop over all wings
    for (int i = 1; i <= wingCount; i++) {
        CCPACSWing* wing = new CCPACSWing(configuration);
        wings.push_back(wing);

        std::ostringstream xpath;
        xpath << wingXPath << "/wing[" << i << "]";
        wing->ReadCPACS(tixiHandle, xpath.str());
    }
}
Example #13
0
// Write CPACS fuselage profiles
void CCPACSFuselageProfiles::WriteCPACS(TixiDocumentHandle tixiHandle)
{
    const char* elementPath = "/cpacs/vehicles/profiles/fuselageProfiles";
    std::string path;
    ReturnCode tixiRet;
    int fuselageProfileCount, test;
    
    TixiSaveExt::TixiSaveElement(tixiHandle, "/cpacs/vehicles", "profiles");
    TixiSaveExt::TixiSaveElement(tixiHandle, "/cpacs/vehicles/profiles", "fuselageProfiles");
    
    if (tixiGetNamedChildrenCount(tixiHandle, elementPath, "fuselageProfile", &test) != SUCCESS) {
        throw CTiglError("XML error: tixiGetNamedChildrenCount failed in CCPACSFuselageProfiles::WriteCPACS", TIGL_XML_ERROR);
    }

    fuselageProfileCount = GetProfileCount();

    for (int i = 1; i <= fuselageProfileCount; i++) {
        std::stringstream ss;
        ss << elementPath << "/fuselageProfile[" << i << "]";
        path = ss.str();
        CCPACSFuselageProfile& fuselageProfile = GetProfile(i);
        if ((tixiRet = tixiCheckElement(tixiHandle, path.c_str())) == ELEMENT_NOT_FOUND) {
            if ((tixiRet = tixiCreateElement(tixiHandle, elementPath, "fuselageProfile")) != SUCCESS) {
                throw CTiglError("XML error: tixiCreateElement failed in CCPACSFuselageProfiles::WriteCPACS", TIGL_XML_ERROR);
            }
        }
        fuselageProfile.WriteCPACS(tixiHandle, path);
    }

    for (int i = fuselageProfileCount + 1; i <= test; i++) {
        std::stringstream ss;
        ss << elementPath << "/fuselageProfile[" << fuselageProfileCount + 1 << "]";
        path = ss.str();
        tixiRet = tixiRemoveElement(tixiHandle, path.c_str());
    }
}
Example #14
0
// Read CPACS fuselage profiles
void CCPACSFuselageProfiles::ReadCPACS(TixiDocumentHandle tixiHandle)
{
    Cleanup();

    if (tixiCheckElement(tixiHandle, "/cpacs/vehicles/profiles/fuselageProfiles") != SUCCESS) {
        return;
    }

    /* Get <geometry> element count */
    int geometryCount;
    if (tixiGetNamedChildrenCount(tixiHandle, "/cpacs/vehicles/profiles/fuselageProfiles", "fuselageProfile", &geometryCount) != SUCCESS) {
        throw CTiglError("Error: tixiGetNamedChildrenCount failed in CCPACSFuselageProfiles::ReadCPACS", TIGL_XML_ERROR);
    }

    // Loop over all <fuselageProfile> elements
    for (int i = 1; i <= geometryCount; i++) {
        std::ostringstream xpath;
        xpath << "/cpacs/vehicles/profiles/fuselageProfiles/fuselageProfile[" << i << "]";

        CCPACSFuselageProfile* profile = new CCPACSFuselageProfile(xpath.str());
        profile->ReadCPACS(tixiHandle);
        profiles[profile->GetUID()] = profile;
    }
}
Example #15
0
ReturnCode saveExternalFiles(xmlNodePtr aNodePtr, TixiDocument* aTixiDocument)
{
  TixiDocumentHandle handle = aTixiDocument->handle;
  xmlNodePtr cur_node = NULL;
  xmlNodePtr copiedNode = NULL;
  char* externalDataDirectory = NULL;
  char* externalFileName = NULL;
  char* fullExternalFileName = NULL;
  char* externalDataNodePath = NULL;
  char* fullExternalDataNodePath = NULL;
  xmlDocPtr xmlDocument = NULL;

  /* find external data nodes */
  for (cur_node = aNodePtr; cur_node; cur_node = cur_node->next) {

    /* recurse down with the next element */
    saveExternalFiles(cur_node->children, aTixiDocument);

    if( checkExternalNode( cur_node ) != SUCCESS) {
      continue;
    }

    if ( cur_node->type == XML_ELEMENT_NODE ) {
      char* dirResolved = NULL;
      char* includetNodeName = (char*) xmlGetNodePath(cur_node);

      /* collect node information - externalFileName */
      tixiGetTextAttribute(handle, includetNodeName,
                           EXTERNAL_DATA_XML_ATTR_FILENAME, &externalFileName);

      /* collect node information - externalDataDirectory */
      tixiGetTextAttribute(handle, includetNodeName,
                           EXTERNAL_DATA_XML_ATTR_DIRECTORY, &externalDataDirectory);

      /* collect node information - externalDataNodePath */
      tixiGetTextAttribute(handle, includetNodeName,
                           EXTERNAL_DATA_XML_ATTR_NODEPATH, &externalDataNodePath);

      free(includetNodeName);


      /* remove attributes */
      xmlUnsetProp(cur_node, (xmlChar*) EXTERNAL_DATA_XML_ATTR_FILENAME);
      xmlUnsetProp(cur_node, (xmlChar*) EXTERNAL_DATA_XML_ATTR_DIRECTORY);
      xmlUnsetProp(cur_node, (xmlChar*) EXTERNAL_DATA_XML_ATTR_NODEPATH);


      /* create new document */
      xmlDocument = xmlNewDoc((xmlChar*) "1.0");
      if (!xmlDocument) {
        printMsg(MESSAGETYPE_ERROR, "Error in TIXI::saveExternalFiles ==> Could not create new document.\n");
        return FAILED;
      }

      /* deep copy of nodes from external files */
      copiedNode = xmlDocCopyNode(cur_node, xmlDocument, 1);

      xmlDocSetRootElement(xmlDocument, copiedNode);

      dirResolved = resolveDirectory(aTixiDocument->dirname, externalDataDirectory);

      /* only save to local paths */
      if(string_startsWith(dirResolved, "file://") == 0) {
        char* externalDataDirectoryNotUrl = uriToLocalPath(dirResolved);
        assert(externalDataDirectoryNotUrl);

        fullExternalFileName = buildString("%s%s", externalDataDirectoryNotUrl, externalFileName);
        xmlSaveFormatFileEnc(fullExternalFileName, xmlDocument, "utf-8", 1);
        free(fullExternalFileName);
        free(externalDataDirectoryNotUrl);
      }
      free(dirResolved);
      xmlFreeDoc(xmlDocument);

      /* create external data node structure */
      fullExternalDataNodePath = buildString("%s/%s", externalDataNodePath, EXTERNAL_DATA_NODE_NAME);

      /* add parent node if not exists */
      if(tixiCheckElement(handle, fullExternalDataNodePath) != SUCCESS) {
        tixiAddTextElement(handle, externalDataNodePath, EXTERNAL_DATA_NODE_NAME, "");
        tixiAddTextElement(handle, fullExternalDataNodePath, EXTERNAL_DATA_NODE_NAME_PATH, externalDataDirectory);
      }

      /* add node for external reference */
      tixiAddTextElement(handle, fullExternalDataNodePath, EXTERNAL_DATA_NODE_NAME_FILENAME, externalFileName);

      /* remove the copied nodes from document*/
      copiedNode = cur_node->prev;
      xmlUnlinkNode(cur_node);
      xmlFreeNode(cur_node);
      free(fullExternalDataNodePath);
      cur_node = copiedNode;
    }
  }
  return SUCCESS;
}