|  | @@ -0,0 +1,155 @@
 | 
	
		
			
				|  |  | +package com.miniframe.mdo.service.processor.impl;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.miniframe.mdo.entity.*;
 | 
	
		
			
				|  |  | +import com.miniframe.mdo.service.processor.FileProcessor;
 | 
	
		
			
				|  |  | +import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import java.io.BufferedReader;
 | 
	
		
			
				|  |  | +import java.io.FileReader;
 | 
	
		
			
				|  |  | +import java.util.*;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +@Service
 | 
	
		
			
				|  |  | +public class BdfFileProcessor implements FileProcessor {
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Map<String, Object> processFile(String filePath) throws Exception {
 | 
	
		
			
				|  |  | +        Map<String, Object> result = new HashMap<>();
 | 
	
		
			
				|  |  | +        List<BdfGrid> grids = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<BdfConm2> conm2s = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<BdfRbe3> rbe3s = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<BdfCquad4> cquad4s = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<BdfCquadr> cquadrs = new ArrayList<>();
 | 
	
		
			
				|  |  | +        List<BdfMaterial> materials = new ArrayList<>();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
 | 
	
		
			
				|  |  | +            String line;
 | 
	
		
			
				|  |  | +            while ((line = reader.readLine()) != null) {
 | 
	
		
			
				|  |  | +                line = line.trim();
 | 
	
		
			
				|  |  | +                if (line.startsWith("GRID")) {
 | 
	
		
			
				|  |  | +                    // 读取下一行
 | 
	
		
			
				|  |  | +                    String nextLine = reader.readLine();
 | 
	
		
			
				|  |  | +                    if (nextLine != null) {
 | 
	
		
			
				|  |  | +                        grids.add(parseGrid(line, nextLine));
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                } else if (line.startsWith("CONM2")) {
 | 
	
		
			
				|  |  | +                    conm2s.add(parseConm2(line));
 | 
	
		
			
				|  |  | +                } else if (line.startsWith("RBE3")) {
 | 
	
		
			
				|  |  | +                    rbe3s.add(parseRbe3(line));
 | 
	
		
			
				|  |  | +                } else if (line.startsWith("CQUAD4")) {
 | 
	
		
			
				|  |  | +                    cquad4s.add(parseCquad4(line));
 | 
	
		
			
				|  |  | +                } else if (line.startsWith("CQUADR")) {
 | 
	
		
			
				|  |  | +                    cquadrs.add(parseCquadr(line));
 | 
	
		
			
				|  |  | +                } else if (line.startsWith("MAT1")) {
 | 
	
		
			
				|  |  | +                    materials.add(parseMaterial(line));
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        result.put("grids", grids);
 | 
	
		
			
				|  |  | +        result.put("conm2s", conm2s);
 | 
	
		
			
				|  |  | +        result.put("rbe3s", rbe3s);
 | 
	
		
			
				|  |  | +        result.put("cquad4s", cquad4s);
 | 
	
		
			
				|  |  | +        result.put("cquadrs", cquadrs);
 | 
	
		
			
				|  |  | +        result.put("materials", materials);
 | 
	
		
			
				|  |  | +        result.put("datasetType", "bdf");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return result;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static BdfGrid parseGrid(String line1, String line2) {
 | 
	
		
			
				|  |  | +        // 解析第一行
 | 
	
		
			
				|  |  | +        String[] part1 = line1.split("\\s+");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 检查part1数组的长度
 | 
	
		
			
				|  |  | +        if (part1.length < 6) {
 | 
	
		
			
				|  |  | +            throw new IllegalArgumentException("Invalid GRID format: " + line1);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        int id = Integer.parseInt(part1[1]); // 第2个字段是ID
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        double x = Double.parseDouble(part1[3]); // 第4个字段是X坐标
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 解析Y坐标,去掉末尾的*字符
 | 
	
		
			
				|  |  | +        String yStr = part1[4];
 | 
	
		
			
				|  |  | +        if (yStr.endsWith("*")) {
 | 
	
		
			
				|  |  | +            yStr = yStr.substring(0, yStr.length() - 1); // 去掉最后一个字符
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        double y = Double.parseDouble(yStr); // 第5个字段是Y坐标
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 解析第二行
 | 
	
		
			
				|  |  | +        String[] part2 = line2.split("\\s+");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 检查part2数组的长度
 | 
	
		
			
				|  |  | +        if (part2.length < 3) {
 | 
	
		
			
				|  |  | +            throw new IllegalArgumentException("Invalid GRID continuation format: " + line2);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        double z = Double.parseDouble(part2[2]); // 第3个字段是Z坐标
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 创建Grid对象
 | 
	
		
			
				|  |  | +        BdfGrid grid = new BdfGrid();
 | 
	
		
			
				|  |  | +        grid.setId(id);
 | 
	
		
			
				|  |  | +        grid.setX(x);
 | 
	
		
			
				|  |  | +        grid.setY(y);
 | 
	
		
			
				|  |  | +        grid.setZ(z);
 | 
	
		
			
				|  |  | +        return grid;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static BdfConm2 parseConm2(String line) {
 | 
	
		
			
				|  |  | +        String[] parts = line.split("\\s+");
 | 
	
		
			
				|  |  | +        BdfConm2 conm2 = new BdfConm2();
 | 
	
		
			
				|  |  | +        conm2.setId(Integer.parseInt(parts[1]));
 | 
	
		
			
				|  |  | +        conm2.setNodeId(Integer.parseInt(parts[2]));
 | 
	
		
			
				|  |  | +        conm2.setMass(Double.parseDouble(parts[4]));
 | 
	
		
			
				|  |  | +        return conm2;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static BdfRbe3 parseRbe3(String line) {
 | 
	
		
			
				|  |  | +        String[] parts = line.split("\\s+");
 | 
	
		
			
				|  |  | +        BdfRbe3 rbe3 = new BdfRbe3();
 | 
	
		
			
				|  |  | +        rbe3.setId(Integer.parseInt(parts[1]));
 | 
	
		
			
				|  |  | +        rbe3.setMasterNodeId(Integer.parseInt(parts[2]));
 | 
	
		
			
				|  |  | +        rbe3.setDegreesOfFreedom(parts[3]);
 | 
	
		
			
				|  |  | +        List<Integer> slaveNodeIds = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (int i = 4; i < parts.length; i++) {
 | 
	
		
			
				|  |  | +            slaveNodeIds.add(Integer.parseInt(parts[i]));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        rbe3.setSlaveNodeIds(slaveNodeIds);
 | 
	
		
			
				|  |  | +        return rbe3;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static BdfCquad4 parseCquad4(String line) {
 | 
	
		
			
				|  |  | +        String[] parts = line.split("\\s+");
 | 
	
		
			
				|  |  | +        BdfCquad4 cquad4 = new BdfCquad4();
 | 
	
		
			
				|  |  | +        cquad4.setId(Integer.parseInt(parts[1]));
 | 
	
		
			
				|  |  | +        cquad4.setMaterialId(Integer.parseInt(parts[2]));
 | 
	
		
			
				|  |  | +        List<Integer> nodeIds = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (int i = 3; i < parts.length; i++) {
 | 
	
		
			
				|  |  | +            nodeIds.add(Integer.parseInt(parts[i]));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        cquad4.setNodeIds(nodeIds);
 | 
	
		
			
				|  |  | +        return cquad4;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static BdfCquadr parseCquadr(String line) {
 | 
	
		
			
				|  |  | +        String[] parts = line.split("\\s+");
 | 
	
		
			
				|  |  | +        BdfCquadr cquadr = new BdfCquadr();
 | 
	
		
			
				|  |  | +        cquadr.setId(Integer.parseInt(parts[1]));
 | 
	
		
			
				|  |  | +        cquadr.setPropertyId(Integer.parseInt(parts[2]));
 | 
	
		
			
				|  |  | +        List<Integer> nodeIds = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (int i = 3; i < parts.length; i++) {
 | 
	
		
			
				|  |  | +            nodeIds.add(Integer.parseInt(parts[i]));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        cquadr.setNodeIds(nodeIds);
 | 
	
		
			
				|  |  | +        return cquadr;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static BdfMaterial parseMaterial(String line) {
 | 
	
		
			
				|  |  | +        String[] parts = line.split("\\s+");
 | 
	
		
			
				|  |  | +        BdfMaterial material = new BdfMaterial();
 | 
	
		
			
				|  |  | +        material.setId(Integer.parseInt(parts[1]));
 | 
	
		
			
				|  |  | +        material.setElasticModulus(Double.parseDouble(parts[2]));
 | 
	
		
			
				|  |  | +        material.setPoissonRatio(Double.parseDouble(parts[3]));
 | 
	
		
			
				|  |  | +        material.setDensity(Double.parseDouble(parts[4]));
 | 
	
		
			
				|  |  | +        return material;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |