Skip to content

Commit

Permalink
Support for importing SealedSurfaceFramework
Browse files Browse the repository at this point in the history
  • Loading branch information
philippeVerney committed Mar 5, 2019
1 parent ec50d78 commit 58156cc
Show file tree
Hide file tree
Showing 18 changed files with 712 additions and 172 deletions.
70 changes: 70 additions & 0 deletions src/common/AbstractObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ under the License.
#include "version_config.h"

#include "resqml2/Activity.h"
#include "common/AbstractHdfProxy.h"

using namespace std;
using namespace COMMON_NS;
Expand Down Expand Up @@ -881,3 +882,72 @@ std::string AbstractObject::getExtraMetadataStringValueAtIndex(const unsigned in
}
}

void AbstractObject::readArrayNdOfUIntValues(gsoap_resqml2_0_1::resqml2__AbstractIntegerArray * arrayInput, unsigned int * arrayOutput) const
{
long soapType = arrayInput->soap_type();
if (soapType == SOAP_TYPE_gsoap_resqml2_0_1_resqml2__IntegerHdf5Array)
{
COMMON_NS::AbstractHdfProxy* hdfProxy = epcDocument->getResqmlAbstractObjectByUuid<COMMON_NS::AbstractHdfProxy>(static_cast<gsoap_resqml2_0_1::resqml2__IntegerHdf5Array*>(arrayInput)->Values->HdfProxy->UUID);
if (hdfProxy == nullptr) {
throw invalid_argument("The hdf proxy " + static_cast<gsoap_resqml2_0_1::resqml2__IntegerHdf5Array*>(arrayInput)->Values->HdfProxy->UUID + " is not available.");
}
hdfProxy->readArrayNdOfUIntValues(static_cast<gsoap_resqml2_0_1::resqml2__IntegerHdf5Array*>(arrayInput)->Values->PathInHdfFile, arrayOutput);
}
else if (soapType == SOAP_TYPE_gsoap_resqml2_0_1_resqml2__IntegerRangeArray)
{
gsoap_resqml2_0_1::resqml2__IntegerRangeArray* rangeArray = static_cast<gsoap_resqml2_0_1::resqml2__IntegerRangeArray*>(arrayInput);
for (size_t i = 0; i < rangeArray->Count; ++i) {
arrayOutput[i] = i + rangeArray->Value;
}
}
else if (soapType == SOAP_TYPE_gsoap_resqml2_0_1_resqml2__IntegerConstantArray)
{
gsoap_resqml2_0_1::resqml2__IntegerConstantArray* constantArray = static_cast<gsoap_resqml2_0_1::resqml2__IntegerConstantArray*>(arrayInput);
for (size_t i = 0; i < constantArray->Count; ++i) {
arrayOutput[i] = constantArray->Value;
}
}
else if (soapType == SOAP_TYPE_gsoap_resqml2_0_1_resqml2__IntegerLatticeArray)
{
gsoap_resqml2_0_1::resqml2__IntegerLatticeArray* latticeArray = static_cast<gsoap_resqml2_0_1::resqml2__IntegerLatticeArray*>(arrayInput);
if (latticeArray->Offset.size() > 1) {
throw invalid_argument("The integer lattice array contains more than one offset.");
}
for (size_t i = 0; i <= latticeArray->Offset[0]->Count; ++i) {
arrayOutput[i] = latticeArray->StartValue + (i * latticeArray->Offset[0]->Value);
}
}
else
throw invalid_argument("The integer array type is not supported yet.");
}

ULONG64 AbstractObject::getCountOfIntegerArray(gsoap_resqml2_0_1::resqml2__AbstractIntegerArray * arrayInput) const
{
long soapType = arrayInput->soap_type();
if (soapType == SOAP_TYPE_gsoap_resqml2_0_1_resqml2__IntegerHdf5Array)
{
COMMON_NS::AbstractHdfProxy* hdfProxy = epcDocument->getResqmlAbstractObjectByUuid<COMMON_NS::AbstractHdfProxy>(static_cast<gsoap_resqml2_0_1::resqml2__IntegerHdf5Array*>(arrayInput)->Values->HdfProxy->UUID);
if (hdfProxy == nullptr) {
throw invalid_argument("The hdf proxy " + static_cast<gsoap_resqml2_0_1::resqml2__IntegerHdf5Array*>(arrayInput)->Values->HdfProxy->UUID + " is not available.");
}
return hdfProxy->getElementCount(static_cast<gsoap_resqml2_0_1::resqml2__IntegerHdf5Array*>(arrayInput)->Values->PathInHdfFile);
}
else if (soapType == SOAP_TYPE_gsoap_resqml2_0_1_resqml2__IntegerRangeArray)
{
return static_cast<gsoap_resqml2_0_1::resqml2__IntegerRangeArray*>(arrayInput)->Count;
}
else if (soapType == SOAP_TYPE_gsoap_resqml2_0_1_resqml2__IntegerConstantArray)
{
return static_cast<gsoap_resqml2_0_1::resqml2__IntegerConstantArray*>(arrayInput)->Count;
}
else if (soapType == SOAP_TYPE_gsoap_resqml2_0_1_resqml2__IntegerLatticeArray)
{
gsoap_resqml2_0_1::resqml2__IntegerLatticeArray* latticeArray = static_cast<gsoap_resqml2_0_1::resqml2__IntegerLatticeArray*>(arrayInput);
if (latticeArray->Offset.size() > 1) {
throw invalid_argument("The integer lattice array contains more than one offset.");
}
return static_cast<gsoap_resqml2_0_1::resqml2__IntegerLatticeArray*>(arrayInput)->Offset[0]->Count + 1;
}
else
throw invalid_argument("The integer array type is not supported yet.");
}
14 changes: 14 additions & 0 deletions src/common/AbstractObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ namespace COMMON_NS
*/
void changeToPartialObject();

