1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH : idl implementation based on 'SMESH' unit's classes
24 // File : StdMeshers_ProjectionSource2D.cxx
25 // Author : Edward AGAPOV
28 #include "StdMeshers_ProjectionSource2D.hxx"
30 #include "SMESH_Mesh.hxx"
31 #include "SMESH_MesherHelper.hxx"
32 #include "StdMeshers_ProjectionUtils.hxx"
34 #include "utilities.h"
40 //=============================================================================
42 * StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D
46 //=============================================================================
48 StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D(int hypId,
50 : SMESH_Hypothesis(hypId, gen)
52 _name = "ProjectionSource2D"; // used by Projection_2D
53 _param_algo_dim = 2; // 2D
57 //=============================================================================
59 * StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D
63 //=============================================================================
65 StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D()
69 //=============================================================================
71 * Sets a source <face> to take a mesh pattern from
73 //=============================================================================
75 void StdMeshers_ProjectionSource2D::SetSourceFace(const TopoDS_Shape& Face)
78 throw SALOME_Exception(LOCALIZED("Null Face is not allowed"));
80 if ( Face.ShapeType() != TopAbs_FACE && Face.ShapeType() != TopAbs_COMPOUND )
81 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
83 if ( !_sourceFace.IsSame( Face ) )
87 NotifySubMeshesHypothesisModification();
91 //=============================================================================
93 * Sets vertex association between the source face and the target one.
94 * This parameter is optional.
95 * Two vertices must belong to one edge of a face
97 //=============================================================================
99 void StdMeshers_ProjectionSource2D::SetVertexAssociation(const TopoDS_Shape& sourceVertex1,
100 const TopoDS_Shape& sourceVertex2,
101 const TopoDS_Shape& targetVertex1,
102 const TopoDS_Shape& targetVertex2)
104 if ( sourceVertex1.IsNull() != targetVertex1.IsNull() ||
105 sourceVertex2.IsNull() != targetVertex2.IsNull() )
106 throw SALOME_Exception(LOCALIZED("Vertices must be provided in couples"));
108 if ( sourceVertex1.IsNull() != sourceVertex2.IsNull() )
110 // possibly there is only 1 vertex in the face
111 if ( !_sourceFace.IsNull() &&
112 SMESH_MesherHelper::Count( _sourceFace, TopAbs_VERTEX, /*ignoreSame=*/true) != 1 )
113 throw SALOME_Exception(LOCALIZED("Two or none pairs of vertices must be provided"));
116 if ( !sourceVertex1.IsNull() )
117 if ( sourceVertex1.ShapeType() != TopAbs_VERTEX ||
118 targetVertex1.ShapeType() != TopAbs_VERTEX )
119 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
121 if ( !sourceVertex2.IsNull() )
122 if ( sourceVertex2.ShapeType() != TopAbs_VERTEX ||
123 targetVertex2.ShapeType() != TopAbs_VERTEX )
124 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
127 if ( !_sourceVertex1.IsSame( sourceVertex1 ) ||
128 !_sourceVertex2.IsSame( sourceVertex2 ) ||
129 !_targetVertex1.IsSame( targetVertex1 ) ||
130 !_targetVertex2.IsSame( targetVertex2 ) )
132 _sourceVertex1 = TopoDS::Vertex( sourceVertex1 );
133 _sourceVertex2 = TopoDS::Vertex( sourceVertex2 );
134 _targetVertex1 = TopoDS::Vertex( targetVertex1 );
135 _targetVertex2 = TopoDS::Vertex( targetVertex2 );
137 NotifySubMeshesHypothesisModification();
141 //=============================================================================
143 * Sets source <mesh> to take a mesh pattern from
145 //=============================================================================
147 void StdMeshers_ProjectionSource2D::SetSourceMesh(SMESH_Mesh* mesh)
149 if ( _sourceMesh != mesh ) {
151 NotifySubMeshesHypothesisModification();
155 //=============================================================================
157 * Returns the source face
159 //=============================================================================
161 TopoDS_Shape StdMeshers_ProjectionSource2D::GetSourceFace() const
166 //=============================================================================
168 * Returns the vertex associated with the target vertex.
169 * Result may be nil if association not set
171 //=============================================================================
173 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetSourceVertex(int i) const
176 return _sourceVertex1;
178 return _sourceVertex2;
180 throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
183 //=============================================================================
185 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
186 * Result may be nil if association not set.
188 //=============================================================================
190 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetTargetVertex(int i) const
193 return _targetVertex1;
195 return _targetVertex2;
197 throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
200 //=============================================================================
204 //=============================================================================
206 ostream & StdMeshers_ProjectionSource2D::SaveTo(ostream & save)
208 // we store it in order to be able to detect that hypo is really modified
209 save << " " << _sourceFace.TShape().operator->() ;
210 save << " " << _sourceVertex1.TShape().operator->();
211 save << " " << _targetVertex1.TShape().operator->();
212 save << " " << _sourceVertex2.TShape().operator->();
213 save << " " << _targetVertex2.TShape().operator->();
214 save << " " << ( _sourceMesh ? _sourceMesh->GetId() : -1 );
218 //=============================================================================
222 //=============================================================================
224 istream & StdMeshers_ProjectionSource2D::LoadFrom(istream & load)
226 // impossible to restore w/o any context
227 // It is done by servant
231 //=============================================================================
235 //=============================================================================
237 ostream & operator <<(ostream & save, StdMeshers_ProjectionSource2D & hyp)
239 return hyp.SaveTo( save );
242 //=============================================================================
246 //=============================================================================
248 istream & operator >>(istream & load, StdMeshers_ProjectionSource2D & hyp)
250 return hyp.LoadFrom( load );
253 //================================================================================
255 * \brief Initialize start and end length by the mesh built on the geometry
256 * \param theMesh - the built mesh
257 * \param theShape - the geometry of interest
258 * \retval bool - true if parameter values have been successfully defined
260 //================================================================================
262 bool StdMeshers_ProjectionSource2D::SetParametersByMesh(const SMESH_Mesh* ,
263 const TopoDS_Shape& )
268 //================================================================================
270 * \brief Return all parameters
272 //================================================================================
274 void StdMeshers_ProjectionSource2D::GetStoreParams(TopoDS_Shape& s1,
278 TopoDS_Shape& s5) const
287 //================================================================================
289 * \brief Set all parameters without notifying on modification
291 //================================================================================
293 void StdMeshers_ProjectionSource2D::RestoreParams(const TopoDS_Shape& s1,
294 const TopoDS_Shape& s2,
295 const TopoDS_Shape& s3,
296 const TopoDS_Shape& s4,
297 const TopoDS_Shape& s5,
301 _sourceVertex1 = TopoDS::Vertex( s2 );
302 _sourceVertex2 = TopoDS::Vertex( s3 );
303 _targetVertex1 = TopoDS::Vertex( s4 );
304 _targetVertex2 = TopoDS::Vertex( s5 );
308 //================================================================================
310 * \brief Initialize my parameter values by default parameters.
311 * \retval bool - true if parameter values have been successfully defined
313 //================================================================================
315 bool StdMeshers_ProjectionSource2D::SetParametersByDefaults(const TDefaults& /*dflts*/,
316 const SMESH_Mesh* /*theMesh*/)