1 // Copyright (C) 2007-2022 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_ProjectionSource1D_i.cxx
25 // Author : Edward AGAPOV
28 #include "StdMeshers_ProjectionSource1D_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_ProjectionSource1D_i::StdMeshers_ProjectionSource1D_i
47 //=============================================================================
49 StdMeshers_ProjectionSource1D_i::StdMeshers_ProjectionSource1D_i
50 ( PortableServer::POA_ptr thePOA,
51 ::SMESH_Gen* theGenImpl ) : SALOME::GenericObj_i( thePOA ),
52 SMESH_Hypothesis_i( thePOA )
54 myBaseImpl = new ::StdMeshers_ProjectionSource1D( theGenImpl->GetANewId(),
58 //=============================================================================
60 * StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i
64 //=============================================================================
66 StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i()
70 //=============================================================================
72 * Sets source <edge> or a group containing edges to take a mesh pattern from
74 //=============================================================================
76 void StdMeshers_ProjectionSource1D_i::SetSourceEdge(GEOM::GEOM_Object_ptr edge)
80 this->GetImpl()->SetSourceEdge( StdMeshers_ObjRefUlils::GeomObjectToShape( edge ));
81 CORBA::String_var entry = edge->GetStudyEntry();
82 myShapeEntries[ SRC_EDGE ] = entry.in();
84 catch ( SALOME_Exception& S_ex ) {
85 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
87 // Update Python script
88 SMESH::TPythonDump() << _this() << ".SetSourceEdge( " << edge << " )";
91 //=============================================================================
93 * Sets vertex association between the source edge and the target one.
94 * This parameter is optional
96 //=============================================================================
98 void StdMeshers_ProjectionSource1D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex,
99 GEOM::GEOM_Object_ptr targetVertex)
101 ASSERT( myBaseImpl );
103 TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex );
104 TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex );
105 this->GetImpl()->SetVertexAssociation( v1, v2 );
107 myShapeEntries[ SRC_VERTEX ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex );
108 myShapeEntries[ TGT_VERTEX ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex );
110 catch ( SALOME_Exception& S_ex ) {
111 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
113 // Update Python script
114 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
115 << sourceVertex << ", " << targetVertex << " )";
118 //=============================================================================
120 * Sets source <mesh> to take a mesh pattern from
122 //=============================================================================
124 void StdMeshers_ProjectionSource1D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
126 ASSERT( myBaseImpl );
128 ::SMESH_Mesh* mesh = 0;
130 if ( !CORBA::is_nil( theMesh ))
132 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
134 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
135 mesh = &mesh_i->GetImpl();
139 this->GetImpl()->SetSourceMesh ( mesh );
141 catch ( SALOME_Exception& S_ex ) {
142 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
145 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
147 // Update Python script
148 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
151 //=============================================================================
155 //=============================================================================
157 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource1D_i::GetSourceMesh()
159 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
163 //=============================================================================
165 * Returns the source edge or a group containing edge
167 //=============================================================================
169 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceEdge()
171 ASSERT( myBaseImpl );
172 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
173 ( myShapeEntries[ SRC_EDGE ],
174 this->GetImpl()->GetSourceEdge() );
177 //=============================================================================
179 * Returns the vertex associated with the target vertex.
180 * Result may be nil if association not set
182 //=============================================================================
184 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceVertex()
186 ASSERT( myBaseImpl );
187 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
188 ( myShapeEntries[ SRC_VERTEX ],
189 this->GetImpl()->GetSourceVertex() );
192 //=============================================================================
194 * Returns the vertex associated with the source vertex.
195 * Result may be nil if association not set
197 //=============================================================================
199 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetTargetVertex()
201 ASSERT( myBaseImpl );
202 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
203 ( myShapeEntries[ TGT_VERTEX ],
204 this->GetImpl()->GetTargetVertex() );
207 //=============================================================================
209 * StdMeshers_ProjectionSource1D_i::GetImpl
213 //=============================================================================
215 ::StdMeshers_ProjectionSource1D* StdMeshers_ProjectionSource1D_i::GetImpl()
217 return ( ::StdMeshers_ProjectionSource1D* )myBaseImpl;
220 //================================================================================
222 * \brief Verify whether hypothesis supports given entity type
223 * \param type - dimension (see SMESH::Dimension enumeration)
224 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
226 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
228 //================================================================================
229 CORBA::Boolean StdMeshers_ProjectionSource1D_i::IsDimSupported( SMESH::Dimension type )
231 return type == SMESH::DIM_1D;
234 //================================================================================
236 * \brief Write parameters in a string
237 * \retval char* - resulting string
239 //================================================================================
241 char* StdMeshers_ProjectionSource1D_i::SaveTo()
243 ASSERT( myBaseImpl );
244 std::ostringstream os;
246 for ( int i = 0; i < NB_SHAPES; ++i )
247 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
248 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
250 myBaseImpl->SaveTo( os );
252 return CORBA::string_dup( os.str().c_str() );
255 //================================================================================
257 * \brief Retrieve parameters from the string
258 * \param theStream - the input string
260 //================================================================================
262 void StdMeshers_ProjectionSource1D_i::LoadFrom( const char* theStream )
264 ASSERT( myBaseImpl );
265 std::istringstream is( theStream );
267 TopoDS_Shape shapes[ NB_SHAPES ];
268 for ( int i = 0; i < NB_SHAPES; ++i )
269 shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
270 SMESH::SMESH_Mesh_var mesh =
271 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
273 ::SMESH_Mesh* meshImpl = 0;
275 if ( !CORBA::is_nil( mesh ))
277 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
279 meshImpl = &mesh_i->GetImpl();
282 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
284 GetImpl()->SetSourceMesh ( meshImpl );
285 GetImpl()->SetSourceEdge ( shapes[ SRC_EDGE ] );
286 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX ],
287 shapes[ TGT_VERTEX ]);
291 myBaseImpl->LoadFrom( is );
293 std::istringstream str( theStream );
294 for ( int i = 0; i < NB_SHAPES; ++i )
295 str >> myShapeEntries[ i ];
298 //================================================================================
300 * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
302 //================================================================================
305 StdMeshers_ProjectionSource1D_i::getObjectsDependOn( std::vector< std::string > & entryArray,
306 std::vector< int > & /*subIDArray*/ ) const
308 for ( int i = 0; i < NB_SHAPES; ++i )
309 entryArray.push_back( myShapeEntries[ i ]);
314 //================================================================================
316 * \brief Set new geometry instead of that returned by getObjectsDependOn()
318 //================================================================================
321 StdMeshers_ProjectionSource1D_i::setObjectsDependOn( std::vector< std::string > & entryArray,
322 std::vector< int > & /*subIDArray*/ )
324 TopoDS_Shape shapes[ NB_SHAPES ];
325 for ( int i = 0; i < NB_SHAPES; ++i )
327 myShapeEntries[ i ] = entryArray[ i ];
328 shapes[ i ] = StdMeshers_ObjRefUlils::EntryToShape( entryArray[ i ]);
332 GetImpl()->SetSourceEdge ( shapes[ SRC_EDGE ] );
333 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX ],
334 shapes[ TGT_VERTEX ]);