Salome HOME
Copyrights update 2015.
[modules/geom.git] / src / XAOPlugin / XAOPlugin_IOperations_i.cc
1 // Copyright (C) 2014-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // internal includes
21 #include "XAOPlugin_IOperations_i.hh"
22 #include "XAOPlugin_IOperations.hxx"
23
24 // KERNEL includes
25 #include <utilities.h>
26
27 //=============================================================================
28 /*!
29  *   constructor:
30  */
31 //=============================================================================
32 XAOPlugin_IOperations_i::XAOPlugin_IOperations_i( PortableServer::POA_ptr thePOA,
33                                                   GEOM::GEOM_Gen_ptr theEngine,
34                                                   XAOPlugin_IOperations* theImpl )
35 :GEOM_IOperations_i( thePOA, theEngine, theImpl )
36 {
37   MESSAGE( "XAOPlugin_IOperations_i::XAOPlugin_IOperations_i" );
38 }
39
40 //=============================================================================
41 /*!
42  *  destructor
43  */
44 //=============================================================================
45 XAOPlugin_IOperations_i::~XAOPlugin_IOperations_i()
46 {
47   MESSAGE( "XAOPlugin_IOperations_i::~XAOPlugin_IOperations_i" );
48 }
49
50 //=============================================================================
51 /*!
52  *  Export a shape to XAO format
53  *  \param shape The shape to export
54  *  \param groups The list of groups to export
55  *  \param fields The list of fields to export
56  *  \param author The author of the export
57  *  \param fileName The name of the exported file
58  *  \return boolean indicating if export was succeful.
59  */
60 //=============================================================================
61 CORBA::Boolean XAOPlugin_IOperations_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
62                                                    const GEOM::ListOfGO& groups,
63                                                    const GEOM::ListOfFields& fields,
64                                                    const char* author,
65                                                    const char* fileName)
66 {
67   bool isGood = false;
68   // Set a not done flag
69   GetOperations()->SetNotDone();
70
71   // Get the reference shape
72   Handle(GEOM_Object) reference = GetObjectImpl( shape );
73
74   // Get the reference groups
75   int ind = 0;
76   std::list<Handle(GEOM_Object)> groupsObj;
77   for (; ind < groups.length(); ind++)
78   {
79     Handle(GEOM_Object) gobj = GetObjectImpl( groups[ind] );
80     if (gobj.IsNull()) return false;
81     groupsObj.push_back(gobj);
82   }
83
84   // Get the reference fields
85   ind = 0;
86   std::list<Handle(GEOM_Field)> fieldsObj;
87   for( ; ind < fields.length(); ind++ )
88   {
89     Handle(GEOM_Field) fobj = Handle(GEOM_Field)::DownCast( GetBaseObjectImpl( fields[ind] ) );
90     if( fobj.IsNull() ) return false;
91     fieldsObj.push_back(fobj);
92   }
93
94   if( !reference.IsNull() )
95   {
96     // Export XAO
97     isGood = GetOperations()->ExportXAO( reference, groupsObj, fieldsObj, author, fileName );
98   }
99
100   return isGood;
101 }
102
103 //=============================================================================
104 /*!
105  *  Import a shape from XAO format
106  *  \param fileName The name of the file to import
107  *  \param shape The imported shape
108  *  \param subShapes The list of imported subShapes
109  *  \param groups The list of imported groups
110  *  \param fields The list of imported fields
111  *  \return boolean indicating if import was succeful.
112  */
113 //=============================================================================
114 CORBA::Boolean XAOPlugin_IOperations_i::ImportXAO( const char* fileName,
115                                                    GEOM::GEOM_Object_out shape,
116                                                    GEOM::ListOfGO_out subShapes,
117                                                    GEOM::ListOfGO_out groups,
118                                                    GEOM::ListOfFields_out fields)
119 {
120   GEOM::GEOM_Object_var vshape;
121   shape = vshape._retn();
122
123   subShapes = new GEOM::ListOfGO;
124   groups = new GEOM::ListOfGO;
125   fields = new GEOM::ListOfFields;
126
127   // Set a not done flag
128   GetOperations()->SetNotDone();
129
130   Handle(TColStd_HSequenceOfTransient) importedSubShapes = new TColStd_HSequenceOfTransient();
131   Handle(TColStd_HSequenceOfTransient) importedGroups = new TColStd_HSequenceOfTransient();
132   Handle(TColStd_HSequenceOfTransient) importedFields = new TColStd_HSequenceOfTransient();
133   Handle(GEOM_Object) hshape;
134   bool res = GetOperations()->ImportXAO( fileName, hshape, importedSubShapes, importedGroups, importedFields );
135
136   if( !GetOperations()->IsDone() || !res )
137     return false;
138
139   // parse fields
140   int n = importedSubShapes->Length();
141   subShapes->length(n);
142   for( int i = 1; i <= n; i++ )
143   {
144     (*subShapes)[i - 1] = GetObject( Handle(GEOM_Object)::DownCast( importedSubShapes->Value(i) ) );
145   }
146
147   // parse groups
148   n = importedGroups->Length();
149   groups->length(n);
150   for( int i = 1; i <= n; i++ )
151   {
152     (*groups)[i - 1] = GetObject( Handle(GEOM_Object)::DownCast( importedGroups->Value(i) ) );
153   }
154
155   // parse fields
156   n = importedFields->Length();
157   fields->length(n);
158   for( int i = 1; i <= n; i++ )
159   {
160     (*fields)[i - 1] = GEOM::GEOM_Field::_narrow(
161       GetBaseObject( Handle(GEOM_Field)::DownCast( importedFields->Value(i) ) ) );
162   }
163
164   shape = GetObject( hshape );
165
166   return res;
167 }
168
169 XAOPlugin_IOperations* XAOPlugin_IOperations_i::GetOperations()
170 {
171   return (XAOPlugin_IOperations*)GetImpl();
172 }