/*
* Read an input array which come from XML (and potentially HDF5) and store it into a preallocated output array in memory.
* It does not allocate or deallocate memory.
*/
void readArrayNdOfUIntValues(gsoap_resqml2_0_1::resqml2__AbstractIntegerArray * arrayInput, unsigned int * arrayOutput) const;

/*
* Get the count of item in an array of integer
*
* @param arrayInput The array of integer.
* @return The count of item in the array of integer.
*/
ULONG64 getCountOfIntegerArray(gsoap_resqml2_0_1::resqml2__AbstractIntegerArray * arrayInput) const;

public:
virtual ~AbstractObject() {}

Expand Down
5 changes: 2 additions & 3 deletions src/common/EpcDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1993,10 +1993,9 @@ RESQML2_NS::RepresentationSetRepresentation* EpcDocument::createPartialRepresent
NonSealedSurfaceFrameworkRepresentation* EpcDocument::createNonSealedSurfaceFrameworkRepresentation(
StructuralOrganizationInterpretation* interp,
const std::string & guid,
const std::string & title,
const bool & isSealed)
const std::string & title)
{
NonSealedSurfaceFrameworkRepresentation* result = new NonSealedSurfaceFrameworkRepresentation(interp, guid, title, isSealed);
NonSealedSurfaceFrameworkRepresentation* result = new NonSealedSurfaceFrameworkRepresentation(interp, guid, title);
addFesapiWrapperAndDeleteItIfException(result);
return result;
}
Expand Down
3 changes: 1 addition & 2 deletions src/common/EpcDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,7 @@ namespace COMMON_NS
RESQML2_0_1_NS::NonSealedSurfaceFrameworkRepresentation* createNonSealedSurfaceFrameworkRepresentation(
RESQML2_0_1_NS::StructuralOrganizationInterpretation* interp,
const std::string & guid,
const std::string & title,
const bool & isSealed);
const std::string & title);

RESQML2_0_1_NS::SealedSurfaceFrameworkRepresentation* createSealedSurfaceFrameworkRepresentation(
RESQML2_0_1_NS::StructuralOrganizationInterpretation* interp,
Expand Down
5 changes: 2 additions & 3 deletions src/resqml2/AbstractRepresentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,12 @@ gsoap_resqml2_0_1::eml20__DataObjectReference* AbstractRepresentation::getLocalC
if (pointGeom != nullptr) {
return pointGeom->LocalCrs;
}
else {
return nullptr;
}
}
else {
throw logic_error("Not implemented yet");
}

return nullptr;
}

std::string AbstractRepresentation::getLocalCrsUuid() const
Expand Down
4 changes: 0 additions & 4 deletions src/resqml2/AbstractRepresentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ under the License.

#include "resqml2/AbstractProperty.h"

namespace COMMON_NS {
class AbstractHdfProxy;
}

