1 // Copyright (C) 2007-2008 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
22 // SMESH SMESH : idl implementation based on 'SMESH' unit's classes
23 // File : StdMeshers_ProjectionSource2D.cxx
24 // Author : Edward AGAPOV
27 #include "StdMeshers_ProjectionSource2D.hxx"
29 #include "SMESH_Mesh.hxx"
31 #include "utilities.h"
37 //=============================================================================
39 * StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D
43 //=============================================================================
45 StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D(int hypId, int studyId,
47 : SMESH_Hypothesis(hypId, studyId, gen)
49 _name = "ProjectionSource2D"; // used by Projection_2D
50 _param_algo_dim = 2; // 2D
54 //=============================================================================
56 * StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D
60 //=============================================================================
62 StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D()
64 MESSAGE( "StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D" );
67 //=============================================================================
69 * Sets a source <face> to take a mesh pattern from
71 //=============================================================================
73 void StdMeshers_ProjectionSource2D::SetSourceFace(const TopoDS_Shape& Face)
74 throw ( SALOME_Exception )
77 throw SALOME_Exception(LOCALIZED("Null Face is not allowed"));
79 if ( Face.ShapeType() != TopAbs_FACE && Face.ShapeType() != TopAbs_COMPOUND )
80 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
82 if ( !_sourceFace.IsSame( Face ) )
86 NotifySubMeshesHypothesisModification();
90 //=============================================================================
92 * Sets vertex association between the source face and the target one.
93 * This parameter is optional.
94 * Two vertices must belong to one edge of a face
96 //=============================================================================
98 void StdMeshers_ProjectionSource2D::SetVertexAssociation(const TopoDS_Shape& sourceVertex1,
99 const TopoDS_Shape& sourceVertex2,
100 const TopoDS_Shape& targetVertex1,
101 const TopoDS_Shape& targetVertex2)
102 throw ( SALOME_Exception )
104 if ( sourceVertex1.IsNull() != targetVertex1.IsNull() ||
105 sourceVertex2.IsNull() != targetVertex2.IsNull() ||
106 sourceVertex1.IsNull() != targetVertex2.IsNull() )
107 throw SALOME_Exception(LOCALIZED("Two or none pairs of vertices must be provided"));
109 if ( !sourceVertex1.IsNull() ) {
110 if ( sourceVertex1.ShapeType() != TopAbs_VERTEX ||
111 sourceVertex2.ShapeType() != TopAbs_VERTEX ||
112 targetVertex1.ShapeType() != TopAbs_VERTEX ||
113 targetVertex2.ShapeType() != TopAbs_VERTEX )
114 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
117 if ( !_sourceVertex1.IsSame( sourceVertex1 ) ||
118 !_sourceVertex2.IsSame( sourceVertex2 ) ||
119 !_targetVertex1.IsSame( targetVertex1 ) ||
120 !_targetVertex2.IsSame( targetVertex2 ) )
122 _sourceVertex1 = TopoDS::Vertex( sourceVertex1 );
123 _sourceVertex2 = TopoDS::Vertex( sourceVertex2 );
124 _targetVertex1 = TopoDS::Vertex( targetVertex1 );
125 _targetVertex2 = TopoDS::Vertex( targetVertex2 );
127 NotifySubMeshesHypothesisModification();
131 //=============================================================================
133 * Sets source <mesh> to take a mesh pattern from
135 //=============================================================================
137 void StdMeshers_ProjectionSource2D::SetSourceMesh(SMESH_Mesh* mesh)
139 if ( _sourceMesh != mesh )
140 NotifySubMeshesHypothesisModification();
144 //=============================================================================
146 * Returns the source face
148 //=============================================================================
150 TopoDS_Shape StdMeshers_ProjectionSource2D::GetSourceFace() const
155 //=============================================================================
157 * Returns the vertex associated with the target vertex.
158 * Result may be nil if association not set
160 //=============================================================================
162 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetSourceVertex(int i) const
163 throw ( SALOME_Exception )
166 return _sourceVertex1;
168 return _sourceVertex2;
170 throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
173 //=============================================================================
175 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
176 * Result may be nil if association not set.
178 //=============================================================================
180 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetTargetVertex(int i) const
181 throw ( SALOME_Exception )
184 return _targetVertex1;
186 return _targetVertex2;
188 throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
191 //=============================================================================
195 //=============================================================================
197 ostream & StdMeshers_ProjectionSource2D::SaveTo(ostream & save)
199 // we store it in order to be able to detect that hypo is really modified
200 save << " " << _sourceFace.TShape().operator->() ;
201 save << " " << _sourceVertex1.TShape().operator->();
202 save << " " << _targetVertex1.TShape().operator->();
203 save << " " << _sourceVertex2.TShape().operator->();
204 save << " " << _targetVertex2.TShape().operator->();
205 save << " " << ( _sourceMesh ? _sourceMesh->GetId() : -1 );
209 //=============================================================================
213 //=============================================================================
215 istream & StdMeshers_ProjectionSource2D::LoadFrom(istream & load)
217 // impossible to restore w/o any context
218 // It is done by servant
222 //=============================================================================
226 //=============================================================================
228 ostream & operator <<(ostream & save, StdMeshers_ProjectionSource2D & hyp)
230 return hyp.SaveTo( save );
233 //=============================================================================
237 //=============================================================================
239 istream & operator >>(istream & load, StdMeshers_ProjectionSource2D & hyp)
241 return hyp.LoadFrom( load );
244 //================================================================================
246 * \brief Initialize start and end length by the mesh built on the geometry
247 * \param theMesh - the built mesh
248 * \param theShape - the geometry of interest
249 * \retval bool - true if parameter values have been successfully defined
251 //================================================================================
253 bool StdMeshers_ProjectionSource2D::SetParametersByMesh(const SMESH_Mesh* ,
254 const TopoDS_Shape& )
259 //================================================================================
261 * \brief Return all parameters
263 //================================================================================
265 void StdMeshers_ProjectionSource2D::GetStoreParams(TopoDS_Shape& s1,
269 TopoDS_Shape& s5) const
278 //================================================================================
280 * \brief Set all parameters without notifying on modification
282 //================================================================================
284 void StdMeshers_ProjectionSource2D::RestoreParams(const TopoDS_Shape& s1,
285 const TopoDS_Shape& s2,
286 const TopoDS_Shape& s3,
287 const TopoDS_Shape& s4,
288 const TopoDS_Shape& s5,
292 _sourceVertex1 = TopoDS::Vertex( s2 );
293 _sourceVertex2 = TopoDS::Vertex( s3 );
294 _targetVertex1 = TopoDS::Vertex( s4 );
295 _targetVertex2 = TopoDS::Vertex( s5 );
299 //================================================================================
301 * \brief Initialize my parameter values by default parameters.
302 * \retval bool - true if parameter values have been successfully defined
304 //================================================================================
306 bool StdMeshers_ProjectionSource2D::SetParametersByDefaults(const TDefaults& /*dflts*/,
307 const SMESH_Mesh* /*theMesh*/)