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 * \param shapeFileName If not empty, save to shape to this external file
59 * \return boolean indicating if export was succeful.
61 //=============================================================================
62 CORBA::Boolean XAOPlugin_IOperations_i::ExportXAO( GEOM::GEOM_Object_ptr shape,
63 const GEOM::ListOfGO& groups,
64 const GEOM::ListOfFields& fields,
67 const char* shapeFileName)
70 // Set a not done flag
71 GetOperations()->SetNotDone();
73 // Get the reference shape
74 Handle(GEOM_Object) reference = GetObjectImpl( shape );
76 // Get the reference groups
78 std::list<Handle(GEOM_Object)> groupsObj;
79 for (; ind < groups.length(); ind++)
81 Handle(GEOM_Object) gobj = GetObjectImpl( groups[ind] );
82 if (gobj.IsNull()) return false;
83 groupsObj.push_back(gobj);
86 // Get the reference fields
88 std::list<Handle(GEOM_Field)> fieldsObj;
89 for( ; ind < fields.length(); ind++ )
91 Handle(GEOM_Field) fobj = Handle(GEOM_Field)::DownCast( GetBaseObjectImpl( fields[ind] ) );
92 if( fobj.IsNull() ) return false;
93 fieldsObj.push_back(fobj);
96 if( !reference.IsNull() )
99 isGood = GetOperations()->ExportXAO( reference, groupsObj, fieldsObj, author, fileName, shapeFileName );
105 //=============================================================================
107 * Import a shape from XAO format
108 * \param fileName The name of the file to import
109 * \param shape The imported shape
110 * \param subShapes The list of imported subShapes
111 * \param groups The list of imported groups
112 * \param fields The list of imported fields
113 * \return boolean indicating if import was succeful.
115 //=============================================================================
116 CORBA::Boolean XAOPlugin_IOperations_i::ImportXAO( const char* fileName,
117 GEOM::GEOM_Object_out shape,
118 GEOM::ListOfGO_out subShapes,
119 GEOM::ListOfGO_out groups,
120 GEOM::ListOfFields_out fields)
122 GEOM::GEOM_Object_var vshape;
123 shape = vshape._retn();
125 subShapes = new GEOM::ListOfGO;
126 groups = new GEOM::ListOfGO;
127 fields = new GEOM::ListOfFields;
129 // Set a not done flag
130 GetOperations()->SetNotDone();
132 Handle(TColStd_HSequenceOfTransient) importedSubShapes = new TColStd_HSequenceOfTransient();
133 Handle(TColStd_HSequenceOfTransient) importedGroups = new TColStd_HSequenceOfTransient();
134 Handle(TColStd_HSequenceOfTransient) importedFields = new TColStd_HSequenceOfTransient();
135 Handle(GEOM_Object) hshape;
136 bool res = GetOperations()->ImportXAO( fileName, hshape, importedSubShapes, importedGroups, importedFields );
138 if( !GetOperations()->IsDone() || !res )
142 int n = importedSubShapes->Length();
143 subShapes->length(n);
144 for( int i = 1; i <= n; i++ )
146 (*subShapes)[i - 1] = GetObject( Handle(GEOM_Object)::DownCast( importedSubShapes->Value(i) ) );
150 n = importedGroups->Length();
152 for( int i = 1; i <= n; i++ )
154 (*groups)[i - 1] = GetObject( Handle(GEOM_Object)::DownCast( importedGroups->Value(i) ) );
158 n = importedFields->Length();
160 for( int i = 1; i <= n; i++ )
162 (*fields)[i - 1] = GEOM::GEOM_Field::_narrow(
163 GetBaseObject( Handle(GEOM_Field)::DownCast( importedFields->Value(i) ) ) );
166 shape = GetObject( hshape );
171 XAOPlugin_IOperations* XAOPlugin_IOperations_i::GetOperations()
173 return (XAOPlugin_IOperations*)GetImpl();