1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "XAOPlugin_IOperations_i.hh"
22 #include "XAOPlugin_IOperations.hxx"
25 #include <utilities.h>
27 //=============================================================================
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 )
37 MESSAGE( "XAOPlugin_IOperations_i::XAOPlugin_IOperations_i" );
40 //=============================================================================
44 //=============================================================================
45 XAOPlugin_IOperations_i::~XAOPlugin_IOperations_i()
47 MESSAGE( "XAOPlugin_IOperations_i::~XAOPlugin_IOperations_i" );
50 //=============================================================================
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.
60 //=============================================================================
61 CORBA::Boolean XAOPlugin_IOperations_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
62 const GEOM::ListOfGO& groups,
63 const GEOM::ListOfFields& fields,
68 // Set a not done flag
69 GetOperations()->SetNotDone();
71 // Get the reference shape
72 Handle(GEOM_Object) reference = GetObjectImpl( shape );
74 // Get the reference groups
76 std::list<Handle(GEOM_Object)> groupsObj;
77 for (; ind < groups.length(); ind++)
79 Handle(GEOM_Object) gobj = GetObjectImpl( groups[ind] );
80 if (gobj.IsNull()) return false;
81 groupsObj.push_back(gobj);
84 // Get the reference fields
86 std::list<Handle(GEOM_Field)> fieldsObj;
87 for( ; ind < fields.length(); ind++ )
89 Handle(GEOM_Field) fobj = Handle(GEOM_Field)::DownCast( GetBaseObjectImpl( fields[ind] ) );
90 if( fobj.IsNull() ) return false;
91 fieldsObj.push_back(fobj);
94 if( !reference.IsNull() )
97 isGood = GetOperations()->ExportXAO( reference, groupsObj, fieldsObj, author, fileName );
103 //=============================================================================
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.
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)
120 GEOM::GEOM_Object_var vshape;
121 shape = vshape._retn();
123 subShapes = new GEOM::ListOfGO;
124 groups = new GEOM::ListOfGO;
125 fields = new GEOM::ListOfFields;
127 // Set a not done flag
128 GetOperations()->SetNotDone();
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 );
136 if( !GetOperations()->IsDone() || !res )
140 int n = importedSubShapes->Length();
141 subShapes->length(n);
142 for( int i = 1; i <= n; i++ )
144 (*subShapes)[i - 1] = GetObject( Handle(GEOM_Object)::DownCast( importedSubShapes->Value(i) ) );
148 n = importedGroups->Length();
150 for( int i = 1; i <= n; i++ )
152 (*groups)[i - 1] = GetObject( Handle(GEOM_Object)::DownCast( importedGroups->Value(i) ) );
156 n = importedFields->Length();
158 for( int i = 1; i <= n; i++ )
160 (*fields)[i - 1] = GEOM::GEOM_Field::_narrow(
161 GetBaseObject( Handle(GEOM_Field)::DownCast( importedFields->Value(i) ) ) );
164 shape = GetObject( hshape );
169 XAOPlugin_IOperations* XAOPlugin_IOperations_i::GetOperations()
171 return (XAOPlugin_IOperations*)GetImpl();