1 // Copyright (C) 2007-2023 CEA, EDF, 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_ProjectionSource2D_i.cxx
25 // Author : Edward AGAPOV
28 #include "StdMeshers_ProjectionSource2D_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_ProjectionSource2D_i::StdMeshers_ProjectionSource2D_i
47 //=============================================================================
49 StdMeshers_ProjectionSource2D_i::StdMeshers_ProjectionSource2D_i
50 ( PortableServer::POA_ptr thePOA,
51 ::SMESH_Gen* theGenImpl ) : SALOME::GenericObj_i( thePOA ),
52 SMESH_Hypothesis_i( thePOA )
54 myBaseImpl = new ::StdMeshers_ProjectionSource2D( theGenImpl->GetANewId(),
58 //=============================================================================
60 * StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i
64 //=============================================================================
66 StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i()
70 //=============================================================================
72 * Sets a source <face> to take a mesh pattern from
74 //=============================================================================
76 void StdMeshers_ProjectionSource2D_i::SetSourceFace(GEOM::GEOM_Object_ptr face)
80 this->GetImpl()->SetSourceFace( StdMeshers_ObjRefUlils::GeomObjectToShape( face ));
81 CORBA::String_var entry = face->GetStudyEntry();
82 myShapeEntries[ SRC_FACE ] = 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() << ".SetSourceFace( " << face << " )";
91 //=============================================================================
93 * Sets source <mesh> to take a mesh pattern from
95 //=============================================================================
97 void StdMeshers_ProjectionSource2D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
101 ::SMESH_Mesh* mesh = 0;
103 if ( !CORBA::is_nil( theMesh ))
105 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
107 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
108 mesh = &mesh_i->GetImpl();
112 this->GetImpl()->SetSourceMesh ( mesh );
114 catch ( SALOME_Exception& S_ex ) {
115 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
118 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
120 // Update Python script
121 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
124 //=============================================================================
128 //=============================================================================
130 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource2D_i::GetSourceMesh()
132 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
136 //=============================================================================
138 * Sets vertex association between the source face and the target one.
139 * This parameter is optional.
140 * Two vertices must belong to one edge of a face
142 //=============================================================================
144 void StdMeshers_ProjectionSource2D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex1,
145 GEOM::GEOM_Object_ptr sourceVertex2,
146 GEOM::GEOM_Object_ptr targetVertex1,
147 GEOM::GEOM_Object_ptr targetVertex2)
149 ASSERT( myBaseImpl );
151 TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex1 );
152 TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex2 );
153 TopoDS_Shape v3 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex1 );
154 TopoDS_Shape v4 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex2 );
155 this->GetImpl()->SetVertexAssociation( v1, v2, v3, v4 );
157 myShapeEntries[ SRC_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex1 );
158 myShapeEntries[ SRC_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex2 );
159 myShapeEntries[ TGT_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex1 );
160 myShapeEntries[ TGT_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex2 );
162 catch ( SALOME_Exception& S_ex ) {
163 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
165 // Update Python script
166 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
167 << sourceVertex1 << ", "
168 << sourceVertex2 << ", "
169 << targetVertex1 << ", "
170 << targetVertex2 << " )";
173 //=============================================================================
175 * Returns the source face
177 //=============================================================================
179 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetSourceFace()
181 ASSERT( myBaseImpl );
182 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
183 ( myShapeEntries[ SRC_FACE ],
184 this->GetImpl()->GetSourceFace() );
187 //=============================================================================
189 * Returns the vertex associated with the target vertex.
190 * Result may be nil if association not set
192 //=============================================================================
194 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetSourceVertex(CORBA::Long i)
196 ASSERT( myBaseImpl );
197 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
198 ( myShapeEntries[ i == 1 ? SRC_VERTEX1 : SRC_VERTEX2 ],
199 this->GetImpl()->GetSourceVertex((int) i ));
202 //=============================================================================
204 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
205 * Result may be nil if association not set.
207 //=============================================================================
209 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetTargetVertex(CORBA::Long i)
211 ASSERT( myBaseImpl );
212 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
213 ( myShapeEntries[ i == 1 ? TGT_VERTEX1 : TGT_VERTEX2 ],
214 this->GetImpl()->GetTargetVertex( (int)i ));
217 //=============================================================================
219 * StdMeshers_ProjectionSource2D_i::GetImpl
223 //=============================================================================
225 ::StdMeshers_ProjectionSource2D* StdMeshers_ProjectionSource2D_i::GetImpl()
227 return ( ::StdMeshers_ProjectionSource2D* )myBaseImpl;
230 //================================================================================
232 * \brief Verify whether hypothesis supports given entity type
233 * \param type - dimension (see SMESH::Dimension enumeration)
234 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
236 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
238 //================================================================================
239 CORBA::Boolean StdMeshers_ProjectionSource2D_i::IsDimSupported( SMESH::Dimension type )
241 return type == SMESH::DIM_2D;
244 //================================================================================
246 * \brief Write parameters in a string
247 * \retval char* - resulting string
249 //================================================================================
251 char* StdMeshers_ProjectionSource2D_i::SaveTo()
253 ASSERT( myBaseImpl );
254 std::ostringstream os;
256 for ( int i = 0; i < NB_SHAPES; ++i )
257 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
258 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
260 myBaseImpl->SaveTo( os );
262 return CORBA::string_dup( os.str().c_str() );
265 //================================================================================
267 * \brief Retrieve parameters from the string
268 * \param theStream - the input string
270 //================================================================================
272 void StdMeshers_ProjectionSource2D_i::LoadFrom( const char* theStream )
274 ASSERT( myBaseImpl );
275 std::istringstream is( theStream );
277 TopoDS_Shape shapes[ NB_SHAPES ];
278 for ( int i = 0; i < NB_SHAPES; ++i )
279 shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
280 SMESH::SMESH_Mesh_var mesh =
281 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
283 ::SMESH_Mesh* meshImpl = 0;
285 if ( !CORBA::is_nil( mesh ))
287 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
289 meshImpl = &mesh_i->GetImpl();
292 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
295 GetImpl()->SetSourceMesh ( meshImpl );
296 GetImpl()->SetSourceFace ( shapes[ SRC_FACE ] );
297 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX1 ],
298 shapes[ SRC_VERTEX2 ],
299 shapes[ TGT_VERTEX1 ],
300 shapes[ TGT_VERTEX2 ]);
304 myBaseImpl->LoadFrom( is );
306 std::istringstream str( theStream );
307 for ( int i = 0; i < NB_SHAPES; ++i )
308 str >> myShapeEntries[ i ];
311 //================================================================================
313 * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
315 //================================================================================
318 StdMeshers_ProjectionSource2D_i::getObjectsDependOn( std::vector< std::string > & entryArray,
319 std::vector< int > & /*subIDArray*/ ) const
321 for ( int i = 0; i < NB_SHAPES; ++i )
322 entryArray.push_back( myShapeEntries[ i ]);
327 //================================================================================
329 * \brief Set new geometry instead of that returned by getObjectsDependOn()
331 //================================================================================
334 StdMeshers_ProjectionSource2D_i::setObjectsDependOn( std::vector< std::string > & entryArray,
335 std::vector< int > & /*subIDArray*/ )
337 TopoDS_Shape shapes[ NB_SHAPES ];
338 for ( int i = 0; i < NB_SHAPES; ++i )
340 myShapeEntries[ i ] = entryArray[ i ];
341 shapes[ i ] = StdMeshers_ObjRefUlils::EntryToShape( entryArray[ i ]);
345 GetImpl()->SetSourceFace ( shapes[ SRC_FACE ] );
346 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX1 ],
347 shapes[ SRC_VERTEX2 ],
348 shapes[ TGT_VERTEX1 ],
349 shapes[ TGT_VERTEX2 ]);