Salome HOME
Copyright update 2022
[modules/geom.git] / src / XAOPlugin / XAOPlugin_IECallBack.cxx
1 // Copyright (C) 2014-2022  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_IECallBack.hxx"
22 #include "XAOPlugin_IOperations.hxx"
23 #include "XAOPlugin_OperationsCreator.hxx"
24 #include "GEOMImpl_IShapesOperations.hxx"
25
26 //=============================================================================
27 /*!
28  *  constructor
29  */
30 //=============================================================================
31 XAOPlugin_IECallBack::XAOPlugin_IECallBack()
32 {
33 }
34
35 //=============================================================================
36 /*!
37  *  destructor
38  */
39 //=============================================================================
40 XAOPlugin_IECallBack::~XAOPlugin_IECallBack()
41 {
42 }
43
44 //=============================================================================
45 /*!
46  *  Export
47  */
48 //=============================================================================
49 bool
50 XAOPlugin_IECallBack::Export( const Handle(GEOM_Object)      theOriginal,
51                               const TCollection_AsciiString& theFileName,
52                               const TCollection_AsciiString& /*theFormatName*/,
53                               const TCollection_AsciiString& theShapeFileName )
54 {
55   XAOPlugin_IOperations* aPluginOperations = XAOPlugin_OperationsCreator::get( GetEngine() );
56   GEOMImpl_IShapesOperations* aShapesOperations = GetEngine()->GetIShapesOperations();
57
58   Handle(TColStd_HSequenceOfTransient) groups = aShapesOperations->GetExistingSubObjects( theOriginal, GEOMImpl_IShapesOperations::Groups );
59   Handle(TColStd_HSequenceOfTransient) fields = aShapesOperations->GetExistingSubObjects( theOriginal, GEOMImpl_IShapesOperations::Fields );
60   std::list<Handle(GEOM_Object)> lgroups;
61   std::list<Handle(GEOM_Field)> lfields;
62   for (int i = 1; i <= groups->Length(); i++)
63     lgroups.push_back( Handle(GEOM_Object)::DownCast( groups->Value(i) ) );
64   for (int i = 1; i <= fields->Length(); i++)
65     lfields.push_back( Handle(GEOM_Field)::DownCast( fields->Value(i) ) );
66   aPluginOperations->ExportXAO( theOriginal, lgroups, lfields, "SIMAN Author", theFileName.ToCString(), theShapeFileName.ToCString() );
67   return true;
68 }
69
70 //=============================================================================
71 /*!
72  *  Import
73  */
74 //=============================================================================
75 Handle(TColStd_HSequenceOfTransient)
76 XAOPlugin_IECallBack::Import( const TCollection_AsciiString& /*theFormatName*/,
77                               const TCollection_AsciiString& theFileName )
78 {
79   XAOPlugin_IOperations* aPluginOperations = XAOPlugin_OperationsCreator::get( GetEngine() );
80
81   Handle(TColStd_HSequenceOfTransient) result = new TColStd_HSequenceOfTransient();
82   Handle(TColStd_HSequenceOfTransient) subshapes = new TColStd_HSequenceOfTransient();
83   Handle(TColStd_HSequenceOfTransient) groups = new TColStd_HSequenceOfTransient();
84   Handle(TColStd_HSequenceOfTransient) fields = new TColStd_HSequenceOfTransient();
85   Handle(GEOM_Object) shape;
86
87   bool ok = aPluginOperations->ImportXAO( theFileName.ToCString(), shape, subshapes, groups, fields );
88   if ( ok ) {
89     result->Append( shape );
90     for ( int i = 1; i <= groups->Length(); i++ )
91       result->Append( groups->Value(i) );
92     for ( int i = 1; i <= fields->Length(); i++ )
93       result->Append( fields->Value(i) );
94   }
95   return result;
96 }