You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AppFlow/FITK_Component/FITKGeoOCCIOHDF5/FITKOCCHDF5AdaptorBasicGeom...

374 lines
18 KiB
C++

#include "FITKOCCHDF5AdaptorCommand.h"
#include "FITKOCCShapeIO.h"
// OCC
#include <TopoDS_Shape.hxx>
//Component
#include "FITK_Component/FITKGeoCompOCC/FITKAbstractOCCModel.h"
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelSurface.h"
#include "FITKOCCHDF5AdaptorBasicGeometryFace.h"
namespace IO
{
// Reader.
//@{
QString FITKOCCHDF5AdaptorBasicGeometryFace::getAdaptorClass()
{
return "FITKOCCHDF5AdaptorBasicGeometryFace";
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometryFace(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
if (!comm) return false;
auto commType = comm->getGeometryCommandType();
switch (commType)
{
//Face
case Interface::FITKGeoEnum::FGTBridgeSurface: return readBasicGeometryBridgeSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTSurfaceFromSolid: return readBasicGeometrySolidSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTMultiSectionSurface: return readBasicGeometryMultiSectionSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTSweepSurface: return readBasicGeometrySweepSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTRevolSurface: return readBasicGeometryRevolSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTExtrudeSurface: return readBasicGeometryExtrudeSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTOffsetSurface: return readBasicGeometryOffsetSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTClosedWireSurface: return readBasicGeometryClosedWireSurface(comm, h5Group);
default:return false;
}
return false;
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometryFace(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
if (!comm) return false;
auto commType = comm->getGeometryCommandType();
switch (commType)
{
//Face
case Interface::FITKGeoEnum::FGTBridgeSurface: return writeBasicGeometryBridgeSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTSurfaceFromSolid: return writeBasicGeometrySolidSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTMultiSectionSurface: return writeBasicGeometryMultiSectionSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTSweepSurface: return writeBasicGeometrySweepSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTRevolSurface: return writeBasicGeometryRevolSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTExtrudeSurface: return writeBasicGeometryExtrudeSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTOffsetSurface: return writeBasicGeometryOffsetSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTClosedWireSurface: return writeBasicGeometryClosedWireSurface(comm, h5Group);
default:return false;
}
return false;
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometryFaceBase(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
return true;
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometryFaceBase(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
return true;
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometryClosedWireSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelClosedWireSurface* circleArc = dynamic_cast<Interface::FITKAbsGeoModelClosedWireSurface*>(comm);
if (!circleArc) return false;
int edgeArray[2];
auto edges = circleArc->edges();
int count = readIntAttribute(h5Group, "Count");
for (int i = 0; i < count; i++)
{
if (!readIntAttribute(h5Group, std::to_string(i), edgeArray, 1, 2)) return false;
Interface::VirtualShape vShape1;
vShape1.CmdId = edgeArray[0];
vShape1.VirtualTopoId = edgeArray[1];
circleArc->addEdge(vShape1);
}
return readBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometryClosedWireSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelClosedWireSurface* circleArc = dynamic_cast<Interface::FITKAbsGeoModelClosedWireSurface*>(comm);
if (!circleArc) return false;
auto edges = circleArc->edges();
int count = edges.count();
for (int i = 0; i < count; i++)
{
auto edge = edges[i];
int edgeArray[2]{ edge.CmdId ,edge.VirtualTopoId };
writeIntAttribute(h5Group, std::to_string(i), &edgeArray, 1, 2);
}
writeIntAttribute(h5Group, "Count", &count);
return writeBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometryOffsetSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelOffsetSurface* offsetSurface = dynamic_cast<Interface::FITKAbsGeoModelOffsetSurface*>(comm);
if (!offsetSurface) return false;
Interface::VirtualShape sourceSurface;
int sourceSurfaceArray[2];
if (!readIntAttribute(h5Group, "SourceSurface", sourceSurfaceArray, 1, 2)) return false;
sourceSurface.CmdId = sourceSurfaceArray[0];
sourceSurface.VirtualTopoId = sourceSurfaceArray[1];
offsetSurface->setSourceSurface(sourceSurface);
double offset = readDoubleAttribute(h5Group, "Offset");
offsetSurface->setOffset(offset);
return readBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometryOffsetSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelOffsetSurface* offsetSurface = dynamic_cast<Interface::FITKAbsGeoModelOffsetSurface*>(comm);
if (!offsetSurface) return false;
Interface::VirtualShape sourceSurface = offsetSurface->sourceSurface();
int sourceSurfaceArray[2]{ sourceSurface.CmdId ,sourceSurface.VirtualTopoId };
writeIntAttribute(h5Group, "SourceSurface", &sourceSurfaceArray, 1, 2);
double offset = offsetSurface->offset();
writeDoubleAttribute(h5Group, "Offset", &offset);
return writeBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometryExtrudeSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelExtrudeSurface* extrudeSurface = dynamic_cast<Interface::FITKAbsGeoModelExtrudeSurface*>(comm);
if (!extrudeSurface) return false;
int sourceCurveArray[2];
double directionArray[3];
if (!readIntAttribute(h5Group, "ExtrudeSurface", sourceCurveArray, 1, 2)) return false;
Interface::VirtualShape sourceCurve;
sourceCurve.CmdId = sourceCurveArray[0];
sourceCurve.VirtualTopoId = sourceCurveArray[1];
extrudeSurface->setSourceCurve(sourceCurve);
if (!readDoubleAttribute(h5Group, "Direction", directionArray, 1, 3)) return false;
extrudeSurface->setDirection(directionArray[0], directionArray[1], directionArray[2]);
double length = readDoubleAttribute(h5Group, "Length");
extrudeSurface->setLength(length);
return readBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometryExtrudeSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelExtrudeSurface* extrudeSurface = dynamic_cast<Interface::FITKAbsGeoModelExtrudeSurface*>(comm);
if (!extrudeSurface) return false;
Interface::VirtualShape sourceCurve = extrudeSurface->sourceCurve();
int sourceCurveArray[2]{ sourceCurve.CmdId ,sourceCurve.VirtualTopoId };
writeIntAttribute(h5Group, "ExtrudeSurface", &sourceCurveArray, 1, 2);
auto direction = extrudeSurface->direction();
double directionArray[3]{ direction[0],direction[1],direction[2] };
writeDoubleAttribute(h5Group, "Direction", directionArray, 1, 3);
double length = extrudeSurface->length();
writeDoubleAttribute(h5Group, "Length", &length);
return writeBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometryRevolSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelRevolSurface* revolSurface = dynamic_cast<Interface::FITKAbsGeoModelRevolSurface*>(comm);
if (!revolSurface) return false;
int sourceCurveArray[2];
if (!readIntAttribute(h5Group, "SourceCurve", sourceCurveArray, 1, 2)) return false;
Interface::VirtualShape sourceCurve;
sourceCurve.CmdId = sourceCurveArray[0];
sourceCurve.VirtualTopoId = sourceCurveArray[1];
revolSurface->setSourveCurve(sourceCurve);
double rotateAxisPoint1Array[3], rotateAxisPoint2Array[3];
if (!readDoubleAttribute(h5Group, "RotateAxisPoint1", rotateAxisPoint1Array, 1, 3)) return false;
revolSurface->setRotateAxisPoint1(rotateAxisPoint1Array[0], rotateAxisPoint1Array[1], rotateAxisPoint1Array[2]);
if (!readDoubleAttribute(h5Group, "RotateAxisPoint2", rotateAxisPoint2Array, 1, 3)) return false;
revolSurface->setRotateAxisPoint2(rotateAxisPoint2Array[0], rotateAxisPoint2Array[1], rotateAxisPoint2Array[2]);
int angle = readIntAttribute(h5Group, "Angle");
revolSurface->setAngle(angle);
return readBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometryRevolSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelRevolSurface* revolSurface = dynamic_cast<Interface::FITKAbsGeoModelRevolSurface*>(comm);
if (!revolSurface) return false;
Interface::VirtualShape sourceCurve = revolSurface->sourceCurve();
int sourceCurveArray[2]{ sourceCurve.CmdId ,sourceCurve.VirtualTopoId };
writeIntAttribute(h5Group, "SourceCurve", &sourceCurveArray, 1, 2);
auto rotateAxisPoint1 = revolSurface->rotateAxisPoint1();
double rotateAxisPoint1Array[3]{ rotateAxisPoint1[0],rotateAxisPoint1[1],rotateAxisPoint1[2] };
writeDoubleAttribute(h5Group, "RotateAxisPoint1", rotateAxisPoint1Array, 1, 3);
auto rotateAxisPoint2 = revolSurface->rotateAxisPoint2();
double rotateAxisPoint2Array[3]{ rotateAxisPoint2[0],rotateAxisPoint2[1],rotateAxisPoint2[2] };
writeDoubleAttribute(h5Group, "RotateAxisPoint2", rotateAxisPoint2Array, 1, 3);
int angle = revolSurface->angle();
writeIntAttribute(h5Group, "Angle", &angle);
return writeBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometryRectangularTrimmedSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
return false;
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometryRectangularTrimmedSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
return false;
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometrySweepSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelSweepSurface* sweepSurface = dynamic_cast<Interface::FITKAbsGeoModelSweepSurface*>(comm);
if (!sweepSurface) return false;
int profileArray[2], curveArray[2];
if (!readIntAttribute(h5Group, "Profile", profileArray, 1, 2)) return false;
Interface::VirtualShape profile;
profile.CmdId = profileArray[0];
profile.VirtualTopoId = profileArray[1];
sweepSurface->setProfile(profile);
if (!readIntAttribute(h5Group, "Curve", curveArray, 1, 2)) return false;
Interface::VirtualShape curve;
curve.CmdId = curveArray[0];
curve.VirtualTopoId = curveArray[1];
sweepSurface->setCurve(curve);
return readBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometrySweepSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelSweepSurface* sweepSurface = dynamic_cast<Interface::FITKAbsGeoModelSweepSurface*>(comm);
if (!sweepSurface) return false;
Interface::VirtualShape profile = sweepSurface->profile();
int profileArray[2]{ profile.CmdId ,profile.VirtualTopoId };
writeIntAttribute(h5Group, "Profile", &profileArray, 1, 2);
Interface::VirtualShape curve = sweepSurface->curve();
int curveArray[2]{ curve.CmdId ,curve.VirtualTopoId };
writeIntAttribute(h5Group, "Curve", &curveArray, 1, 2);
return writeBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometryMultiSectionSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelMultiSectionSurface* multiSectionSurface = dynamic_cast<Interface::FITKAbsGeoModelMultiSectionSurface*>(comm);
if (!multiSectionSurface) return false;
int count = readIntAttribute(h5Group, "Count");
for (int i = 0; i < count; i++)
{
int curveArray[2];
if (!readIntAttribute(h5Group, std::to_string(i), curveArray, 1, 2)) return false;
Interface::VirtualShape curve;
curve.CmdId = curveArray[0];
curve.VirtualTopoId = curveArray[1];
multiSectionSurface->addSection(curve);
}
return readBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometryMultiSectionSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelMultiSectionSurface* multiSectionSurface = dynamic_cast<Interface::FITKAbsGeoModelMultiSectionSurface*>(comm);
if (!multiSectionSurface) return false;
auto sections = multiSectionSurface->sections();
int count = sections.size();
for (int i = 0; i < count; i++)
{
auto section = sections[i];
int curveArray[2]{ section.CmdId ,section.VirtualTopoId };
writeIntAttribute(h5Group, std::to_string(i), &curveArray, 1, 2);
}
writeIntAttribute(h5Group, "Count", &count);
return writeBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometryBridgeSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelBridgeSurface* bridgeSurface = dynamic_cast<Interface::FITKAbsGeoModelBridgeSurface*>(comm);
if (!bridgeSurface) return false;
int sourceSurface1Array[2], sourceSurface2Array[2];
if (!readIntAttribute(h5Group, "SourceSurface1", sourceSurface1Array, 1, 2)) return false;
Interface::VirtualShape sourceSurface1;
sourceSurface1.CmdId = sourceSurface1Array[0];
sourceSurface1.VirtualTopoId = sourceSurface1Array[1];
bridgeSurface->setSourceSurface1(sourceSurface1);
int edgeVirtualTopoId1 = readIntAttribute(h5Group, "EdgeVirtualTopoId1");
bridgeSurface->setEdgeVirtualTopoId1(edgeVirtualTopoId1);
if (!readIntAttribute(h5Group, "SourceSurface2", sourceSurface2Array, 1, 2)) return false;
Interface::VirtualShape sourceSurface2;
sourceSurface2.CmdId = sourceSurface2Array[0];
sourceSurface2.VirtualTopoId = sourceSurface2Array[1];
bridgeSurface->setSourceSurface2(sourceSurface2);
int edgeVirtualTopoId2 = readIntAttribute(h5Group, "EdgeVirtualTopoId2");
bridgeSurface->setEdgeVirtualTopoId2(edgeVirtualTopoId2);
return readBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometryBridgeSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelBridgeSurface* bridgeSurface = dynamic_cast<Interface::FITKAbsGeoModelBridgeSurface*>(comm);
if (!bridgeSurface) return false;
Interface::VirtualShape sourceSurface1 = bridgeSurface->sourceSurface1();
int sourceSurface1Array[2]{ sourceSurface1.CmdId ,sourceSurface1.VirtualTopoId };
writeIntAttribute(h5Group, "SourceSurface1", &sourceSurface1Array, 1, 2);
int edgeVirtualTopoId1 = bridgeSurface->edgeVirtualTopoId1();
writeIntAttribute(h5Group, "EdgeVirtualTopoId1", &edgeVirtualTopoId1);
Interface::VirtualShape sourceSurface2 = bridgeSurface->sourceSurface2();
int sourceSurface2Array[2]{ sourceSurface2.CmdId ,sourceSurface2.VirtualTopoId };
writeIntAttribute(h5Group, "SourceSurface2", &sourceSurface2Array, 1, 2);
int edgeVirtualTopoId2 = bridgeSurface->edgeVirtualTopoId2();
writeIntAttribute(h5Group, "EdgeVirtualTopoId2", &edgeVirtualTopoId2);
return writeBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::readBasicGeometrySolidSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelSolidSurface* solidSurface = dynamic_cast<Interface::FITKAbsGeoModelSolidSurface*>(comm);
if (!solidSurface) return false;
int sourceSolidArray[2];
if (!readIntAttribute(h5Group, "SourceSolid", sourceSolidArray, 1, 2)) return false;
Interface::VirtualShape SourceSolid;
SourceSolid.CmdId = sourceSolidArray[0];
SourceSolid.VirtualTopoId = sourceSolidArray[1];
solidSurface->setSourceSolid(SourceSolid);
int faceVirtualTopoId = readIntAttribute(h5Group, "FaceVirtualTopoId");
solidSurface->setFaceVirtualTopoId(faceVirtualTopoId);
return readBasicGeometryFaceBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryFace::writeBasicGeometrySolidSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelSolidSurface* solidSurface = dynamic_cast<Interface::FITKAbsGeoModelSolidSurface*>(comm);
if (!solidSurface) return false;
Interface::VirtualShape sourceSolid = solidSurface->sourceSolid();
int sourceSolidArray[2]{ sourceSolid.CmdId ,sourceSolid.VirtualTopoId };
writeIntAttribute(h5Group, "SourceSolid", &sourceSolidArray, 1, 2);
int faceVirtualTopoId = solidSurface->faceVirtualTopoId();
writeIntAttribute(h5Group, "FaceVirtualTopoId", &faceVirtualTopoId);
return writeBasicGeometryFaceBase(comm, h5Group);
}
//@}
} // namespace IO