1 // Copyright (C) 2007-2012 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.
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 "StdMeshers_ProjectionUtils.hxx"
33 #include "utilities.h"
39 //=============================================================================
41 * StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D
45 //=============================================================================
47 StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D(int hypId, int studyId,
49 : SMESH_Hypothesis(hypId, studyId, gen)
51 _name = "ProjectionSource2D"; // used by Projection_2D
52 _param_algo_dim = 2; // 2D
56 //=============================================================================
58 * StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D
62 //=============================================================================
64 StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D()
66 MESSAGE( "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)
76 throw ( SALOME_Exception )
79 throw SALOME_Exception(LOCALIZED("Null Face is not allowed"));
81 if ( Face.ShapeType() != TopAbs_FACE && Face.ShapeType() != TopAbs_COMPOUND )
82 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
84 if ( !_sourceFace.IsSame( Face ) )
88 NotifySubMeshesHypothesisModification();
92 //=============================================================================
94 * Sets vertex association between the source face and the target one.
95 * This parameter is optional.
96 * Two vertices must belong to one edge of a face
98 //=============================================================================
100 void StdMeshers_ProjectionSource2D::SetVertexAssociation(const TopoDS_Shape& sourceVertex1,
101 const TopoDS_Shape& sourceVertex2,
102 const TopoDS_Shape& targetVertex1,
103 const TopoDS_Shape& targetVertex2)
104 throw ( SALOME_Exception )
106 if ( sourceVertex1.IsNull() != targetVertex1.IsNull() ||
107 sourceVertex2.IsNull() != targetVertex2.IsNull() )
108 throw SALOME_Exception(LOCALIZED("Vertices must be provided in couples"));
110 if ( sourceVertex1.IsNull() != sourceVertex2.IsNull() )
112 // possibly there is only 1 vertex in the face
113 if ( !_sourceFace.IsNull() &&
114 StdMeshers_ProjectionUtils::Count( _sourceFace, TopAbs_VERTEX, /*ignoreSame=*/true) != 1 )
115 throw SALOME_Exception(LOCALIZED("Two or none pairs of vertices must be provided"));
118 if ( !sourceVertex1.IsNull() )
119 if ( sourceVertex1.ShapeType() != TopAbs_VERTEX ||
120 targetVertex1.ShapeType() != TopAbs_VERTEX )
121 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
123 if ( !sourceVertex2.IsNull() )
124 if ( sourceVertex2.ShapeType() != TopAbs_VERTEX ||
125 targetVertex2.ShapeType() != TopAbs_VERTEX )
126 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
129 if ( !_sourceVertex1.IsSame( sourceVertex1 ) ||
130 !_sourceVertex2.IsSame( sourceVertex2 ) ||
131 !_targetVertex1.IsSame( targetVertex1 ) ||
132 !_targetVertex2.IsSame( targetVertex2 ) )
134 _sourceVertex1 = TopoDS::Vertex( sourceVertex1 );
135 _sourceVertex2 = TopoDS::Vertex( sourceVertex2 );
136 _targetVertex1 = TopoDS::Vertex( targetVertex1 );
137 _targetVertex2 = TopoDS::Vertex( targetVertex2 );
139 NotifySubMeshesHypothesisModification();
143 //=============================================================================
145 * Sets source <mesh> to take a mesh pattern from
147 //=============================================================================
149 void StdMeshers_ProjectionSource2D::SetSourceMesh(SMESH_Mesh* mesh)
151 if ( _sourceMesh != mesh ) {
153 NotifySubMeshesHypothesisModification();
157 //=============================================================================
159 * Returns the source face
161 //=============================================================================
163 TopoDS_Shape StdMeshers_ProjectionSource2D::GetSourceFace() const
168 //=============================================================================
170 * Returns the vertex associated with the target vertex.
171 * Result may be nil if association not set
173 //=============================================================================
175 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetSourceVertex(int i) const
176 throw ( SALOME_Exception )
179 return _sourceVertex1;
181 return _sourceVertex2;
183 throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
186 //=============================================================================
188 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
189 * Result may be nil if association not set.
191 //=============================================================================
193 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetTargetVertex(int i) const
194 throw ( SALOME_Exception )
197 return _targetVertex1;
199 return _targetVertex2;
201 throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
204 //=============================================================================
208 //=============================================================================
210 ostream & StdMeshers_ProjectionSource2D::SaveTo(ostream & save)
212 // we store it in order to be able to detect that hypo is really modified
213 save << " " << _sourceFace.TShape().operator->() ;
214 save << " " << _sourceVertex1.TShape().operator->();
215 save << " " << _targetVertex1.TShape().operator->();
216 save << " " << _sourceVertex2.TShape().operator->();
217 save << " " << _targetVertex2.TShape().operator->();
218 save << " " << ( _sourceMesh ? _sourceMesh->GetId() : -1 );
222 //=============================================================================
226 //=============================================================================
228 istream & StdMeshers_ProjectionSource2D::LoadFrom(istream & load)
230 // impossible to restore w/o any context
231 // It is done by servant
235 //=============================================================================
239 //=============================================================================
241 ostream & operator <<(ostream & save, StdMeshers_ProjectionSource2D & hyp)
243 return hyp.SaveTo( save );
246 //=============================================================================
250 //=============================================================================
252 istream & operator >>(istream & load, StdMeshers_ProjectionSource2D & hyp)
254 return hyp.LoadFrom( load );
257 //================================================================================
259 * \brief Initialize start and end length by the mesh built on the geometry
260 * \param theMesh - the built mesh
261 * \param theShape - the geometry of interest
262 * \retval bool - true if parameter values have been successfully defined
264 //================================================================================
266 bool StdMeshers_ProjectionSource2D::SetParametersByMesh(const SMESH_Mesh* ,
267 const TopoDS_Shape& )
272 //================================================================================
274 * \brief Return all parameters
276 //================================================================================
278 void StdMeshers_ProjectionSource2D::GetStoreParams(TopoDS_Shape& s1,
282 TopoDS_Shape& s5) const
291 //================================================================================
293 * \brief Set all parameters without notifying on modification
295 //================================================================================
297 void StdMeshers_ProjectionSource2D::RestoreParams(const TopoDS_Shape& s1,
298 const TopoDS_Shape& s2,
299 const TopoDS_Shape& s3,
300 const TopoDS_Shape& s4,
301 const TopoDS_Shape& s5,
305 _sourceVertex1 = TopoDS::Vertex( s2 );
306 _sourceVertex2 = TopoDS::Vertex( s3 );
307 _targetVertex1 = TopoDS::Vertex( s4 );
308 _targetVertex2 = TopoDS::Vertex( s5 );
312 //================================================================================
314 * \brief Initialize my parameter values by default parameters.
315 * \retval bool - true if parameter values have been successfully defined
317 //================================================================================
319 bool StdMeshers_ProjectionSource2D::SetParametersByDefaults(const TDefaults& /*dflts*/,
320 const SMESH_Mesh* /*theMesh*/)