source: main/trunk/openPLM/document3D/generateComposition.py @ 1007

Revision 1007, 2.5 KB checked in by agalech, 11 years ago (diff)

New algorithm of decomposition

Line 
1import sys
2import django.utils.simplejson as json
3
4from OCC.TDF import TDF_LabelSequence
5from OCC.XSControl import XSControl_WorkSession
6from OCC.STEPControl import STEPControl_AsIs
7from OCC.STEPCAFControl import STEPCAFControl_Writer
8from OCC.TopLoc import TopLoc_Location
9from OCC.gp import gp_Trsf
10from STP_converter_WebGL import NEW_STEP_Import , SetLabelNom , colour_chercher
11from classes import generateArbre
12
13
14
15
16
17
18def composer(temp_file_name):
19
20
21   
22    output = open(temp_file_name.encode(),"r")
23    product =generateArbre(json.loads(output.read()))
24    output.close()
25    output = open(temp_file_name.encode(),"w+")# erase old data
26    output.close()
27    my_step_importer = NEW_STEP_Import(product.doc_path)
28
29 
30    st=my_step_importer.shape_tool
31    lr= TDF_LabelSequence()
32    st.GetFreeShapes(lr)
33   
34    add_labels(product,lr.Value(1),st)
35
36   
37    WS = XSControl_WorkSession()
38    writer = STEPCAFControl_Writer( WS.GetHandle(), False )
39    for i in range(lr.Length()):
40        writer.Transfer(lr.Value(i+1), STEPControl_AsIs)
41       
42    #f = NamedTemporaryFile(delete=False)
43       
44    status = writer.Write(temp_file_name)
45    #f.seek(0)
46    #return f
47   
48   
49   
50   
51def add_labels(product,lr,st):
52
53   
54    for link in product.links:
55
56   
57        if link.product.doc_id!= product.doc_id: # solo los que esten descompuesto, si no esta descompuesto no tiene que anadirlo
58
59            if not link.product.label_reference:
60
61                my_step_importer = NEW_STEP_Import(link.product.doc_path)
62                lr_2= TDF_LabelSequence()
63                my_step_importer.shape_tool.GetFreeShapes(lr_2)       
64                add_labels(link.product,lr_2.Value(1),my_step_importer.shape_tool)
65                link.product.label_reference=lr_2.Value(1)
66             
67             
68            for d in range(link.quantity):
69
70                transformation=gp_Trsf()
71                transformation.SetValues(link.locations[d].x1,link.locations[d].x2,link.locations[d].x3,link.locations[d].x4,link.locations[d].y1,link.locations[d].y2,link.locations[d].y3,link.locations[d].y4,link.locations[d].z1,link.locations[d].z2,link.locations[d].z3,link.locations[d].z4,1,1) 
72                new_label=st.AddComponent(lr,link.product.label_reference,TopLoc_Location(transformation))
73                SetLabelNom(new_label,link.names[d])
74
75           
76        else:
77            pass # no hace falta por que ya esta en la geometria                                           
78               
79   
80composer(sys.argv[1])   
81   
82   
83   
84   
85     
86   
Note: See TracBrowser for help on using the repository browser.