1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
24 // File : StdMeshers_ProjectionSource3D_i.cxx
25 // Author : Edward AGAPOV
28 #include "StdMeshers_ProjectionSource3D_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_PythonDump.hxx"
34 #include "Utils_CorbaException.hxx"
35 #include "utilities.h"
37 #include "StdMeshers_ObjRefUlils.hxx"
41 //=============================================================================
43 * StdMeshers_ProjectionSource3D_i::StdMeshers_ProjectionSource3D_i
47 //=============================================================================
49 StdMeshers_ProjectionSource3D_i::StdMeshers_ProjectionSource3D_i
50 ( PortableServer::POA_ptr thePOA,
51 ::SMESH_Gen* theGenImpl ) : SALOME::GenericObj_i( thePOA ),
52 SMESH_Hypothesis_i( thePOA )
54 myBaseImpl = new ::StdMeshers_ProjectionSource3D( theGenImpl->GetANewId(),
58 //=============================================================================
60 * StdMeshers_ProjectionSource3D_i::~StdMeshers_ProjectionSource3D_i
64 //=============================================================================
66 StdMeshers_ProjectionSource3D_i::~StdMeshers_ProjectionSource3D_i()
70 //=============================================================================
72 * Sets a source <face> to take a mesh pattern from
74 //=============================================================================
76 void StdMeshers_ProjectionSource3D_i::SetSource3DShape(GEOM::GEOM_Object_ptr shape)
80 this->GetImpl()->SetSource3DShape( StdMeshers_ObjRefUlils::GeomObjectToShape( shape ));
82 CORBA::String_var entry = shape->GetStudyEntry();
83 myShapeEntries[ SRC_SHAPE3D ] = entry.in();
85 catch ( SALOME_Exception& S_ex ) {
86 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
88 // Update Python script
89 SMESH::TPythonDump() << _this() << ".SetSource3DShape( " << shape << " )";
92 //=============================================================================
94 * Sets source <mesh> to take a mesh pattern from
96 //=============================================================================
98 void StdMeshers_ProjectionSource3D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
100 ASSERT( myBaseImpl );
102 ::SMESH_Mesh* mesh = 0;
104 if ( !CORBA::is_nil( theMesh ))
106 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
108 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
109 mesh = &mesh_i->GetImpl();
113 this->GetImpl()->SetSourceMesh ( mesh );
115 catch ( SALOME_Exception& S_ex ) {
116 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
119 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
121 // Update Python script
122 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
125 //=============================================================================
129 //=============================================================================
131 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource3D_i::GetSourceMesh()
133 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
137 //=============================================================================
139 * Sets vertex association between the source shape and the target one.
140 * This parameter is optional.
141 * Two vertices must belong to one edge of a shape
143 //=============================================================================
145 void StdMeshers_ProjectionSource3D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex1,
146 GEOM::GEOM_Object_ptr sourceVertex2,
147 GEOM::GEOM_Object_ptr targetVertex1,
148 GEOM::GEOM_Object_ptr targetVertex2)
150 ASSERT( myBaseImpl );
152 TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex1 );
153 TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex2 );
154 TopoDS_Shape v3 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex1 );
155 TopoDS_Shape v4 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex2 );
156 this->GetImpl()->SetVertexAssociation( v1, v2, v3, v4 );
158 myShapeEntries[ SRC_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex1 );
159 myShapeEntries[ SRC_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex2 );
160 myShapeEntries[ TGT_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex1 );
161 myShapeEntries[ TGT_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex2 );
163 catch ( SALOME_Exception& S_ex ) {
164 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
166 // Update Python script
167 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
168 << sourceVertex1 << ", "
169 << sourceVertex2 << ", "
170 << targetVertex1 << ", "
171 << targetVertex2 << " )";
174 //=============================================================================
176 * Returns the source face
178 //=============================================================================
180 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource3D_i::GetSource3DShape()
182 ASSERT( myBaseImpl );
183 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
184 ( myShapeEntries[ SRC_SHAPE3D ],
185 this->GetImpl()->GetSource3DShape() );
188 //=============================================================================
190 * Returns the vertex associated with the target vertex.
191 * Result may be nil if association not set
193 //=============================================================================
195 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource3D_i::GetSourceVertex(CORBA::Long i)
197 ASSERT( myBaseImpl );
198 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
199 ( myShapeEntries[ i == 1 ? SRC_VERTEX1 : SRC_VERTEX2 ],
200 this->GetImpl()->GetSourceVertex((int) i ));
203 //=============================================================================
205 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
206 * Result may be nil if association not set.
208 //=============================================================================
210 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource3D_i::GetTargetVertex(CORBA::Long i)
212 ASSERT( myBaseImpl );
213 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
214 ( myShapeEntries[ i == 1 ? TGT_VERTEX1 : TGT_VERTEX2 ],
215 this->GetImpl()->GetTargetVertex( (int)i ));
218 //=============================================================================
220 * StdMeshers_ProjectionSource3D_i::GetImpl
224 //=============================================================================
226 ::StdMeshers_ProjectionSource3D* StdMeshers_ProjectionSource3D_i::GetImpl()
228 return ( ::StdMeshers_ProjectionSource3D* )myBaseImpl;
231 //================================================================================
233 * \brief Verify whether hypothesis supports given entity type
234 * \param type - dimension (see SMESH::Dimension enumeration)
235 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
237 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
239 //================================================================================
240 CORBA::Boolean StdMeshers_ProjectionSource3D_i::IsDimSupported( SMESH::Dimension type )
242 return type == SMESH::DIM_3D;
245 //================================================================================
247 * \brief Write parameters in a string
248 * \retval char* - resulting string
250 //================================================================================
252 char* StdMeshers_ProjectionSource3D_i::SaveTo()
254 ASSERT( myBaseImpl );
255 std::ostringstream os;
257 for ( int i = 0; i < NB_SHAPES; ++i )
258 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
259 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
261 myBaseImpl->SaveTo( os );
263 return CORBA::string_dup( os.str().c_str() );
266 //================================================================================
268 * \brief Retrieve parameters from the string
269 * \param theStream - the input string
271 //================================================================================
273 void StdMeshers_ProjectionSource3D_i::LoadFrom( const char* theStream )
275 ASSERT( myBaseImpl );
276 std::istringstream is( theStream );
278 TopoDS_Shape shapes[ NB_SHAPES ];
279 for ( int i = 0; i < NB_SHAPES; ++i )
280 shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
281 SMESH::SMESH_Mesh_var mesh =
282 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
284 ::SMESH_Mesh* meshImpl = 0;
286 if ( !CORBA::is_nil( mesh ))
288 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
290 meshImpl = &mesh_i->GetImpl();
293 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
296 GetImpl()->SetSourceMesh ( meshImpl );
297 GetImpl()->SetSource3DShape ( shapes[ SRC_SHAPE3D ] );
298 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX1 ],
299 shapes[ SRC_VERTEX2 ],
300 shapes[ TGT_VERTEX1 ],
301 shapes[ TGT_VERTEX2 ]);
305 myBaseImpl->LoadFrom( is );
307 std::istringstream str( theStream );
308 for ( int i = 0; i < NB_SHAPES; ++i )
309 str >> myShapeEntries[ i ];
312 //================================================================================
314 * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
316 //================================================================================
319 StdMeshers_ProjectionSource3D_i::getObjectsDependOn( std::vector< std::string > & entryArray,
320 std::vector< int > & /*subIDArray*/ ) const
322 for ( int i = 0; i < NB_SHAPES; ++i )
323 entryArray.push_back( myShapeEntries[ i ]);
328 //================================================================================
330 * \brief Set new geometry instead of that returned by getObjectsDependOn()
332 //================================================================================
335 StdMeshers_ProjectionSource3D_i::setObjectsDependOn( std::vector< std::string > & entryArray,
336 std::vector< int > & /*subIDArray*/ )
338 TopoDS_Shape shapes[ NB_SHAPES ];
339 for ( int i = 0; i < NB_SHAPES; ++i )
341 myShapeEntries[ i ] = entryArray[ i ];
342 shapes[ i ] = StdMeshers_ObjRefUlils::EntryToShape( entryArray[ i ]);
346 GetImpl()->SetSource3DShape ( shapes[ SRC_SHAPE3D ] );
347 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX1 ],
348 shapes[ SRC_VERTEX2 ],
349 shapes[ TGT_VERTEX1 ],
350 shapes[ TGT_VERTEX2 ]);