namespace RESQML2_NS
{
class DLL_IMPORT_OR_EXPORT AbstractRepresentation : public COMMON_NS::AbstractObject
Expand Down
180 changes: 180 additions & 0 deletions src/resqml2_0_1/AbstractSurfaceFrameworkRepresentation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
/*-----------------------------------------------------------------------
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"; you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-----------------------------------------------------------------------*/
#include "resqml2_0_1/AbstractSurfaceFrameworkRepresentation.h"

#include <stdexcept>
#include <sstream>

#include "H5Tpublic.h"

#include "resqml2_0_1/StructuralOrganizationInterpretation.h"
#include "common/AbstractHdfProxy.h"

using namespace std;
using namespace RESQML2_0_1_NS;
using namespace gsoap_resqml2_0_1;
using namespace epc;

AbstractSurfaceFrameworkRepresentation::AbstractSurfaceFrameworkRepresentation(StructuralOrganizationInterpretation* interp):
RESQML2_NS::RepresentationSetRepresentation(interp)
{}

void AbstractSurfaceFrameworkRepresentation::pushBackContactIdentity(
gsoap_resqml2_0_1::resqml2__IdentityKind kind,
unsigned int sealedContactRepresentationsCount, int * sealedContactRepresentationsIndexes,
COMMON_NS::AbstractHdfProxy * proxy)
{
resqml2__AbstractSurfaceFrameworkRepresentation* orgRep = static_cast<resqml2__AbstractSurfaceFrameworkRepresentation*>(gsoapProxy2_0_1);

resqml2__ContactIdentity * contactIdentity = soap_new_resqml2__ContactIdentity(gsoapProxy2_0_1->soap, 1);
contactIdentity->IdentityKind = kind;

// ListOfContactRepresentations handling
resqml2__IntegerHdf5Array * xmlListOfContactRepresentations = soap_new_resqml2__IntegerHdf5Array(gsoapProxy2_0_1->soap, 1);
xmlListOfContactRepresentations->NullValue = (std::numeric_limits<unsigned int>::max)();
xmlListOfContactRepresentations->Values = soap_new_eml20__Hdf5Dataset(gsoapProxy2_0_1->soap, 1);
xmlListOfContactRepresentations->Values->HdfProxy = proxy->newResqmlReference();
ostringstream ossForHdfContactRepresentations;
ossForHdfContactRepresentations << "contactIdentity_listOfContactRep_" << orgRep->ContactIdentity.size();
xmlListOfContactRepresentations->Values->PathInHdfFile = "/RESQML/" + gsoapProxy2_0_1->uuid + "/" + ossForHdfContactRepresentations.str();
contactIdentity->ListOfContactRepresentations = xmlListOfContactRepresentations;
// ************ HDF *************
hsize_t dimContactRepresentations[1] = { sealedContactRepresentationsCount };
proxy->writeArrayNd(gsoapProxy2_0_1->uuid,
ossForHdfContactRepresentations.str(), H5T_NATIVE_UINT,
sealedContactRepresentationsIndexes,
dimContactRepresentations, 1);

orgRep->ContactIdentity.push_back(contactIdentity);
}

void AbstractSurfaceFrameworkRepresentation::pushBackContactIdentity(
gsoap_resqml2_0_1::resqml2__IdentityKind kind,
unsigned int sealedContactRepresentationsCount, int * sealedContactRepresentationsIndexes,
unsigned int identicalNodesCount, int * identicalNodesIndexes, COMMON_NS::AbstractHdfProxy * proxy)
{
resqml2__AbstractSurfaceFrameworkRepresentation* orgRep = static_cast<resqml2__AbstractSurfaceFrameworkRepresentation*>(gsoapProxy2_0_1);

resqml2__ContactIdentity * contactIdentity = soap_new_resqml2__ContactIdentity(gsoapProxy2_0_1->soap, 1);
contactIdentity->IdentityKind = kind;

// ListOfContactRepresentations handling
resqml2__IntegerHdf5Array * xmlListOfContactRepresentations = soap_new_resqml2__IntegerHdf5Array(gsoapProxy2_0_1->soap, 1);
xmlListOfContactRepresentations->NullValue = (std::numeric_limits<unsigned int>::max)();
xmlListOfContactRepresentations->Values = soap_new_eml20__Hdf5Dataset(gsoapProxy2_0_1->soap, 1);
xmlListOfContactRepresentations->Values->HdfProxy = proxy->newResqmlReference();
ostringstream ossForHdfContactRepresentations;
ossForHdfContactRepresentations << "contactIdentity_listOfContactRep_" << orgRep->ContactIdentity.size();
xmlListOfContactRepresentations->Values->PathInHdfFile = "/RESQML/" + gsoapProxy2_0_1->uuid + "/" + ossForHdfContactRepresentations.str();
contactIdentity->ListOfContactRepresentations = xmlListOfContactRepresentations;
// ************ HDF *************
hsize_t dimContactRepresentations[1] = { sealedContactRepresentationsCount };
proxy->writeArrayNd(gsoapProxy2_0_1->uuid,
ossForHdfContactRepresentations.str(), H5T_NATIVE_UINT,
sealedContactRepresentationsIndexes,
dimContactRepresentations, 1);

// ListOfIdenticalNodes handling
resqml2__IntegerHdf5Array * xmlListOfIdenticalNodes = soap_new_resqml2__IntegerHdf5Array(gsoapProxy2_0_1->soap, 1);
xmlListOfIdenticalNodes->NullValue = (std::numeric_limits<unsigned int>::max)();
xmlListOfIdenticalNodes->Values = soap_new_eml20__Hdf5Dataset(gsoapProxy2_0_1->soap, 1);
xmlListOfIdenticalNodes->Values->HdfProxy = proxy->newResqmlReference();
ostringstream ossForHdfIdenticalNodes;
ossForHdfIdenticalNodes << "contactIdentity_listOfIdenticalNodes_" << orgRep->ContactIdentity.size();
xmlListOfIdenticalNodes->Values->PathInHdfFile = "/RESQML/" + gsoapProxy2_0_1->uuid + "/" + ossForHdfIdenticalNodes.str();
contactIdentity->ListOfIdenticalNodes = xmlListOfIdenticalNodes;
// ************ HDF *************
hsize_t dimIdenticalNodes[2] = { identicalNodesCount, sealedContactRepresentationsCount };
proxy->writeArrayNd(gsoapProxy2_0_1->uuid,
ossForHdfIdenticalNodes.str(), H5T_NATIVE_UINT,
identicalNodesIndexes,
dimIdenticalNodes, 2);

orgRep->ContactIdentity.push_back(contactIdentity);
}

unsigned int AbstractSurfaceFrameworkRepresentation::getContactRepIdentityCount() const
{
resqml2__AbstractSurfaceFrameworkRepresentation* orgRep = static_cast<resqml2__AbstractSurfaceFrameworkRepresentation*>(gsoapProxy2_0_1);

if (orgRep->ContactIdentity.size() > (std::numeric_limits<unsigned int>::max)()) {
throw range_error("There are too much contact identities in this surface framework");
}

return static_cast<unsigned int>(orgRep->ContactIdentity.size());
}

gsoap_resqml2_0_1::resqml2__ContactIdentity* AbstractSurfaceFrameworkRepresentation::getContactIdentity(unsigned int ciIndex) const
{
resqml2__AbstractSurfaceFrameworkRepresentation* orgRep = static_cast<resqml2__AbstractSurfaceFrameworkRepresentation*>(gsoapProxy2_0_1);

if (ciIndex >= orgRep->ContactIdentity.size()) {
throw range_error("The index of the contact identity is out of range.");
}

return orgRep->ContactIdentity[ciIndex];
}

gsoap_resqml2_0_1::resqml2__IdentityKind AbstractSurfaceFrameworkRepresentation::getContactRepIdentityKind(unsigned int ciIndex) const
{
return getContactIdentity(ciIndex)->IdentityKind;
}

unsigned int AbstractSurfaceFrameworkRepresentation::getContactRepCountOfContactIdentity(unsigned int ciIndex) const
{
ULONG64 result = getCountOfIntegerArray(getContactIdentity(ciIndex)->ListOfContactRepresentations);
if (result > (std::numeric_limits<unsigned int>::max)()) {
throw range_error("There are too much contact representations for fesapi");
}

return static_cast<unsigned int>(result);
}

void AbstractSurfaceFrameworkRepresentation::getContactRepIndicesOfContactIdentity(unsigned int ciIndex, unsigned int * contactRepIndices) const
{
readArrayNdOfUIntValues(getContactIdentity(ciIndex)->ListOfContactRepresentations, contactRepIndices);
}

bool AbstractSurfaceFrameworkRepresentation::areAllContactRepNodesIdenticalInContactIdentity(unsigned int ciIndex) const
{
return getContactIdentity(ciIndex)->ListOfIdenticalNodes == nullptr;
}

unsigned int AbstractSurfaceFrameworkRepresentation::getIdenticalNodeCountOfContactIdentity(unsigned int ciIndex) const
{
if (areAllContactRepNodesIdenticalInContactIdentity(ciIndex)) {
throw invalid_argument("The nodes are all identical");
}

ULONG64 result = getCountOfIntegerArray(getContactIdentity(ciIndex)->ListOfIdenticalNodes);
if (result > (std::numeric_limits<unsigned int>::max)()) {
throw range_error("There are too much identical nodes for fesapi");
}

return static_cast<unsigned int>(result);
}

void AbstractSurfaceFrameworkRepresentation::getIdenticalNodeIndicesOfContactIdentity(unsigned int ciIndex, unsigned int * nodeIndices) const
{
if (areAllContactRepNodesIdenticalInContactIdentity(ciIndex)) {
throw invalid_argument("The nodes are all identical");
}

readArrayNdOfUIntValues(getContactIdentity(ciIndex)->ListOfIdenticalNodes, nodeIndices);
}

0 comments on commit 58156cc

Please sign in to comment.