]> SALOME platform Git repositories - modules/shaper.git/blob - src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py
Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / ConnectorPlugin / ConnectorPlugin_ExportFeature.py
1 """
2 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 """
4
5 import ModelAPI
6 import salome
7 from salome.geom import geomBuilder
8
9
10 class ExportFeature(ModelAPI.ModelAPI_Feature):
11
12     "Feature to create a box by drawing a sketch and extruding it"
13
14     def __init__(self):
15         ModelAPI.ModelAPI_Feature.__init__(self)
16
17     @staticmethod
18     def ID():
19         return "ExportToGEOM"
20
21     def getKind(self):
22         return ExportFeature.ID()
23
24     # This feature is action: has no property pannel and executes immideately
25     def isAction(self):
26         return True
27
28     def initAttributes(self):
29         # This feature has no attributes, but should perfore some actions on initialization
30         aSession = ModelAPI.ModelAPI_Session.get()
31         aPart = aSession.activeDocument()
32         # Get all bodies
33         kResultBodyType = "ResultBody"
34         aPartSize = aPart.size(kResultBodyType)
35         if aPartSize == 0:
36             print "No results in the active document"
37             return
38
39         aResultList = [aPart.object(kResultBodyType, idx) for idx in xrange(aPartSize)]
40         for idx, aResult in enumerate(aResultList):
41             aBodyResult = modelAPI_ResultBody(aResult)
42             if not aBodyResult:
43                 continue
44             aShape = aBodyResult.shape()
45             aDump = aShape.getShapeStream()
46             # Load shape to SALOME Geom
47             geompy = geomBuilder.New(salome.myStudy)
48             aBrep = geompy.RestoreShape(aDump)
49             geompy.addToStudy(aBrep, "NewGeomShape_{0}".format(idx))
50
51     def execute(self):
52         # Nothing to execute: all logic would be in the initAttributes
53         pass
54
55 # TEST
56 """
57 if __name__=='__main__':
58   session = ModelAPI.ModelAPI_Session.get()
59   part = session.activeDocument()
60   session.startOperation()
61   feature = part.addFeature('Box')
62   feature.real('box_width').setValue(10)
63   feature.real('box_length').setValue(10)
64   feature.real('box_height').setValue(10)
65   feature.execute()
66   session.finishOperation()
67 """