]> 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 EventsAPI
6 import ModelAPI
7
8 import salome
9 from salome.geom import geomBuilder
10
11
12 class ExportFeature(ModelAPI.ModelAPI_Feature):
13
14     "Feature to create a box by drawing a sketch and extruding it"
15
16     def __init__(self):
17         ModelAPI.ModelAPI_Feature.__init__(self)
18
19     @staticmethod
20     def ID():
21         return "ExportToGEOM"
22
23     def getKind(self):
24         return ExportFeature.ID()
25
26     # This feature is action: has no property pannel and executes immideately
27     # def isAction(self):
28     #    return True
29
30     def isInHistory(self):
31         return False
32
33     def initAttributes(self):
34         # This feature has no attributes, but should perfore some actions on initialization
35         aSession = ModelAPI.ModelAPI_Session.get()
36         aPart = aSession.activeDocument()
37         # Get all bodies
38         kResultBodyType = "Bodies"
39         aPartSize = aPart.size(kResultBodyType)
40         if aPartSize == 0:
41             EventsAPI.Events_Error_send("No results in the active document")
42             return
43
44         anObjList = [aPart.object(kResultBodyType, idx) for idx in xrange(aPartSize)]
45         for idx, anObject in enumerate(anObjList):
46             aResult = ModelAPI.modelAPI_Result(anObject)
47             aBodyResult = ModelAPI.modelAPI_ResultBody(aResult)
48             if not aBodyResult:
49                 continue
50             aShape = aBodyResult.shape()
51             aDump = aShape.getShapeStream()
52             # Load shape to SALOME Geom
53             geompy = geomBuilder.New(salome.myStudy)
54             aBrep = geompy.RestoreShape(aDump)
55             geompy.addToStudy(aBrep, "NewGeomShape_{0}".format(idx))
56
57     def execute(self):
58         # Nothing to execute: all logic would be in the initAttributes
59         pass