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...

330 lines
17 KiB
C++

#include "FITKOCCHDF5AdaptorCommand.h"
#include "FITKOCCShapeIO.h"
// OCC
#include <TopoDS_Shape.hxx>
//Component
#include "FITK_Component/FITKGeoCompOCC/FITKAbstractOCCModel.h"
#include "FITKOCCHDF5AdaptorBasicGeometryPoint.h"
//Geommtry
#include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelPoint.h"
namespace IO
{
// Reader.
//@{
QString FITKOCCHDF5AdaptorBasicGeometryPoint::getAdaptorClass()
{
return "FITKOCCHDF5AdaptorBasicGeometryPoint";
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::adaptR()
{
auto comm = dynamic_cast<Interface::FITKAbsGeoCommand*>(_dataObj);
if (!_reader || !comm || !_h5Group) return false;
return readBasicGeometry(comm, *_h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::adaptW()
{
auto comm = dynamic_cast<Interface::FITKAbsGeoCommand*>(_dataObj);
if (!_writer || !comm || !_h5Group) return false;
return writeBasicGeometry(comm, *_h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::readBasicGeometry(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
if (comm == nullptr) return false;
//获取命令类型
auto commType = comm->getGeometryCommandType();
if (commType == Interface::FITKGeoEnum::FITKGeometryComType::FGTNone) return false;
switch (commType)
{
case Interface::FITKGeoEnum::FGTPoint: return readBasicGeometryPointBase(comm, h5Group);
case Interface::FITKGeoEnum::FGTCurveEnd: return readBasicGeometryCurveEnd(comm, h5Group);
case Interface::FITKGeoEnum::FGTCurveEndDistance: return readBasicGeometryCurveEndDistance(comm, h5Group);
case Interface::FITKGeoEnum::FGTCurveRadio: return readBasicGeometryCurveRadio(comm, h5Group);
case Interface::FITKGeoEnum::FGTPointProjectionOnCurve: return readBasicGeometryProjectionOnCurve(comm, h5Group);
case Interface::FITKGeoEnum::FGTTwoCurveIntersectPoint: return readBasicGeometryTwoCurveIntersection(comm, h5Group);
case Interface::FITKGeoEnum::FGTPointProjectionOnSurface: return readBasicGeometryPointProjectionOnSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTCurveIntersectSurface: return readBasicGeometryCurveIntersectionSurface(comm, h5Group);
default: return false;
}
return true;
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::writeBasicGeometry(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
if (comm == nullptr) return false;
//获取命令类型
auto commType = comm->getGeometryCommandType();
if (commType == Interface::FITKGeoEnum::FITKGeometryComType::FGTNone) return false;
switch (commType)
{
case Interface::FITKGeoEnum::FGTPoint: return writeBasicGeometryPointBase(comm, h5Group);
case Interface::FITKGeoEnum::FGTCurveEnd: return writeBasicGeometryCurveEnd(comm, h5Group);
case Interface::FITKGeoEnum::FGTCurveEndDistance: return writeBasicGeometryCurveEndDistance(comm, h5Group);
case Interface::FITKGeoEnum::FGTCurveRadio: return writeBasicGeometryCurveRadio(comm, h5Group);
case Interface::FITKGeoEnum::FGTPointProjectionOnCurve: return writeBasicGeometryProjectionOnCurve(comm, h5Group);
case Interface::FITKGeoEnum::FGTTwoCurveIntersectPoint: return writeBasicGeometryTwoCurveIntersection(comm, h5Group);
case Interface::FITKGeoEnum::FGTPointProjectionOnSurface: return writeBasicGeometryPointProjectionOnSurface(comm, h5Group);
case Interface::FITKGeoEnum::FGTCurveIntersectSurface: return writeBasicGeometryCurveIntersectionSurface(comm, h5Group);
default: return false;
}
return true;
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::readBasicGeometryPointBase(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelPoint* point = dynamic_cast<Interface::FITKAbsGeoModelPoint*>(comm);
if (point == nullptr) return false;
QList<double> xyz;
if (!readDoubleAttrbuteDataSet(h5Group, "Point", xyz, 1, 3)) return false;
point->setCoord(xyz[0], xyz[1], xyz[2]);
return true;
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::writeBasicGeometryPointBase(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelPoint* point = dynamic_cast<Interface::FITKAbsGeoModelPoint*>(comm);
if (point == nullptr) return false;
double p[3]{ point->x(),point->y(), point->z() };
writeDoubleAttribute(h5Group, "Point", &p, 1, 3);
return true;
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::readBasicGeometryCurveEnd(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelCurveEnd* curveEnd = dynamic_cast<Interface::FITKAbsGeoModelCurveEnd*>(comm);
if (!curveEnd) return false;
int sourceCurveArray[2];
if (!readIntAttribute(h5Group, "SourceCurve", sourceCurveArray, 1, 2)) return false;
Interface::VirtualShape vShape;
vShape.CmdId = sourceCurveArray[0];
vShape.VirtualTopoId = sourceCurveArray[1];
curveEnd->setSourceCurve(vShape);
bool useStartEnd = readBoolAttribute(h5Group, "UseStartEnd");
curveEnd->setUseStartEnd(useStartEnd);
return readBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::writeBasicGeometryCurveEnd(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelCurveEnd* curveEnd = dynamic_cast<Interface::FITKAbsGeoModelCurveEnd*>(comm);
if (!curveEnd) return false;
auto sourceCurve = curveEnd->sourceCurve();
int sourceCurveArray[2]{ sourceCurve.CmdId,sourceCurve.VirtualTopoId };
writeIntAttribute(h5Group, "SourceCurve", &sourceCurveArray, 1, 2);
bool useStartEnd = curveEnd->useStartEnd();
writeBoolAttribute(h5Group, "UseStartEnd", &useStartEnd);
return writeBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::readBasicGeometryCurveEndDistance(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelCurveEndDistance* curveEnd = dynamic_cast<Interface::FITKAbsGeoModelCurveEndDistance*>(comm);
if (!curveEnd) return false;
int sourceCurveArray[2];
if (!readIntAttribute(h5Group, "SourceCurve", sourceCurveArray, 1, 2)) return false;
Interface::VirtualShape vShape;
vShape.CmdId = sourceCurveArray[0];
vShape.VirtualTopoId = sourceCurveArray[1];
curveEnd->setSourceCurve(vShape);
bool useStartEnd = readBoolAttribute(h5Group, "UseStartEnd");
curveEnd->setUseStartEnd(useStartEnd);
double distance = readDoubleAttribute(h5Group, "Distance");
curveEnd->setDistance(distance);
return readBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::writeBasicGeometryCurveEndDistance(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelCurveEndDistance* curveEnd = dynamic_cast<Interface::FITKAbsGeoModelCurveEndDistance*>(comm);
if (!curveEnd) return false;
auto sourceCurve = curveEnd->sourceCurve();
int sourceCurveArray[2]{ sourceCurve.CmdId,sourceCurve.VirtualTopoId };
writeIntAttribute(h5Group, "SourceCurve", &sourceCurveArray, 1, 2);
bool useStartEnd = curveEnd->useStartEnd();
writeBoolAttribute(h5Group, "UseStartEnd", &useStartEnd);
double distance = curveEnd->distance();
writeDoubleAttribute(h5Group, "Distance", &distance);
return writeBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::readBasicGeometryCurveRadio(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelCurveRadio* curveRadio = dynamic_cast<Interface::FITKAbsGeoModelCurveRadio*>(comm);
if (!curveRadio) return false;
int sourceCurveArray[2];
if (!readIntAttribute(h5Group, "SourceCurve", sourceCurveArray, 1, 2)) return false;
Interface::VirtualShape vShape;
vShape.CmdId = sourceCurveArray[0];
vShape.VirtualTopoId = sourceCurveArray[1];
curveRadio->setSourceCurve(vShape);
double radio = readDoubleAttribute(h5Group, "Radio");
curveRadio->setRadio(radio);
return readBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::writeBasicGeometryCurveRadio(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelCurveRadio* curveRadio = dynamic_cast<Interface::FITKAbsGeoModelCurveRadio*>(comm);
if (!curveRadio) return false;
auto sourceCurve = curveRadio->sourceCurve();
int sourceCurveArray[2]{ sourceCurve.CmdId,sourceCurve.VirtualTopoId };
writeIntAttribute(h5Group, "SourceCurve", &sourceCurveArray, 1, 2);
double radio = curveRadio->radio();
writeDoubleAttribute(h5Group, "Radio", &radio);
return writeBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::readBasicGeometryProjectionOnCurve(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelPointProjectionOnCurve* projectionOnCurve = dynamic_cast<Interface::FITKAbsGeoModelPointProjectionOnCurve*>(comm);
if (!projectionOnCurve) return false;
int sourcePointArray[2], sourceCurveArray[2];
if (!readIntAttribute(h5Group, "SourceCurve", sourcePointArray, 1, 2)) return false;
Interface::VirtualShape vShapePoint;
vShapePoint.CmdId = sourcePointArray[0];
vShapePoint.VirtualTopoId = sourcePointArray[1];
projectionOnCurve->setSourcePoint(vShapePoint);
if (!readIntAttribute(h5Group, "SourceCurve", sourceCurveArray, 1, 2)) return false;
Interface::VirtualShape vShapeCurve;
vShapeCurve.CmdId = sourceCurveArray[0];
vShapeCurve.VirtualTopoId = sourceCurveArray[1];
projectionOnCurve->setSourceCurve(vShapeCurve);
return readBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::writeBasicGeometryProjectionOnCurve(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelPointProjectionOnCurve* projectionOnCurve = dynamic_cast<Interface::FITKAbsGeoModelPointProjectionOnCurve*>(comm);
if (!projectionOnCurve) return false;
auto sourcePoint = projectionOnCurve->sourcePoint();
int sourcePointArray[2]{ sourcePoint.CmdId,sourcePoint.VirtualTopoId };
writeIntAttribute(h5Group, "sourcePoint", &sourcePointArray, 1, 2);
auto sourceCurve = projectionOnCurve->sourceCurve();
int sourceCurveArray[2]{ sourceCurve.CmdId,sourceCurve.VirtualTopoId };
writeIntAttribute(h5Group, "SourceCurve", &sourceCurveArray, 1, 2);
return writeBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::readBasicGeometryTwoCurveIntersection(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelTwoCurveIntersection* twoCurveIntersection = dynamic_cast<Interface::FITKAbsGeoModelTwoCurveIntersection*>(comm);
if (!twoCurveIntersection) return false;
int sourceCurve1Array[2], sourceCurve2Array[2];
if (!readIntAttribute(h5Group, "SourceCurve1", sourceCurve1Array, 1, 2)) return false;
Interface::VirtualShape sourceCurve1;
sourceCurve1.CmdId = sourceCurve1Array[0];
sourceCurve1.VirtualTopoId = sourceCurve1Array[1];
if (!readIntAttribute(h5Group, "SourceCurve2", sourceCurve2Array, 1, 2)) return false;
Interface::VirtualShape sourceCurve2;
sourceCurve2.CmdId = sourceCurve2Array[0];
sourceCurve2.VirtualTopoId = sourceCurve2Array[1];
twoCurveIntersection->setSourceCurve(sourceCurve1, sourceCurve2);
//不需要处理交点
//int count = readIntAttribute(h5Group, "Count");
//double pArray[3];
//for (int i = 0; i < count; i++)
//{
// if (!readDoubleAttribute(h5Group, std::to_string(i), pArray, 1, 3)) return false;
//
//}
return readBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::writeBasicGeometryTwoCurveIntersection(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelTwoCurveIntersection* twoCurveIntersection = dynamic_cast<Interface::FITKAbsGeoModelTwoCurveIntersection*>(comm);
if (!twoCurveIntersection) return false;
auto sourceCurve1 = twoCurveIntersection->sourceCurve1();
int sourceCurve1Array[2]{ sourceCurve1.CmdId,sourceCurve1.VirtualTopoId };
writeIntAttribute(h5Group, "SourceCurve1", &sourceCurve1Array, 1, 2);
auto sourceCurve2 = twoCurveIntersection->sourceCurve2();
int sourceCurve2Array[2]{ sourceCurve2.CmdId,sourceCurve2.VirtualTopoId };
writeIntAttribute(h5Group, "SourceCurve2", &sourceCurve2Array, 1, 2);
auto points = twoCurveIntersection->getResultPoints();
int count = points.size();
writeIntAttribute(h5Group, "Count", &count);
for (int i = 0; i < count; i++)
{
auto point = points[i];
double pArray[3]{ point[0], point[1], point[2] };
writeDoubleAttribute(h5Group, std::to_string(i), &pArray, 1, 3);
}
return writeBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::readBasicGeometryPointProjectionOnSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelPointProjectionOnSurface* ppOnSurface = dynamic_cast<Interface::FITKAbsGeoModelPointProjectionOnSurface*>(comm);
if (!ppOnSurface) return false;
int sourcePointArray[2], sourceSurfaceArray[2];
if (!readIntAttribute(h5Group, "SourcePoint", sourcePointArray, 1, 2)) return false;
Interface::VirtualShape sourcePoint;
sourcePoint.CmdId = sourcePointArray[0];
sourcePoint.VirtualTopoId = sourcePointArray[1];
ppOnSurface->setSourcePoint(sourcePoint);
if (!readIntAttribute(h5Group, "SourceSurface", sourceSurfaceArray, 1, 2)) return false;
Interface::VirtualShape sourceSurface;
sourceSurface.CmdId = sourceSurfaceArray[0];
sourceSurface.VirtualTopoId = sourceSurfaceArray[1];
ppOnSurface->setSourceSurface(sourceSurface);
return readBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::writeBasicGeometryPointProjectionOnSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelPointProjectionOnSurface* ppOnSurface = dynamic_cast<Interface::FITKAbsGeoModelPointProjectionOnSurface*>(comm);
if (!ppOnSurface) return false;
auto sourcePoint = ppOnSurface->sourcePoint();
int sourcePointArray[2]{ sourcePoint.CmdId,sourcePoint.VirtualTopoId };
writeIntAttribute(h5Group, "SourcePoint", &sourcePointArray, 1, 2);
auto sourceSurface = ppOnSurface->sourceSurface();
int sourceSurfaceArray[2]{ sourceSurface.CmdId,sourceSurface.VirtualTopoId };
writeIntAttribute(h5Group, "SourceSurface", &sourceSurface, 1, 2);
return writeBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::readBasicGeometryCurveIntersectionSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelCurveIntersectionSurface* cIntersectionSurface = dynamic_cast<Interface::FITKAbsGeoModelCurveIntersectionSurface*>(comm);
if (!cIntersectionSurface) return false;
int sourceCurveArray[2], sourceSurfaceArray[2];
if (!readIntAttribute(h5Group, "SourceCurve", sourceCurveArray, 1, 2)) return false;
Interface::VirtualShape sourceCurve;
sourceCurve.CmdId = sourceCurveArray[0];
sourceCurve.VirtualTopoId = sourceCurveArray[1];
cIntersectionSurface->setSourceCurve(sourceCurve);
if (!readIntAttribute(h5Group, "SourceSurface", sourceSurfaceArray, 1, 2)) return false;
Interface::VirtualShape sourceSurface;
sourceSurface.CmdId = sourceSurfaceArray[0];
sourceSurface.VirtualTopoId = sourceSurfaceArray[1];
cIntersectionSurface->setSourceSurface(sourceSurface);
return readBasicGeometryPointBase(comm, h5Group);
}
bool FITKOCCHDF5AdaptorBasicGeometryPoint::writeBasicGeometryCurveIntersectionSurface(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group)
{
Interface::FITKAbsGeoModelCurveIntersectionSurface* cIntersectionSurface = dynamic_cast<Interface::FITKAbsGeoModelCurveIntersectionSurface*>(comm);
if (!cIntersectionSurface) return false;
auto sourceCurve = cIntersectionSurface->sourceCurve();
int sourceCurveArray[2]{ sourceCurve.CmdId,sourceCurve.VirtualTopoId };
writeIntAttribute(h5Group, "SourceCurve", &sourceCurveArray, 1, 2);
auto sourceSurface = cIntersectionSurface->sourceSurface();
int sourceSurfaceArray[2]{ sourceSurface.CmdId,sourceSurface.VirtualTopoId };
writeIntAttribute(h5Group, "SourceSurface", &sourceSurface, 1, 2);
return writeBasicGeometryPointBase(comm, h5Group);
}
//@}
} // namespace IO