source: main/branches/3D/openPLM/document3D/models.py @ 597

Revision 597, 3.8 KB checked in by agalech, 9 years ago (diff)

branch 3D: 3D view: make it possible to show/hide each shape of a stp file

Line 
1from django.db import models
2from django.contrib import admin
3from openPLM.plmapp.models import *
4from openPLM.plmapp.controllers import DocumentController
5
6from django.db.models import get_model
7# Create your models here.
8
9class Document3D(Document):
10
11   
12   
13    @property
14    def menu_items(self):
15        items = list(super(Document3D, self).menu_items)       
16        items.extend(["3D"])
17        return items
18           
19       
20       
21
22
23admin.site.register(Document3D)
24
25
26
27
28media3Djs = DocumentStorage(location=settings.MEDIA_ROOT+"3D/")   
29media3Djs_navigabilite = DocumentStorage(location=settings.MEDIA_ROOT+"3D/navigabilite")
30
31
32class stp_to_jss_navigabilite(models.Model):
33
34    js = models.FileField(upload_to='.',storage=media3Djs_navigabilite)
35    stp = models.ForeignKey(DocumentFile)
36   
37         
38class stp_to_jss(models.Model):
39
40    js = models.FileField(upload_to='.',storage=media3Djs)
41    stp = models.ForeignKey(DocumentFile)   
42
43class arbre_nom_shapes():
44    nom=''
45    children=[]
46    def __init__(self, nom):
47        self.nom = nom
48        self.children=[]
49   
50#restricciones fichero:si no se genera el jss , o si el jss generado es demasiado grande
51class Document3DController(DocumentController):
52
53    def handle_added_file(self, doc_file):
54        from openPLM.document3D.aficher import convertir_STP_to_JSS
55       
56        fileName, fileExtension = os.path.splitext(doc_file.filename)
57        if fileExtension.upper()== '.STP':
58           
59           
60
61            #delete old jss file (only neccesary in case of check-in -> handle)
62            multi_jss=stp_to_jss.objects.filter(stp=doc_file)
63            count=multi_jss.count()
64            for i in range(count): 
65                os.remove(settings.MEDIA_ROOT+"3D/"+multi_jss[count-i-1].js.name)
66                print "Deleting .jss associes:" , (settings.MEDIA_ROOT+"3D/"+multi_jss[count-i-1].js.name)
67                multi_jss[count-i-1].delete()
68
69            #delete old jss_navigabilite file
70            multi_jss=stp_to_jss_navigabilite.objects.filter(stp=doc_file)
71            count=multi_jss.count()
72            for i in range(count): 
73                os.remove(settings.MEDIA_ROOT+"3D/navigabilite/"+multi_jss[count-i-1].js.name)
74                print "Deleting navigabilite .jss associe:" , (settings.MEDIA_ROOT+"3D/navigabilite/"+multi_jss[count-i-1].js.name)
75                multi_jss[count-i-1].delete()
76            # end delteting
77           
78            if not convertir_STP_to_JSS(doc_file):
79                return False           
80
81            return True
82           
83    def delete_file(self, doc_file):
84
85       
86        fileName, fileExtension = os.path.splitext(doc_file.filename)
87        if fileExtension.upper()== '.STP':
88       
89            multi_jss=stp_to_jss.objects.filter(stp=doc_file)
90            count=multi_jss.count()
91            for i in range(count):
92                os.remove(settings.MEDIA_ROOT+"3D/"+multi_jss[count-i-1].js.name)
93                print "Deleting .jss associes :" , (settings.MEDIA_ROOT+"3D/"+multi_jss[count-i-1].js.name)
94                multi_jss[count-i-1].delete()
95               
96            multi_jss=stp_to_jss_navigabilite.objects.filter(stp=doc_file)
97            count=multi_jss.count()
98            for i in range(count):
99                os.remove(settings.MEDIA_ROOT+"3D/navigabilite/"+multi_jss[count-i-1].js.name)
100                print "Deleting .jss associes :" , (settings.MEDIA_ROOT+"3D/navigabilite/"+multi_jss[count-i-1].js.name)
101                multi_jss[count-i-1].delete()
102
103
104            super(Document3DController, self).delete_file(doc_file)
105           
106
107
108           
109        else:
110       
111            super(Document3DController, self).delete_file(doc_file)
112
113
114class Arbre:
115
116  def __init__(self, datos,):
117    self.datos
118    self.nom = nom
119    self.hijos  = []
120
121           
122
Note: See TracBrowser for help on using the repository browser.