1 // Copyright (C) 2007-2014 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 MESSAGE( "StdMeshers_QuadrangleParams_i::StdMeshers_QuadrangleParams_i" );
54 myBaseImpl = new ::StdMeshers_QuadrangleParams(theGenImpl->GetANewId(),
59 //=============================================================================
61 * StdMeshers_QuadrangleParams_i::~StdMeshers_QuadrangleParams_i
65 //=============================================================================
67 StdMeshers_QuadrangleParams_i::~StdMeshers_QuadrangleParams_i()
69 MESSAGE( "StdMeshers_QuadrangleParams_i::~StdMeshers_QuadrangleParams_i" );
72 //=============================================================================
74 * StdMeshers_QuadrangleParams_i::SetTriaVertex
76 * Set base vertex for triangles
78 //=============================================================================
80 void StdMeshers_QuadrangleParams_i::SetTriaVertex(CORBA::Long vertID)
82 MESSAGE( "StdMeshers_QuadrangleParams_i::SetTriaVertex" );
85 this->GetImpl()->SetTriaVertex( vertID );
87 catch ( SALOME_Exception& S_ex ) {
88 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
91 // Update Python script
92 SMESH::TPythonDump() << _this() << ".SetTriaVertex( " << vertID << " )";
95 //=============================================================================
97 * StdMeshers_QuadrangleParams_i::GetTriaVertex
99 * Get base vertex for triangles
101 //=============================================================================
103 CORBA::Long StdMeshers_QuadrangleParams_i::GetTriaVertex()
105 MESSAGE( "StdMeshers_QuadrangleParams_i::GetTriaVertex" );
106 ASSERT( myBaseImpl );
107 return this->GetImpl()->GetTriaVertex();
110 //=============================================================================
112 * StdMeshers_QuadrangleParams_i::SetObjectEntry
114 * Set the Entry for the Main Object
116 //=============================================================================
118 void StdMeshers_QuadrangleParams_i::SetObjectEntry( const char* entry )
120 MESSAGE( "StdMeshers_QuadrangleParams_i::SetObjectEntry" );
121 ASSERT( myBaseImpl );
124 this->GetImpl()->SetObjectEntry( entry );
125 // Update Python script
126 // SMESH::TPythonDump() << _this() << ".SetObjectEntry( '" << entry << "' )";
128 catch ( SALOME_Exception& S_ex ) {
129 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
134 //=============================================================================
136 * StdMeshers_QuadrangleParams_i::GetObjectEntry
138 * Set the Entry for the Main Object
140 //=============================================================================
142 char* StdMeshers_QuadrangleParams_i::GetObjectEntry()
144 MESSAGE( "StdMeshers_QuadrangleParams_i::SetObjectEntry" );
145 ASSERT( myBaseImpl );
148 entry = this->GetImpl()->GetObjectEntry();
150 catch ( SALOME_Exception& S_ex ) {
151 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
153 return CORBA::string_dup( entry );
156 //=============================================================================
158 * StdMeshers_QuadrangleParams_i::SetQuadType
160 * Set the type of quadrangulation
162 //=============================================================================
163 void StdMeshers_QuadrangleParams_i::SetQuadType(StdMeshers::QuadType type)
165 MESSAGE("StdMeshers_QuadrangleParams_i::SetQuadType");
168 if (int(type) >= int(StdMeshers::QUAD_NB_TYPES)) {
169 THROW_SALOME_CORBA_EXCEPTION("Bad type of quadrangulation", SALOME::BAD_PARAM);
173 this->GetImpl()->SetQuadType(StdMeshers_QuadType(int(type)));
175 catch (SALOME_Exception& S_ex) {
176 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
179 // Update Python script
180 const char* quadType;
182 case StdMeshers::QUAD_STANDARD:
183 quadType = "StdMeshers.QUAD_STANDARD"; break;
184 case StdMeshers::QUAD_TRIANGLE_PREF:
185 quadType = "StdMeshers.QUAD_TRIANGLE_PREF"; break;
186 case StdMeshers::QUAD_QUADRANGLE_PREF:
187 quadType = "StdMeshers.QUAD_QUADRANGLE_PREF"; break;
188 case StdMeshers::QUAD_QUADRANGLE_PREF_REVERSED:
189 quadType = "StdMeshers.QUAD_QUADRANGLE_PREF_REVERSED"; break;
190 case StdMeshers::QUAD_REDUCED:
191 quadType = "StdMeshers.QUAD_REDUCED"; break;
193 quadType = "UNKNOWN";
195 SMESH::TPythonDump() << _this() << ".SetQuadType( " << quadType << " )";
198 //=============================================================================
200 * StdMeshers_QuadrangleParams_i::GetQuadType
202 * Get the type of quadrangulation
204 //=============================================================================
205 StdMeshers::QuadType StdMeshers_QuadrangleParams_i::GetQuadType()
207 MESSAGE("StdMeshers_QuadrangleParams_i::GetQuadType");
209 return StdMeshers::QuadType(int(this->GetImpl()->GetQuadType()));
212 //================================================================================
214 * \brief Set positions of enforced nodes
216 //================================================================================
218 void StdMeshers_QuadrangleParams_i::SetEnforcedNodes(const GEOM::ListOfGO& theVertices,
219 const SMESH::nodes_array& thePoints)
220 throw ( SALOME::SALOME_Exception )
223 std::vector< TopoDS_Shape > shapes;
224 std::vector< gp_Pnt > points;
225 shapes.reserve( theVertices.length() );
226 points.reserve( thePoints.length() );
228 myShapeEntries.clear();
230 for ( size_t i = 0; i < theVertices.length(); ++i )
232 if ( CORBA::is_nil( theVertices[i] ))
234 CORBA::String_var entry = theVertices[i]->GetStudyEntry();
235 if ( !entry.in() || !entry.in()[0] )
236 THROW_SALOME_CORBA_EXCEPTION( "Not published enforced vertex shape", SALOME::BAD_PARAM );
238 shapes.push_back( StdMeshers_ObjRefUlils::GeomObjectToShape( theVertices[i].in() ));
239 myShapeEntries.push_back( entry.in() );
241 for ( size_t i = 0; i < thePoints.length(); ++i )
243 points.push_back( gp_Pnt( thePoints[i].x, thePoints[i].y, thePoints[i].z ));
245 this->GetImpl()->SetEnforcedNodes( shapes, points );
247 catch ( SALOME_Exception& S_ex ) {
248 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
250 // Update Python script
251 SMESH::TPythonDump() << _this() << ".SetEnforcedNodes( "
252 << theVertices << ", " << thePoints << " )";
255 //================================================================================
257 * \brief Returns positions of enforced nodes
259 //================================================================================
261 void StdMeshers_QuadrangleParams_i::GetEnforcedNodes(GEOM::ListOfGO_out theVertices,
262 SMESH::nodes_array_out thePoints)
266 std::vector< TopoDS_Shape > shapes;
267 std::vector< gp_Pnt > points;
268 this->GetImpl()->GetEnforcedNodes( shapes, points );
270 theVertices = new GEOM::ListOfGO;
271 thePoints = new SMESH::nodes_array;
274 theVertices->length( myShapeEntries.size() );
275 for ( i = 0; i < myShapeEntries.size(); ++i )
277 StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject( myShapeEntries[i], shapes[i] );
279 thePoints->length( points.size() );
280 for ( i = 0; i < points.size(); ++i )
282 thePoints[i].x = points[i].X();
283 thePoints[i].y = points[i].Y();
284 thePoints[i].z = points[i].Z();
286 SMESH_CATCH( SMESH::doNothing );
289 //================================================================================
291 * \brief Returns study entries of shapes defining enforced nodes
293 //================================================================================
295 SMESH::string_array* StdMeshers_QuadrangleParams_i::GetEnfVertices()
297 SMESH::string_array_var arr = new SMESH::string_array;
298 arr->length( myShapeEntries.size() );
300 for ( size_t i = 0; i < myShapeEntries.size(); ++i )
301 arr[ i ] = myShapeEntries[ i ].c_str();
306 //=============================================================================
308 * StdMeshers_QuadrangleParams_i::GetImpl
312 //=============================================================================
314 ::StdMeshers_QuadrangleParams* StdMeshers_QuadrangleParams_i::GetImpl()
316 MESSAGE( "StdMeshers_QuadrangleParams_i::GetImpl" );
317 return ( ::StdMeshers_QuadrangleParams* )myBaseImpl;
320 //================================================================================
322 * \brief Verify whether hypothesis supports given entity type
323 * \param type - dimension (see SMESH::Dimension enumeration)
324 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
326 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
328 //================================================================================
329 CORBA::Boolean StdMeshers_QuadrangleParams_i::IsDimSupported( SMESH::Dimension type )
331 return type == SMESH::DIM_2D;
334 //================================================================================
336 * \brief Write parameters in a string
337 * \retval char* - resulting string
339 //================================================================================
341 char* StdMeshers_QuadrangleParams_i::SaveTo()
343 ASSERT( myBaseImpl );
344 std::ostringstream os;
346 os << "ENTRIES: " << myShapeEntries.size();
347 for ( size_t i = 0; i < myShapeEntries.size(); ++i )
348 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
351 myBaseImpl->SaveTo( os );
353 return CORBA::string_dup( os.str().c_str() );
356 //================================================================================
358 * \brief Retrieve parameters from the string
359 * \param theStream - the input string
361 //================================================================================
363 void StdMeshers_QuadrangleParams_i::LoadFrom( const char* theStream )
365 ASSERT( myBaseImpl );
367 bool hasEntries = ( strncmp( "ENTRIES: ", theStream, 9 ) == 0 );
368 std::istringstream is( theStream + ( hasEntries ? 9 : 0 ));
373 if ( is >> nb && nb > 0 )
375 std::vector< TopoDS_Shape > shapes;
376 std::vector< gp_Pnt > points;
377 myShapeEntries.resize( nb );
379 for ( int i = 0; i < nb; ++i )
380 shapes.push_back( StdMeshers_ObjRefUlils::LoadFromStream( is, & myShapeEntries[i] ));
382 GetImpl()->SetEnforcedNodes( shapes, points );
386 myBaseImpl->LoadFrom( is );