Salome HOME
Implementation of ACISPLUGIN as a GEOM plugin (added files)
[plugins/acisplugin.git] / src / ACISPluginBuilder.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2014  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 from ACISPlugin import GEOM_IACISPluginOperations
22
23 # Engine Library Name
24 __libraryName__ = "ACISPluginEngine"
25
26 def GetACISPluginOperations(self):
27     anOp = self.GetPluginOperations(self.myStudyId, __libraryName__)
28     return anOp._narrow(GEOM_IACISPluginOperations)
29
30 ## Export the given shape into a file with given name in ACIS format.
31 #  @param theObject Shape to be stored in the file.
32 #  @param theFileName Name of the file to store the given shape in.
33 def ExportACIS(self, theObject, theFileName):
34     """
35     Export the given shape into a file with given name in ACIS format.
36
37     Parameters: 
38         theObject Shape to be stored in the file.
39         theFileName Name of the file to store the given shape in.
40     """
41     anOp = GetACISPluginOperations(self)
42     anOp.ExportACIS(theObject, theFileName)
43     if anOp.IsDone() == 0:
44         raise RuntimeError,  "Export : " + anOp.GetErrorCode()
45         pass
46     pass
47
48
49 ## Import a shape from the ACIS file
50 #  @param theFileName The file, containing the shape.
51 #  @param theName Object name; when specified, this parameter is used
52 #         for result publication in the study. Otherwise, if automatic
53 #         publication is switched on, default value is used for result name.
54 #
55 #  @return New GEOM.GEOM_Object, containing the imported shape.
56 #          If material names are imported it returns the list of
57 #          objects. The first one is the imported object followed by
58 #          material groups.
59 #  @note Auto publishing is allowed for the shape itself. Imported
60 #        material groups are not automatically published.
61 def ImportACIS(self, theFileName, theName=None):
62     """
63     Import a shape from the ACIS file
64
65     Parameters: 
66         theFileName The file, containing the shape.
67         theName Object name; when specified, this parameter is used
68                 for result publication in the study. Otherwise, if automatic
69                 publication is switched on, default value is used for result name.
70
71     Returns:
72         New GEOM.GEOM_Object, containing the imported shape.
73         If material names are imported it returns the list of
74         objects. The first one is the imported object followed by
75         material groups.
76     Note:
77         Auto publishing is allowed for the shape itself. Imported
78         material groups are not automatically published.
79     """
80     from salome.geom.geomBuilder import RaiseIfFailed
81     anOp = GetACISPluginOperations(self)
82     aListObj = anOp.ImportACIS(theFileName)
83     RaiseIfFailed("ImportACIS", anOp)
84     aNbObj = len(aListObj)
85     if aNbObj > 0:
86         self._autoPublish(aListObj[0], theName, "imported")
87     if aNbObj == 1:
88         return aListObj[0]
89     return aListObj