#include "FITKOCCHDF5AdaptorCommand.h" #include "FITKOCCShapeIO.h" // OCC #include //Geommtry #include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoDelete.h" #include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoOperBool.h" #include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelOperImprintSolid.h" #include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelImport.h" #include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelExport.h" #include "FITK_Interface/FITKInterfaceGeometry/FITKAbsGeoModelOperCompound.h" //Component #include "FITK_Component/FITKGeoCompOCC/FITKAbstractOCCModel.h" #include "FITKOCCHDF5AdaptorOperGeometry.h" namespace IO { // Reader. //@{ QString FITKOCCHDF5AdaptorOperGeometry::getAdaptorClass() { return "FITKOCCHDF5AdaptorOperGeometry"; } bool FITKOCCHDF5AdaptorOperGeometry::adaptR() { auto comm = dynamic_cast(_dataObj); if (!_reader || !comm || !_h5Group) return false; return readOperGeometry(comm, *_h5Group); } bool FITKOCCHDF5AdaptorOperGeometry::adaptW() { auto comm = dynamic_cast(_dataObj); if (!_writer || !comm || !_h5Group) return false; return writeOperGeometry(comm, *_h5Group); } bool FITKOCCHDF5AdaptorOperGeometry::readOperGeometry(Interface::FITKAbsGeoCommand* comm, H5::Group& h5Group) { if (comm == nullptr) return false; //获取命令类型 auto commType = comm->getGeometryCommandType(); switch (commType) { case Interface::FITKGeoEnum::FITKGeometryComType::FGTDelete: return readOperGeometryDelete(comm, h5Group); case Interface::FITKGeoEnum::FITKGeometryComType::FGTBool: return readOperGeometryBool(comm, h5Group); case Interface::FITKGeoEnum::FITKGeometryComType::FGTImprintSolid: return readOperGeometryOperImprintSolid(comm, h5Group); case Interface::FITKGeoEnum::FITKGeometryComType::FGTImport: return readOperGeometryOperImport(comm, h5Group); case Interface::FITKGeoEnum::FITKGeometryComType::FGTExport: return readOperGeometryOperExport(comm, h5Group); case Interface::FITKGeoEnum::FITKGeometryComType::FGTCompoundAppendShape: case Interface::FITKGeoEnum::FITKGeometryComType::FGTCompoundRemoveShape: return readOperGeometryOperCompoundBase(comm, h5Group); default: return false; } return true; } bool FITKOCCHDF5AdaptorOperGeometry::writeOperGeometry(Interface::FITKAbsGeoCommand* comm, H5::Group& h5Group) { if (comm == nullptr) return false; //获取命令类型 auto commType = comm->getGeometryCommandType(); switch (commType) { case Interface::FITKGeoEnum::FITKGeometryComType::FGTDelete: return writeOperGeometryDelete(comm, h5Group); case Interface::FITKGeoEnum::FITKGeometryComType::FGTBool: return writeOperGeometryBool(comm, h5Group); case Interface::FITKGeoEnum::FITKGeometryComType::FGTImprintSolid: return writeOperGeometryOperImprintSolid(comm, h5Group); case Interface::FITKGeoEnum::FITKGeometryComType::FGTImport: return writeOperGeometryOperImport(comm, h5Group); case Interface::FITKGeoEnum::FITKGeometryComType::FGTExport: return writeOperGeometryOperExport(comm, h5Group); case Interface::FITKGeoEnum::FITKGeometryComType::FGTCompoundAppendShape: case Interface::FITKGeoEnum::FITKGeometryComType::FGTCompoundRemoveShape: return writeOperGeometryOperCompoundBase(comm, h5Group); default: return false; } return true; } bool FITKOCCHDF5AdaptorOperGeometry::readOperGeometryDelete(Interface::FITKAbsGeoCommand* comm, H5::Group& h5Group) { Interface::FITKAbsGeoDelete* geoDelete = dynamic_cast(comm); if (!geoDelete) return false; int deleteCommandID = readIntAttribute(h5Group, "DeleteCommandID"); geoDelete->setDeleteCommandID(deleteCommandID); return true; } bool FITKOCCHDF5AdaptorOperGeometry::writeOperGeometryDelete(Interface::FITKAbsGeoCommand* comm, H5::Group& h5Group) { Interface::FITKAbsGeoDelete* geoDelete = dynamic_cast(comm); if (!geoDelete) return false; int deleteCommandID = geoDelete->getDeleteCommandID(); writeIntAttribute(h5Group, "DeleteCommandID", &deleteCommandID); return true; } bool FITKOCCHDF5AdaptorOperGeometry::readOperGeometryBool(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group) { Interface::FITKAbsGeoOperBool* operBool = dynamic_cast(comm); if (!operBool) return false; int t = readIntAttribute(h5Group, "Type"); operBool->setBoolOperType((Interface::FITKAbsGeoOperBool::GeoBoolOperType)t); int targetArray[2], toolArray[2]; if (!readIntAttribute(h5Group, "Target", targetArray, 1, 2)) return false; Interface::VirtualShape vShapeTarget; vShapeTarget.CmdId = targetArray[0]; vShapeTarget.VirtualTopoId = targetArray[1]; operBool->setTarget(vShapeTarget); if (!readIntAttribute(h5Group, "ToolArray", toolArray, 1, 2)) return false; Interface::VirtualShape vShapeTool; vShapeTool.CmdId = targetArray[0]; vShapeTool.VirtualTopoId = targetArray[1]; operBool->setTool(vShapeTool); return true; } bool FITKOCCHDF5AdaptorOperGeometry::writeOperGeometryBool(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group) { Interface::FITKAbsGeoOperBool* operBool = dynamic_cast(comm); if (!operBool) return false; int t = (int)operBool->getBoolOperType(); writeIntAttribute(h5Group, "Type", &t); auto target = operBool->target(); int targetArray[2]{ target.CmdId ,target.VirtualTopoId }; writeIntAttribute(h5Group, "Target", &targetArray, 1, 2); auto tool = operBool->tool(); int toolArray[2]{ tool.CmdId ,tool.VirtualTopoId }; writeIntAttribute(h5Group, "ToolArray", &toolArray, 1, 2); return true; } bool FITKOCCHDF5AdaptorOperGeometry::readOperGeometryOperImprintSolid(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group) { Interface::FITKAbsGeoModelOperImprintSolid* operImprintSolid = dynamic_cast(comm); if (!operImprintSolid) return false; int type = readIntAttribute(h5Group, "Type"); operImprintSolid->setType((Interface::FITKAbsGeoModelOperImprintSolid::GeoSolidOperType)type); double tolerance = readDoubleAttribute(h5Group, "Tolerance"); operImprintSolid->setTolerance(tolerance); int count = readIntAttribute(h5Group, "Count"); int sourceSurfaceArray[2]; for (int i = 0; i < count; i++) { if (!readIntAttribute(h5Group, std::to_string(i), sourceSurfaceArray, 1, 2)) return false; Interface::VirtualShape* vShape = new Interface::VirtualShape; vShape->CmdId = sourceSurfaceArray[0]; vShape->VirtualTopoId = sourceSurfaceArray[1]; operImprintSolid->add(vShape); } return true; } bool FITKOCCHDF5AdaptorOperGeometry::writeOperGeometryOperImprintSolid(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group) { Interface::FITKAbsGeoModelOperImprintSolid* operImprintSolid = dynamic_cast(comm); if (!operImprintSolid) return false; int type = operImprintSolid->getType(); writeIntAttribute(h5Group, "Type", &type); double tolerance = operImprintSolid->getTolerance(); writeDoubleAttribute(h5Group, "Tolerance", &tolerance); auto shapes = operImprintSolid->getVShapes(); int count = shapes.size(); writeIntAttribute(h5Group, "Count", &count); for (int i = 0; i < count; i++) { int vShape[2]{ shapes[i]->CmdId, shapes[i]->VirtualTopoId }; writeIntAttribute(h5Group, std::to_string(i), &vShape, 1, 2); } return true; } bool FITKOCCHDF5AdaptorOperGeometry::readOperGeometryOperImport(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group) { Interface::FITKAbsGeoModelImport* gImport = dynamic_cast(comm); if (!gImport) return false; std::string fileName = readStrAttribute(h5Group, "FileName"); gImport->setFileName(QString::fromStdString(fileName)); return true; } bool FITKOCCHDF5AdaptorOperGeometry::writeOperGeometryOperImport(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group) { Interface::FITKAbsGeoModelImport* gImport = dynamic_cast(comm); if (!gImport) return false; QString fileName = gImport->getFileName(); writeStrAttribute(h5Group, "FileName", fileName.toStdString()); return true; } bool FITKOCCHDF5AdaptorOperGeometry::readOperGeometryOperExport(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group) { Interface::FITKAbsGeoModelExport* gExport = dynamic_cast(comm); if (!gExport) return false; std::string fileName = readStrAttribute(h5Group, "FileName"); gExport->setFileName(QString::fromStdString(fileName)); return true; } bool FITKOCCHDF5AdaptorOperGeometry::writeOperGeometryOperExport(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group) { Interface::FITKAbsGeoModelExport* gExport = dynamic_cast(comm); if (!gExport) return false; QString fileName = gExport->getFileName(); writeStrAttribute(h5Group, "FileName", fileName.toStdString()); return true; } bool FITKOCCHDF5AdaptorOperGeometry::readOperGeometryOperCompoundBase(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group) { Interface::FITKAbsGeoModelOperCompound* operCompound = dynamic_cast(comm); if (!operCompound) return false; int inputCmdArray[2], childCmdArray[2]; if (!readIntAttribute(h5Group, "InputCmd", inputCmdArray, 1, 3)) return false; Interface::VirtualShape* vShape = new Interface::VirtualShape; vShape->CmdId = inputCmdArray[0]; vShape->VirtualTopoId = inputCmdArray[1]; operCompound->setInputCmdId(vShape); int count = readIntAttribute(h5Group, "Count"); QList vShapeChildList; for (int i = 0; i < count; i++) { if (!readIntAttribute(h5Group, std::to_string(i), childCmdArray, 1, 3)) return false; Interface::VirtualShape* vShapeChild = new Interface::VirtualShape; vShapeChild->CmdId = childCmdArray[0]; vShapeChild->VirtualTopoId = childCmdArray[1]; vShapeChildList.append(vShapeChild); } operCompound->setShapeCmdIds(vShapeChildList); return true; } bool FITKOCCHDF5AdaptorOperGeometry::writeOperGeometryOperCompoundBase(Interface::FITKAbsGeoCommand * comm, H5::Group & h5Group) { Interface::FITKAbsGeoModelOperCompound* operCompound = dynamic_cast(comm); if (!operCompound) return false; Interface::VirtualShape* vShape = operCompound->getInputCmdId(); int inputCmdArray[2]{ vShape->CmdId,vShape->VirtualTopoId }; writeIntAttribute(h5Group, "InputCmd", inputCmdArray, 1, 3); auto cmdIDs = operCompound->getShapeCmdIds(); int count = cmdIDs.size(); writeIntAttribute(h5Group, "Count", &count); for (int i = 0; i < count; i++) { auto cmdID = cmdIDs[i]; int cmdIDArray[2]{ cmdID->CmdId, cmdID->VirtualTopoId }; writeIntAttribute(h5Group, std::to_string(i), inputCmdArray, 1, 3); } return true; } //@} } // namespace IO