1 // Copyright (C) 2007-2024 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
20 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
21 // File : StdMeshers_ViscousLayers_i.cxx
24 #include "StdMeshers_ViscousLayerBuilder_i.hxx"
26 #include "SMESH_Gen.hxx"
27 #include "SMESH_Gen_i.hxx"
28 #include "SMESH_Group.hxx"
29 #include "SMESH_Group_i.hxx"
30 #include "SMESH_PythonDump.hxx"
32 #include "BRepTools.hxx"
33 #include "Utils_CorbaException.hxx"
34 #include "utilities.h"
36 #include <TCollection_AsciiString.hxx>
38 #include CORBA_SERVER_HEADER(SMESH_Group)
42 //=============================================================================
44 * StdMeshers_ViscousLayerBuilder_i::StdMeshers_ViscousLayerBuilder_i
48 //=============================================================================
50 StdMeshers_ViscousLayerBuilder_i::StdMeshers_ViscousLayerBuilder_i( PortableServer::POA_ptr thePOA,
51 ::SMESH_Gen* theGenImpl )
52 : SALOME::GenericObj_i( thePOA ),
53 SMESH_Hypothesis_i( thePOA ),
54 SMESH_Algo_i( thePOA ),
55 SMESH_2D_Algo_i( thePOA )
57 myBaseImpl = new ::StdMeshers_ViscousLayerBuilder( theGenImpl->GetANewId(),
61 ::StdMeshers_ViscousLayerBuilder* StdMeshers_ViscousLayerBuilder_i::GetImpl()
63 return ( ::StdMeshers_ViscousLayerBuilder* )myBaseImpl;
66 //================================================================================
68 * \brief Verify whether hypothesis supports given entity type
69 * \param type - dimension (see SMESH::Dimension enumeration)
70 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
72 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
74 //================================================================================
75 CORBA::Boolean StdMeshers_ViscousLayerBuilder_i::IsDimSupported( SMESH::Dimension type )
77 return type == SMESH::DIM_3D || type == SMESH::DIM_2D;
80 void StdMeshers_ViscousLayerBuilder_i::SetFaces(const ::SMESH::long_array& faceIDs,
81 CORBA::Boolean toIgnore)
83 vector<int> ids( faceIDs.length() );
84 for ( unsigned i = 0; i < ids.size(); ++i )
85 if (( ids[i] = faceIDs[i] ) < 1 )
86 THROW_SALOME_CORBA_EXCEPTION( "Invalid face id", SALOME::BAD_PARAM );
88 GetImpl()->SetBndShapes( ids, toIgnore );
90 SMESH::TPythonDump() << _this() << ".SetFaces( " << faceIDs << ", " << toIgnore << " )";
94 void StdMeshers_ViscousLayerBuilder_i::SetIgnoreFaces(const ::SMESH::long_array& faceIDs)
96 vector<int> ids( faceIDs.length() );
97 for ( unsigned i = 0; i < ids.size(); ++i )
98 if (( ids[i] = faceIDs[i] ) < 1 )
99 THROW_SALOME_CORBA_EXCEPTION( "Invalid face id", SALOME::BAD_PARAM );
100 GetImpl()->SetBndShapes( ids, /*toIgnore=*/true );
101 SMESH::TPythonDump() << _this() << ".SetIgnoreFaces( " << faceIDs << " )";
104 void StdMeshers_ViscousLayerBuilder_i::SetTotalThickness(::CORBA::Double thickness)
106 if ( thickness < 1e-100 )
107 THROW_SALOME_CORBA_EXCEPTION( "Invalid thickness", SALOME::BAD_PARAM );
108 GetImpl()->SetTotalThickness(thickness);
109 SMESH::TPythonDump() << _this() << ".SetTotalThickness( " << SMESH::TVar(thickness) << " )";
112 void StdMeshers_ViscousLayerBuilder_i::SetNumberLayers(::CORBA::Short nb)
115 THROW_SALOME_CORBA_EXCEPTION( "Invalid number of layers", SALOME::BAD_PARAM );
116 GetImpl()->SetNumberLayers( nb );
117 SMESH::TPythonDump() << _this() << ".SetNumberLayers( " << SMESH::TVar(nb) << " )";
120 void StdMeshers_ViscousLayerBuilder_i::SetStretchFactor(::CORBA::Double factor)
123 THROW_SALOME_CORBA_EXCEPTION( "Invalid stretch factor, it must be >= 1.0", SALOME::BAD_PARAM );
124 GetImpl()->SetStretchFactor(factor);
125 SMESH::TPythonDump() << _this() << ".SetStretchFactor( " << SMESH::TVar(factor) << " )";
128 void StdMeshers_ViscousLayerBuilder_i::SetMethod( ::StdMeshers::VLExtrusionMethod how )
130 GetImpl()->SetMethod( ::StdMeshers_ViscousLayers::ExtrusionMethod( how ));
131 const char* methNames[3] = { "SURF_OFFSET_SMOOTH",
134 if ( how >= 0 && how < 3 )
135 SMESH::TPythonDump() << _this() << ".SetMethod( StdMeshers." << methNames[ how ]<< " )";
138 void StdMeshers_ViscousLayerBuilder_i::SetGroupName(const char* name)
140 GetImpl()->SetGroupName( name );
141 SMESH::TPythonDump() << _this() << ".SetGroupName( '" << name << "' )";
144 GEOM::GEOM_Object_ptr StdMeshers_ViscousLayerBuilder_i::GetShrinkGeometry( SMESH::SMESH_Mesh_ptr finalMesh, GEOM::GEOM_Object_ptr theShapeObject )
147 GEOM::GEOM_Object_var aShapeObj;
148 TopoDS_Shape theShape = StdMeshers_ObjRefUlils::GeomObjectToShape( theShapeObject );
149 SMESH_Mesh_i* theFinalMesh_i = SMESH::DownCast< SMESH_Mesh_i* >( finalMesh );
150 TopoDS_Shape shrinkGeometry;
154 shrinkGeometry = GetImpl()->GetShrinkGeometry( theFinalMesh_i->GetImpl(), theShape );
156 catch ( std::exception& exc )
158 std::cout << exc.what() << "\n";
159 THROW_SALOME_CORBA_EXCEPTION( exc.what(), SALOME::INTERNAL_ERROR );
160 return aShapeObj; // Maybe better to return a init and empty object(?)
163 if ( !shrinkGeometry.IsNull() )
165 std::ostringstream streamShape;
166 //Write TopoDS_Shape in ASCII format to the stream
167 BRepTools::Write(shrinkGeometry, streamShape);
168 //Returns the number of bytes that have been stored in the stream's buffer.
169 int size = streamShape.str().size();
170 //Allocate octect buffer of required size
171 CORBA::Octet* OctetBuf = SALOMEDS::TMPFile::allocbuf(size);
172 //Copy ostrstream content to the octect buffer
173 memcpy(OctetBuf, streamShape.str().c_str(), size);
174 //Create and return TMPFile
175 SALOMEDS::TMPFile_var SeqFile = new SALOMEDS::TMPFile(size,size,OctetBuf,1);
176 // Get the geom engine
177 GEOM::GEOM_Gen_var geomEngine = theShapeObject->GetGen();
178 auto iOp = geomEngine->GetIInsertOperations();
179 aShapeObj = iOp->RestoreShape( SeqFile );
180 geomEngine->AddInStudy( aShapeObj, "Shrink", GEOM::GEOM_Object::_nil());
186 CORBA::Boolean StdMeshers_ViscousLayerBuilder_i::AddLayers( SMESH::SMESH_Mesh_ptr shrinkMesh, SMESH::SMESH_Mesh_ptr finalMesh, GEOM::GEOM_Object_ptr theShapeObject )
188 TopoDS_Shape theShape = StdMeshers_ObjRefUlils::GeomObjectToShape( theShapeObject );
189 SMESH_Mesh_i* shrinkMesh_i = SMESH::DownCast< SMESH_Mesh_i* >( shrinkMesh );
190 SMESH_Mesh_i* theFinalMesh_i = SMESH::DownCast< SMESH_Mesh_i* >( finalMesh );
191 bool success = false;
195 success = GetImpl()->AddLayers( shrinkMesh_i->GetImpl(), theFinalMesh_i->GetImpl(), theShape );
197 catch ( std::exception& exc )
199 THROW_SALOME_CORBA_EXCEPTION( exc.what(), SALOME::INTERNAL_ERROR );
204 //=============================================================================
206 * StdMeshers_ViscousLayerBuilder_i::~StdMeshers_ViscousLayerBuilder_i
210 //=============================================================================
211 StdMeshers_ViscousLayerBuilder_i::~StdMeshers_ViscousLayerBuilder_i()