1 // Copyright (C) 2007-2016 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,
49 ::SMESH_Gen* theGenImpl )
50 : SALOME::GenericObj_i( thePOA ),
51 SMESH_Hypothesis_i( thePOA )
53 myBaseImpl = new ::StdMeshers_QuadrangleParams(theGenImpl->GetANewId(),
58 //=============================================================================
60 * StdMeshers_QuadrangleParams_i::~StdMeshers_QuadrangleParams_i
64 //=============================================================================
66 StdMeshers_QuadrangleParams_i::~StdMeshers_QuadrangleParams_i()
70 //=============================================================================
72 * StdMeshers_QuadrangleParams_i::SetTriaVertex
74 * Set base vertex for triangles
76 //=============================================================================
78 void StdMeshers_QuadrangleParams_i::SetTriaVertex(CORBA::Long vertID)
82 this->GetImpl()->SetTriaVertex( vertID );
84 catch ( SALOME_Exception& S_ex ) {
85 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
88 // Update Python script
89 SMESH::TPythonDump() << _this() << ".SetTriaVertex( " << vertID << " )";
92 //=============================================================================
94 * StdMeshers_QuadrangleParams_i::GetTriaVertex
96 * Get base vertex for triangles
98 //=============================================================================
100 CORBA::Long StdMeshers_QuadrangleParams_i::GetTriaVertex()
102 ASSERT( myBaseImpl );
103 return this->GetImpl()->GetTriaVertex();
106 //=============================================================================
108 * StdMeshers_QuadrangleParams_i::SetObjectEntry
110 * Set the Entry for the Main Object
112 //=============================================================================
114 void StdMeshers_QuadrangleParams_i::SetObjectEntry( const char* entry )
116 ASSERT( myBaseImpl );
119 this->GetImpl()->SetObjectEntry( entry );
120 // Update Python script
121 // SMESH::TPythonDump() << _this() << ".SetObjectEntry( '" << entry << "' )";
123 catch ( SALOME_Exception& S_ex ) {
124 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
129 //=============================================================================
131 * StdMeshers_QuadrangleParams_i::GetObjectEntry
133 * Set the Entry for the Main Object
135 //=============================================================================
137 char* StdMeshers_QuadrangleParams_i::GetObjectEntry()
139 ASSERT( myBaseImpl );
142 entry = this->GetImpl()->GetObjectEntry();
144 catch ( SALOME_Exception& S_ex ) {
145 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
147 return CORBA::string_dup( entry );
150 //=============================================================================
152 * StdMeshers_QuadrangleParams_i::SetQuadType
154 * Set the type of quadrangulation
156 //=============================================================================
157 void StdMeshers_QuadrangleParams_i::SetQuadType(StdMeshers::QuadType type)
161 if (int(type) >= int(StdMeshers::QUAD_NB_TYPES)) {
162 THROW_SALOME_CORBA_EXCEPTION("Bad type of quadrangulation", SALOME::BAD_PARAM);
166 this->GetImpl()->SetQuadType(StdMeshers_QuadType(int(type)));
168 catch (SALOME_Exception& S_ex) {
169 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
172 // Update Python script
173 const char* quadType;
175 case StdMeshers::QUAD_STANDARD:
176 quadType = "StdMeshers.QUAD_STANDARD"; break;
177 case StdMeshers::QUAD_TRIANGLE_PREF:
178 quadType = "StdMeshers.QUAD_TRIANGLE_PREF"; break;
179 case StdMeshers::QUAD_QUADRANGLE_PREF:
180 quadType = "StdMeshers.QUAD_QUADRANGLE_PREF"; break;
181 case StdMeshers::QUAD_QUADRANGLE_PREF_REVERSED:
182 quadType = "StdMeshers.QUAD_QUADRANGLE_PREF_REVERSED"; break;
183 case StdMeshers::QUAD_REDUCED:
184 quadType = "StdMeshers.QUAD_REDUCED"; break;
186 quadType = "UNKNOWN";
188 SMESH::TPythonDump() << _this() << ".SetQuadType( " << quadType << " )";
191 //=============================================================================
193 * StdMeshers_QuadrangleParams_i::GetQuadType
195 * Get the type of quadrangulation
197 //=============================================================================
198 StdMeshers::QuadType StdMeshers_QuadrangleParams_i::GetQuadType()
201 return StdMeshers::QuadType(int(this->GetImpl()->GetQuadType()));
204 //================================================================================
206 * \brief Set positions of enforced nodes
208 //================================================================================
210 void StdMeshers_QuadrangleParams_i::SetEnforcedNodes(const GEOM::ListOfGO& theVertices,
211 const SMESH::nodes_array& thePoints)
212 throw ( SALOME::SALOME_Exception )
215 std::vector< TopoDS_Shape > shapes;
216 std::vector< gp_Pnt > points;
217 shapes.reserve( theVertices.length() );
218 points.reserve( thePoints.length() );
220 myShapeEntries.clear();
222 for ( size_t i = 0; i < theVertices.length(); ++i )
224 if ( CORBA::is_nil( theVertices[i] ))
226 CORBA::String_var entry = theVertices[i]->GetStudyEntry();
227 if ( !entry.in() || !entry.in()[0] )
228 THROW_SALOME_CORBA_EXCEPTION( "Not published enforced vertex shape", SALOME::BAD_PARAM );
230 shapes.push_back( StdMeshers_ObjRefUlils::GeomObjectToShape( theVertices[i].in() ));
231 myShapeEntries.push_back( entry.in() );
233 for ( size_t i = 0; i < thePoints.length(); ++i )
235 points.push_back( gp_Pnt( thePoints[i].x, thePoints[i].y, thePoints[i].z ));
237 this->GetImpl()->SetEnforcedNodes( shapes, points );
239 catch ( SALOME_Exception& S_ex ) {
240 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
242 // Update Python script
243 SMESH::TPythonDump() << _this() << ".SetEnforcedNodes( "
244 << theVertices << ", " << thePoints << " )";
247 //================================================================================
249 * \brief Returns positions of enforced nodes
251 //================================================================================
253 void StdMeshers_QuadrangleParams_i::GetEnforcedNodes(GEOM::ListOfGO_out theVertices,
254 SMESH::nodes_array_out thePoints)
258 std::vector< TopoDS_Shape > shapes;
259 std::vector< gp_Pnt > points;
260 this->GetImpl()->GetEnforcedNodes( shapes, points );
262 theVertices = new GEOM::ListOfGO;
263 thePoints = new SMESH::nodes_array;
266 theVertices->length( myShapeEntries.size() );
267 for ( i = 0; i < myShapeEntries.size(); ++i )
269 StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject( myShapeEntries[i], shapes[i] );
271 thePoints->length( points.size() );
272 for ( i = 0; i < points.size(); ++i )
274 thePoints[i].x = points[i].X();
275 thePoints[i].y = points[i].Y();
276 thePoints[i].z = points[i].Z();
278 SMESH_CATCH( SMESH::doNothing );
281 //================================================================================
283 * \brief Returns study entries of shapes defining enforced nodes
285 //================================================================================
287 SMESH::string_array* StdMeshers_QuadrangleParams_i::GetEnfVertices()
289 SMESH::string_array_var arr = new SMESH::string_array;
290 arr->length( myShapeEntries.size() );
292 for ( size_t i = 0; i < myShapeEntries.size(); ++i )
293 arr[ i ] = myShapeEntries[ i ].c_str();
298 //=============================================================================
300 * StdMeshers_QuadrangleParams_i::GetImpl
304 //=============================================================================
306 ::StdMeshers_QuadrangleParams* StdMeshers_QuadrangleParams_i::GetImpl()
308 return ( ::StdMeshers_QuadrangleParams* )myBaseImpl;
311 //================================================================================
313 * \brief Verify whether hypothesis supports given entity type
314 * \param type - dimension (see SMESH::Dimension enumeration)
315 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
317 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
319 //================================================================================
320 CORBA::Boolean StdMeshers_QuadrangleParams_i::IsDimSupported( SMESH::Dimension type )
322 return type == SMESH::DIM_2D;
325 //================================================================================
327 * \brief Write parameters in a string
328 * \retval char* - resulting string
330 //================================================================================
332 char* StdMeshers_QuadrangleParams_i::SaveTo()
334 ASSERT( myBaseImpl );
335 std::ostringstream os;
337 os << "ENTRIES: " << myShapeEntries.size();
338 for ( size_t i = 0; i < myShapeEntries.size(); ++i )
339 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
342 myBaseImpl->SaveTo( os );
344 return CORBA::string_dup( os.str().c_str() );
347 //================================================================================
349 * \brief Retrieve parameters from the string
350 * \param theStream - the input string
352 //================================================================================
354 void StdMeshers_QuadrangleParams_i::LoadFrom( const char* theStream )
356 ASSERT( myBaseImpl );
358 bool hasEntries = ( strncmp( "ENTRIES: ", theStream, 9 ) == 0 );
359 std::istringstream is( theStream + ( hasEntries ? 9 : 0 ));
364 if ( is >> nb && nb > 0 )
366 std::vector< TopoDS_Shape > shapes;
367 std::vector< gp_Pnt > points;
368 myShapeEntries.resize( nb );
370 for ( int i = 0; i < nb; ++i )
371 shapes.push_back( StdMeshers_ObjRefUlils::LoadFromStream( is, & myShapeEntries[i] ));
374 GetImpl()->SetEnforcedNodes( shapes, points );
381 myBaseImpl->LoadFrom( is );