From b12880da502b18f53801a2b0352bedba273daa71 Mon Sep 17 00:00:00 2001 From: yuxianghui <1608204036@qq.com> Date: Fri, 8 Sep 2023 10:39:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=BE=E5=BC=80OCC=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/product_template.py | 32 +++++++++--------- sf_sale/models/quick_easy_order.py | 36 ++++++++++----------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/sf_manufacturing/models/product_template.py b/sf_manufacturing/models/product_template.py index a55ebef8..c26181d1 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -1,8 +1,8 @@ from odoo import models, fields, api from odoo.exceptions import ValidationError from odoo.modules import get_resource_path -# from OCC.Extend.DataExchange import read_step_file -# from OCC.Extend.DataExchange import write_stl_file +from OCC.Extend.DataExchange import read_step_file +from OCC.Extend.DataExchange import write_stl_file import logging import base64 import hashlib @@ -663,20 +663,20 @@ class ResProductMo(models.Model): item.model_file = self.transition_glb_file(report_path, model_code) # 将attach的datas内容转为glb文件 - # def transition_glb_file(self, report_path, code): - # shapes = read_step_file(report_path) - # output_file = os.path.join('/tmp', str(code) + '.stl') - # write_stl_file(shapes, output_file, 'binary', 0.03, 0.5) - # # 转化为glb - # output_glb_file = os.path.join('/tmp', str(code) + '.glb') - # util_path = get_resource_path('sf_dlm', 'static/util') - # cmd = 'python3 %s/stl2gltf.py %s %s -b' % (util_path, output_file, output_glb_file) - # os.system(cmd) - # # 转base64 - # with open(output_glb_file, 'rb') as fileObj: - # image_data = fileObj.read() - # base64_data = base64.b64encode(image_data) - # return base64_data + def transition_glb_file(self, report_path, code): + shapes = read_step_file(report_path) + output_file = os.path.join('/tmp', str(code) + '.stl') + write_stl_file(shapes, output_file, 'binary', 0.03, 0.5) + # 转化为glb + output_glb_file = os.path.join('/tmp', str(code) + '.glb') + util_path = get_resource_path('sf_dlm', 'static/util') + cmd = 'python3 %s/stl2gltf.py %s %s -b' % (util_path, output_file, output_glb_file) + os.system(cmd) + # 转base64 + with open(output_glb_file, 'rb') as fileObj: + image_data = fileObj.read() + base64_data = base64.b64encode(image_data) + return base64_data class ResMrpBomMo(models.Model): diff --git a/sf_sale/models/quick_easy_order.py b/sf_sale/models/quick_easy_order.py index 625e21a2..eed2be57 100644 --- a/sf_sale/models/quick_easy_order.py +++ b/sf_sale/models/quick_easy_order.py @@ -1,7 +1,7 @@ from odoo import models, fields, api from odoo.modules import get_resource_path -# from OCC.Extend.DataExchange import read_step_file -# from OCC.Extend.DataExchange import write_stl_file +from OCC.Extend.DataExchange import read_step_file +from OCC.Extend.DataExchange import write_stl_file from odoo.exceptions import ValidationError, UserError from odoo.addons.sf_base.commons.common import Common from datetime import datetime @@ -86,22 +86,22 @@ class QuickEasyOrder(models.Model): return obj # 将attach的datas内容转为glb文件 - # def transition_glb_file(self, report_path, model_code): - # shapes = read_step_file(report_path) - # # output_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.stl') - # output_file = os.path.join('/tmp', str(model_code) + '.stl') - # write_stl_file(shapes, output_file, 'binary', 0.03, 0.5) - # # 转化为glb - # # output_glb_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.glb') - # output_glb_file = os.path.join('/tmp', str(model_code) + '.glb') - # util_path = get_resource_path('sf_dlm', 'static/util') - # cmd = 'python3 %s/stl2gltf.py %s %s -b' % (util_path, output_file, output_glb_file) - # os.system(cmd) - # # 转base64 - # with open(output_glb_file, 'rb') as fileObj: - # image_data = fileObj.read() - # base64_data = base64.b64encode(image_data) - # return base64_data + def transition_glb_file(self, report_path, model_code): + shapes = read_step_file(report_path) + # output_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.stl') + output_file = os.path.join('/tmp', str(model_code) + '.stl') + write_stl_file(shapes, output_file, 'binary', 0.03, 0.5) + # 转化为glb + # output_glb_file = os.path.join('C:/Users/43484/Desktop/机企猫工作文档', str(model_code) + '.glb') + output_glb_file = os.path.join('/tmp', str(model_code) + '.glb') + util_path = get_resource_path('sf_dlm', 'static/util') + cmd = 'python3 %s/stl2gltf.py %s %s -b' % (util_path, output_file, output_glb_file) + os.system(cmd) + # 转base64 + with open(output_glb_file, 'rb') as fileObj: + image_data = fileObj.read() + base64_data = base64.b64encode(image_data) + return base64_data # return False