Salome HOME
9f5953f305c40288323f96de286285d45f171747
[modules/geom.git] / src / GEOM_I / GEOM_IFieldOperations_i.cc
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "GEOM_IFieldOperations_i.hh"
24
25 #include "utilities.h"
26 #include "OpUtil.hxx"
27 #include "Utils_ExceptHandlers.hxx"
28
29 #include "GEOM_Engine.hxx"
30 #include "GEOM_Object.hxx"
31 #include "GEOM_Field.hxx"
32
33 //=============================================================================
34 /*
35  *   constructor:
36  */
37 //=============================================================================
38 GEOM_IFieldOperations_i::GEOM_IFieldOperations_i (PortableServer::POA_ptr thePOA,
39                                                   GEOM::GEOM_Gen_ptr theEngine,
40                                                   ::GEOMImpl_IFieldOperations* theImpl)
41   :GEOM_IOperations_i(thePOA, theEngine, theImpl)
42 {
43   MESSAGE("GEOM_IFieldOperations_i::GEOM_IFieldOperations_i");
44 }
45
46 //=============================================================================
47 /*
48  *  destructor
49  */
50 //=============================================================================
51 GEOM_IFieldOperations_i::~GEOM_IFieldOperations_i()
52 {
53   MESSAGE("GEOM_IFieldOperations_i::~GEOM_IFieldOperations_i");
54 }
55
56
57 //=============================================================================
58 /*
59  *  \brief Creates a field
60  */
61 //=============================================================================
62
63 GEOM::GEOM_Field_ptr
64 GEOM_IFieldOperations_i::CreateField(GEOM::GEOM_Object_ptr     theShape,
65                                      const char*               theName,
66                                      GEOM::field_data_type     theType,
67                                      CORBA::Short              theDimension,
68                                      const GEOM::string_array& theComponentNames)
69 {
70   GEOM::GEOM_Field_var aField;
71
72   Handle(TColStd_HArray1OfExtendedString) compNames;
73   if ( theComponentNames.length() > 0 )
74   {
75     compNames = new TColStd_HArray1OfExtendedString( 1, theComponentNames.length() );
76     for ( size_t i = 0; i < theComponentNames.length(); ++i )
77       compNames->SetValue( i+1, theComponentNames[ i ].in() );
78   }
79   Handle(::GEOM_Object) aShapeRef = GetObjectImpl( theShape );
80   Handle(::GEOM_Field)  aFieldRef = GetOperations()->CreateField( aShapeRef,
81                                                                 theName,
82                                                                 (int) theType,
83                                                                 theDimension,
84                                                                 compNames );
85   if ( !aFieldRef.IsNull() )
86     aField = GEOM::GEOM_Field::_narrow( GetBaseObject( aFieldRef ));
87
88   return aField._retn();
89 }
90
91 //=============================================================================
92 /*
93  *  \brief Returns number of fields on a shape
94  */
95 //=============================================================================
96
97 CORBA::Long GEOM_IFieldOperations_i::CountFields( GEOM::GEOM_Object_ptr shape)
98 {
99   Handle(::GEOM_Object) go = GetObjectImpl( shape );
100
101   return ( CORBA::Long) GetOperations()->CountFields( go );
102 }
103
104 //=============================================================================
105 /*
106  *  \brief Returns all fields on a shape
107  */
108 //=============================================================================
109
110 GEOM::ListOfFields* GEOM_IFieldOperations_i::GetFields( GEOM::GEOM_Object_ptr shape )
111 {
112   GEOM::ListOfFields_var fields = new GEOM::ListOfFields;
113
114   Handle(::GEOM_Object) go = GetObjectImpl( shape );
115
116   Handle(TColStd_HSequenceOfTransient) seq = GetOperations()->GetFields( go );
117   if ( !seq.IsNull() )
118   {
119     fields->length( seq->Length() );
120     int nbF = 0;
121     for ( int i = 1; i <= seq->Length(); ++i )
122     {
123       Handle(::GEOM_Field)      f = Handle(::GEOM_Field)::DownCast( seq->Value( i ));
124       GEOM::GEOM_Field_var fvar = GEOM::GEOM_Field::_narrow( GetBaseObject( f ));
125       if ( !fvar->_is_nil() )
126         fields[ nbF++ ] = fvar._retn();
127     }
128     fields->length( nbF );
129   }
130   return fields._retn();
131 }
132
133 //=============================================================================
134 /*
135  *  \brief Returns all fields on a shape
136  */
137 //=============================================================================
138
139 GEOM::GEOM_Field_ptr GEOM_IFieldOperations_i::GetField( GEOM::GEOM_Object_ptr shape,
140                                                         const char*           name)
141 {
142   GEOM::GEOM_Field_var field;
143
144   Handle(::GEOM_Object) go = GetObjectImpl( shape );
145
146   Handle(::GEOM_Field) f = GetOperations()->GetField( go, name );
147   field = GEOM::GEOM_Field::_narrow( GetBaseObject( f ));
148
149   return field._retn();
150 }
151
152 //=============================================================================
153 /*
154  *  \brief Returns number of sub-shapes of given dimension
155  */
156 //=============================================================================
157
158 ::CORBA::Long GEOM_IFieldOperations_i::GetNbSubShapes(::GEOM::GEOM_Object_ptr shape,
159                                                       ::CORBA::Short          fieldDim)
160 {
161   Handle(::GEOM_Object) go = GetObjectImpl( shape );
162   return GEOM_Field::GetNbSubShapes( go, fieldDim );
163 }