Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_BlockRenumber_i.cxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
24 //  File   : StdMeshers_BlockRenumber_i.cxx
25 //  Author : Edward AGAPOV
26 //  Module : SMESH
27 //  $Header$
28 //
29 #include "StdMeshers_ObjRefUlils.hxx"
30 #include "StdMeshers_BlockRenumber_i.hxx"
31 #include "SMESH_Gen_i.hxx"
32 #include "SMESH_Gen.hxx"
33 #include "SMESH_PythonDump.hxx"
34
35 #include "Utils_CorbaException.hxx"
36
37 //=============================================================================
38 /*!
39  *  StdMeshers_BlockRenumber_i::StdMeshers_BlockRenumber_i
40  *
41  *  Constructor
42  */
43 //=============================================================================
44
45 StdMeshers_BlockRenumber_i::StdMeshers_BlockRenumber_i( PortableServer::POA_ptr thePOA,
46                                                         ::SMESH_Gen*            theGenImpl )
47   : SALOME::GenericObj_i( thePOA ),
48     SMESH_Hypothesis_i( thePOA )
49 {
50   myBaseImpl = new ::StdMeshers_BlockRenumber( theGenImpl->GetANewId(),
51                                                theGenImpl );
52 }
53
54 //================================================================================
55 /*!
56  * \brief Set orientation of blocks
57  */
58 //================================================================================
59
60 void StdMeshers_BlockRenumber_i::SetBlocksOrientation( const StdMeshers::blockcs_array& blockCS )
61 {
62   try {
63     SMESH_Comment dump;
64     CORBA::String_var entry;
65     std::vector< StdMeshers_BlockCS > bcsVec( blockCS.length() );
66     for ( size_t i = 0; i < bcsVec.size(); i++ )
67     {
68       StdMeshers_BlockCS& bcs = bcsVec[i];
69       if ( !CORBA::is_nil( blockCS[i].solid )    &&
70            !CORBA::is_nil( blockCS[i].vertex000 )&&
71            !CORBA::is_nil( blockCS[i].vertex001 ))
72       {
73         entry          = blockCS[i].solid->GetStudyEntry();
74         bcs._solid     = entry.in();
75         entry          = blockCS[i].vertex000->GetStudyEntry();
76         bcs._vertex000 = entry.in();
77         entry          = blockCS[i].vertex001->GetStudyEntry();
78         bcs._vertex001 = entry.in();
79
80         if ( !dump.empty() ) dump << ",\n    ";
81         dump << "StdMeshers.BlockCS( "
82              << bcs._solid << ", " << bcs._vertex000 << ", " << bcs._vertex001
83              << " )";
84       }
85     }
86     this->GetImpl()->SetBlocksOrientation( bcsVec );
87
88     // Update Python script
89     SMESH::TPythonDump() << _this() << ".SetBlocksOrientation([ " << dump << " ])";
90   }
91   catch ( SALOME_Exception& S_ex ) {
92     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
93   }
94 }
95
96 //================================================================================
97 /*!
98  * \brief Return orientation of blocks
99  */
100 //================================================================================
101
102 StdMeshers::blockcs_array*  StdMeshers_BlockRenumber_i::GetBlocksOrientation()
103 {
104   const std::vector< StdMeshers_BlockCS >& bcsVec =  this->GetImpl()->GetBlocksOrientation();
105   StdMeshers::blockcs_array_var          bcsArray = new StdMeshers::blockcs_array();
106   bcsArray->length( bcsVec.size() );
107   TopoDS_Shape nullShape;
108   for ( size_t i = 0; i < bcsVec.size(); ++i )
109   {
110     bcsArray[i].solid =
111       StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject( bcsVec[i]._solid, nullShape );
112     bcsArray[i].vertex000 =
113       StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject( bcsVec[i]._vertex000, nullShape );
114     bcsArray[i].vertex001 =
115       StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject( bcsVec[i]._vertex001, nullShape );
116   }
117   return bcsArray._retn();
118 }
119
120 //================================================================================
121 /*!
122  * \brief Return geom entries
123  */
124 //================================================================================
125
126 bool
127 StdMeshers_BlockRenumber_i::getObjectsDependOn( std::vector< std::string > & entryArray,
128                                                 std::vector< int >         & /*subIDArray*/ ) const
129 {
130   const std::vector< StdMeshers_BlockCS >& bcsVec =
131     const_cast<StdMeshers_BlockRenumber_i*>(this)->GetImpl()->GetBlocksOrientation();
132   entryArray.reserve( entryArray.capacity() + 3 * bcsVec.size());
133   for ( size_t i = 0; i < bcsVec.size(); ++i )
134   {
135     entryArray.push_back( bcsVec[i]._solid     );
136     entryArray.push_back( bcsVec[i]._vertex000 );
137     entryArray.push_back( bcsVec[i]._vertex001 );
138   }
139   return !bcsVec.empty();
140 }
141
142 //================================================================================
143 /*!
144  * \brief Update geom entries for a new geometry
145  */
146 //================================================================================
147
148 bool StdMeshers_BlockRenumber_i::setObjectsDependOn( std::vector< std::string > & entryArray,
149                                                      std::vector< int >         & /*subIDArray*/ )
150 {
151   std::vector< StdMeshers_BlockCS > bcsVec( entryArray.size() / 3 );
152   for ( size_t i = 0; i + 2 < entryArray.size(); i += 3 )
153   {
154     StdMeshers_BlockCS& bcs = bcsVec[i];
155     bcs._solid     = entryArray[ i ];
156     bcs._vertex000 = entryArray[ i + 1 ];
157     bcs._vertex001 = entryArray[ i + 2 ];
158   }
159   this->GetImpl()->SetBlocksOrientation( bcsVec );
160   return true;
161 }
162
163
164 //=============================================================================
165 /*!
166  *  StdMeshers_BlockRenumber_i::GetImpl
167  *
168  *  Get implementation
169  */
170 //=============================================================================
171
172 ::StdMeshers_BlockRenumber* StdMeshers_BlockRenumber_i::GetImpl()
173 {
174   return ( ::StdMeshers_BlockRenumber* )myBaseImpl;
175 }
176
177 //================================================================================
178 /*!
179  * \brief Verify whether hypothesis supports given entity type
180  * \param type - dimension (see SMESH::Dimension enumeration)
181  * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
182  *
183  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
184  */
185 //================================================================================
186 CORBA::Boolean StdMeshers_BlockRenumber_i::IsDimSupported( SMESH::Dimension type )
187 {
188   return type == SMESH::DIM_3D;
189 }
190