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

Revision 1005, 2.0 KB checked in by agalech, 11 years ago (diff)

Decomposition multi-level for document3D

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
9
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:
58            print "adding labels to : " , link.product.name
59            my_step_importer = NEW_STEP_Import(link.product.doc_path)
60            print "A"
61            lr_2= TDF_LabelSequence()
62
63            my_step_importer.shape_tool.GetFreeShapes(lr_2)
64           
65            add_labels(link.product,lr_2.Value(1),my_step_importer.shape_tool)
66            print "B"               
67            for d in range(link.quantity):
68
69                new_label=st.AddComponent(lr,lr_2.Value(1),TopLoc_Location(link.locations[d].Transformation()))
70                SetLabelNom(new_label,link.names[d])
71            print "C"                                           
72               
73   
74composer(sys.argv[1])   
75   
76   
77   
78   
79     
80   
Note: See TracBrowser for help on using the repository browser.