1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : StdMeshers_QuadrangleParams_i.cxx
20 // Author : Sergey KUUL, OCC
23 #include "StdMeshers_QuadrangleParams_i.hxx"
25 #include "SMESH_Gen.hxx"
26 #include "SMESH_Gen_i.hxx"
27 #include "SMESH_PythonDump.hxx"
28 #include "StdMeshers_ObjRefUlils.hxx"
30 #include <Utils_CorbaException.hxx>
31 #include <utilities.h>
33 #include <Standard_ErrorHandler.hxx>
34 #include "SMESH_TryCatch.hxx"
38 //=============================================================================
40 * StdMeshers_QuadrangleParams_i::StdMeshers_QuadrangleParams_i
44 //=============================================================================
46 StdMeshers_QuadrangleParams_i::StdMeshers_QuadrangleParams_i
47 (PortableServer::POA_ptr thePOA,
48 ::SMESH_Gen* theGenImpl )
49 : SALOME::GenericObj_i( thePOA ),
50 SMESH_Hypothesis_i( thePOA )
52 myBaseImpl = new ::StdMeshers_QuadrangleParams(theGenImpl->GetANewId(),
56 //=============================================================================
58 * StdMeshers_QuadrangleParams_i::~StdMeshers_QuadrangleParams_i
62 //=============================================================================
64 StdMeshers_QuadrangleParams_i::~StdMeshers_QuadrangleParams_i()
68 //=============================================================================
70 * StdMeshers_QuadrangleParams_i::SetTriaVertex
72 * Set base vertex for triangles
74 //=============================================================================
76 void StdMeshers_QuadrangleParams_i::SetTriaVertex(CORBA::Long vertID)
80 this->GetImpl()->SetTriaVertex( vertID );
82 catch ( SALOME_Exception& S_ex ) {
83 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
86 // Update Python script
87 SMESH::TPythonDump() << _this() << ".SetTriaVertex( " << vertID << " )";
90 //=============================================================================
92 * StdMeshers_QuadrangleParams_i::GetTriaVertex
94 * Get base vertex for triangles
96 //=============================================================================
98 CORBA::Long StdMeshers_QuadrangleParams_i::GetTriaVertex()
100 ASSERT( myBaseImpl );
101 return this->GetImpl()->GetTriaVertex();
104 //=============================================================================
106 * StdMeshers_QuadrangleParams_i::SetObjectEntry
108 * Set the Entry for the Main Object
110 //=============================================================================
112 void StdMeshers_QuadrangleParams_i::SetObjectEntry( const char* entry )
114 ASSERT( myBaseImpl );
117 this->GetImpl()->SetObjectEntry( entry );
118 // Update Python script
119 // SMESH::TPythonDump() << _this() << ".SetObjectEntry( '" << entry << "' )";
121 catch ( SALOME_Exception& S_ex ) {
122 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
127 //=============================================================================
129 * StdMeshers_QuadrangleParams_i::GetObjectEntry
131 * Set the Entry for the Main Object
133 //=============================================================================
135 char* StdMeshers_QuadrangleParams_i::GetObjectEntry()
137 ASSERT( myBaseImpl );
140 entry = this->GetImpl()->GetObjectEntry();
142 catch ( SALOME_Exception& S_ex ) {
143 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
145 return CORBA::string_dup( entry );
148 //=============================================================================
150 * StdMeshers_QuadrangleParams_i::SetQuadType
152 * Set the type of quadrangulation
154 //=============================================================================
155 void StdMeshers_QuadrangleParams_i::SetQuadType(StdMeshers::QuadType type)
159 if (int(type) >= int(StdMeshers::QUAD_NB_TYPES)) {
160 THROW_SALOME_CORBA_EXCEPTION("Bad type of quadrangulation", SALOME::BAD_PARAM);
164 this->GetImpl()->SetQuadType(StdMeshers_QuadType(int(type)));
166 catch (SALOME_Exception& S_ex) {
167 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
170 // Update Python script
171 const char* quadType;
173 case StdMeshers::QUAD_STANDARD:
174 quadType = "StdMeshers.QUAD_STANDARD"; break;
175 case StdMeshers::QUAD_TRIANGLE_PREF:
176 quadType = "StdMeshers.QUAD_TRIANGLE_PREF"; break;
177 case StdMeshers::QUAD_QUADRANGLE_PREF:
178 quadType = "StdMeshers.QUAD_QUADRANGLE_PREF"; break;
179 case StdMeshers::QUAD_QUADRANGLE_PREF_REVERSED:
180 quadType = "StdMeshers.QUAD_QUADRANGLE_PREF_REVERSED"; break;
181 case StdMeshers::QUAD_REDUCED:
182 quadType = "StdMeshers.QUAD_REDUCED"; break;
184 quadType = "UNKNOWN";
186 SMESH::TPythonDump() << _this() << ".SetQuadType( " << quadType << " )";
189 //=============================================================================
191 * StdMeshers_QuadrangleParams_i::GetQuadType
193 * Get the type of quadrangulation
195 //=============================================================================
196 StdMeshers::QuadType StdMeshers_QuadrangleParams_i::GetQuadType()
199 return StdMeshers::QuadType(int(this->GetImpl()->GetQuadType()));
202 //================================================================================
204 * \brief Set positions of enforced nodes
206 //================================================================================
208 void StdMeshers_QuadrangleParams_i::SetEnforcedNodes(const GEOM::ListOfGO& theVertices,
209 const SMESH::nodes_array& thePoints)
212 std::vector< TopoDS_Shape > shapes;
213 std::vector< gp_Pnt > points;
214 shapes.reserve( theVertices.length() );
215 points.reserve( thePoints.length() );
217 myShapeEntries.clear();
219 for ( size_t i = 0; i < theVertices.length(); ++i )
221 if ( CORBA::is_nil( theVertices[i] ))
223 CORBA::String_var entry = theVertices[i]->GetStudyEntry();
224 if ( !entry.in() || !entry.in()[0] )
225 THROW_SALOME_CORBA_EXCEPTION( "Not published enforced vertex shape", SALOME::BAD_PARAM );
227 shapes.push_back( StdMeshers_ObjRefUlils::GeomObjectToShape( theVertices[i].in() ));
228 myShapeEntries.push_back( entry.in() );
230 for ( size_t i = 0; i < thePoints.length(); ++i )
232 points.push_back( gp_Pnt( thePoints[i].x, thePoints[i].y, thePoints[i].z ));
234 this->GetImpl()->SetEnforcedNodes( shapes, points );
236 catch ( SALOME_Exception& S_ex ) {
237 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
239 // Update Python script
240 SMESH::TPythonDump() << _this() << ".SetEnforcedNodes( "
241 << theVertices << ", " << thePoints << " )";
244 //================================================================================
246 * \brief Returns positions of enforced nodes
248 //================================================================================
250 void StdMeshers_QuadrangleParams_i::GetEnforcedNodes(GEOM::ListOfGO_out theVertices,
251 SMESH::nodes_array_out thePoints)
255 std::vector< TopoDS_Shape > shapes;
256 std::vector< gp_Pnt > points;
257 this->GetImpl()->GetEnforcedNodes( shapes, points );
259 theVertices = new GEOM::ListOfGO;
260 thePoints = new SMESH::nodes_array;
263 theVertices->length( myShapeEntries.size() );
264 for ( i = 0; i < myShapeEntries.size(); ++i )
266 StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject( myShapeEntries[i], shapes[i] );
268 thePoints->length( points.size() );
269 for ( i = 0; i < points.size(); ++i )
271 thePoints[i].x = points[i].X();
272 thePoints[i].y = points[i].Y();
273 thePoints[i].z = points[i].Z();
275 SMESH_CATCH( SMESH::doNothing );
278 //================================================================================
280 * \brief Returns study entries of shapes defining enforced nodes
282 //================================================================================
284 SMESH::string_array* StdMeshers_QuadrangleParams_i::GetEnfVertices()
286 SMESH::string_array_var arr = new SMESH::string_array;
287 arr->length( myShapeEntries.size() );
289 for ( size_t i = 0; i < myShapeEntries.size(); ++i )
290 arr[ i ] = myShapeEntries[ i ].c_str();
295 //=============================================================================
297 * Set corner vertices
299 //=============================================================================
301 void StdMeshers_QuadrangleParams_i::SetCorners(const SMESH::long_array& theVertexIDs )
303 std::vector< int > ids;
304 for ( CORBA::ULong i = 0; i < theVertexIDs.length(); ++i )
305 ids.push_back( theVertexIDs[i] );
307 if ( ids != GetImpl()->GetCorners() )
309 GetImpl()->SetCorners( ids );
310 SMESH::TPythonDump() << _this() << ".SetCorners( " << theVertexIDs << " )";
314 //=============================================================================
316 * Return IDs of corner vertices
318 //=============================================================================
320 SMESH::long_array* StdMeshers_QuadrangleParams_i::GetCorners()
322 const std::vector< int >& ids = GetImpl()->GetCorners();
324 SMESH::long_array_var result = new SMESH::long_array;
325 result->length( ids.size() );
326 for ( size_t i = 0; i < ids.size(); ++i )
327 result[ i ] = ids[ i ];
329 return result._retn();
332 //=============================================================================
334 * StdMeshers_QuadrangleParams_i::GetImpl
338 //=============================================================================
340 ::StdMeshers_QuadrangleParams* StdMeshers_QuadrangleParams_i::GetImpl()
342 return ( ::StdMeshers_QuadrangleParams* )myBaseImpl;
345 //================================================================================
347 * \brief Verify whether hypothesis supports given entity type
348 * \param type - dimension (see SMESH::Dimension enumeration)
349 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
351 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
353 //================================================================================
354 CORBA::Boolean StdMeshers_QuadrangleParams_i::IsDimSupported( SMESH::Dimension type )
356 return type == SMESH::DIM_2D;
359 //================================================================================
361 * \brief Write parameters in a string
362 * \retval char* - resulting string
364 //================================================================================
366 char* StdMeshers_QuadrangleParams_i::SaveTo()
368 ASSERT( myBaseImpl );
369 std::ostringstream os;
371 os << "ENTRIES: " << myShapeEntries.size();
372 for ( size_t i = 0; i < myShapeEntries.size(); ++i )
373 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
376 myBaseImpl->SaveTo( os );
378 return CORBA::string_dup( os.str().c_str() );
381 //================================================================================
383 * \brief Retrieve parameters from the string
384 * \param theStream - the input string
386 //================================================================================
388 void StdMeshers_QuadrangleParams_i::LoadFrom( const char* theStream )
390 ASSERT( myBaseImpl );
392 bool hasEntries = ( strncmp( "ENTRIES: ", theStream, 9 ) == 0 );
393 std::istringstream is( theStream + ( hasEntries ? 9 : 0 ));
398 if ( is >> nb && nb > 0 )
400 std::vector< TopoDS_Shape > shapes;
401 std::vector< gp_Pnt > points;
402 myShapeEntries.resize( nb );
404 for ( int i = 0; i < nb; ++i )
405 shapes.push_back( StdMeshers_ObjRefUlils::LoadFromStream( is, & myShapeEntries[i] ));
408 GetImpl()->SetEnforcedNodes( shapes, points );
415 myBaseImpl->LoadFrom( is );
418 //================================================================================
420 * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
422 //================================================================================
425 StdMeshers_QuadrangleParams_i::getObjectsDependOn( std::vector< std::string > & entryArray,
426 std::vector< int > & subIDArray ) const
428 const ::StdMeshers_QuadrangleParams* impl =
429 static_cast<const ::StdMeshers_QuadrangleParams*>( myBaseImpl );
431 subIDArray.push_back( impl->GetTriaVertex() );
433 entryArray.push_back( impl->GetObjectEntry() );
434 entryArray.insert( entryArray.end(), myShapeEntries.begin(), myShapeEntries.end() );
439 //================================================================================
441 * \brief Set new geometry instead of that returned by getObjectsDependOn()
443 //================================================================================
446 StdMeshers_QuadrangleParams_i::setObjectsDependOn( std::vector< std::string > & entryArray,
447 std::vector< int > & subIDArray )
449 if ( !subIDArray.empty() )
450 GetImpl()->SetTriaVertex( subIDArray[0] );
452 GetImpl()->SetObjectEntry( entryArray[0].c_str() );
454 myShapeEntries.assign( ++entryArray.begin(), entryArray.end() );
456 std::vector< TopoDS_Shape > shapes;
457 std::vector< gp_Pnt > points;
458 this->GetImpl()->GetEnforcedNodes( shapes, points );
461 for ( size_t i = 0; i < myShapeEntries.size(); ++i )
462 shapes.push_back( StdMeshers_ObjRefUlils::EntryToShape( myShapeEntries[i] ));
464 this->GetImpl()->SetEnforcedNodes( shapes, points );