Пример #1
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);
    }
}
Пример #2
0
TEST_F(GetAttributeTests, notUnique)
{
  char* text = NULL;
  const char* elementPath = "/plane/wings/wing";
  const char* attributeName = "position";
  ASSERT_TRUE( tixiGetTextAttribute( documentHandle, elementPath, attributeName, &text ) == ELEMENT_PATH_NOT_UNIQUE );
}
Пример #3
0
TEST_F(GetAttributeTests, invalidXpath)
{
  char* text = NULL;
  const char* elementPath = "cc/plane/name|||/pp";
  const char* attributeName = "position";
  ASSERT_TRUE( tixiGetTextAttribute( documentHandle, elementPath, attributeName, &text ) == INVALID_XPATH );
}
Пример #4
0
TEST_F(GetAttributeTests, elementNotFound)
{
  char* text = NULL;
  const char* elementPath = "/plane/name/pp";
  const char* attributeName = "non_existing_attribute";
  ASSERT_TRUE( tixiGetTextAttribute( documentHandle, elementPath, attributeName, &text ) == ELEMENT_NOT_FOUND );
}
Пример #5
0
TEST_F(GetAttributeTests, attributeNotFound)
{
  char* text = NULL;
  const char* elementPath = "/plane/wings/wing[1]";
  const char* attributeName = "non_existing_attribute";
  ASSERT_TRUE( tixiGetTextAttribute( documentHandle, elementPath, attributeName, &text ) == ATTRIBUTE_NOT_FOUND );
}
Пример #6
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;
    }
}
Пример #7
0
TEST_F(GetAttributeTests, invalidHandle)
{
  char* text = NULL;
  const char* elementPath = "/plane/name";
  const char* attributeName = "non_existing_attribute";

  ASSERT_TRUE( tixiGetTextAttribute( -1, elementPath, attributeName, &text ) == INVALID_HANDLE );
}
Пример #8
0
// 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;
}
Пример #9
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;
}