1 // SMESH SMESH : idl implementation based on 'SMESH' unit's classes
3 // Copyright (C) 2003 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
24 // File : StdMeshers_ProjectionSource2D.cxx
25 // Author : Edward AGAPOV
30 #include "StdMeshers_ProjectionSource2D.hxx"
32 #include "SMESH_Mesh.hxx"
34 #include "utilities.h"
40 //=============================================================================
42 * StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D
46 //=============================================================================
48 StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D(int hypId, int studyId,
50 : SMESH_Hypothesis(hypId, studyId, 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()
67 MESSAGE( "StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D" );
70 //=============================================================================
72 * Sets a source <face> to take a mesh pattern from
74 //=============================================================================
76 void StdMeshers_ProjectionSource2D::SetSourceFace(const TopoDS_Shape& Face)
77 throw ( SALOME_Exception )
80 throw SALOME_Exception(LOCALIZED("Null Face is not allowed"));
82 if ( Face.ShapeType() != TopAbs_FACE )
83 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
85 if ( !_sourceFace.IsSame( Face ) )
87 _sourceFace = TopoDS::Face( Face );
89 NotifySubMeshesHypothesisModification();
93 //=============================================================================
95 * Sets vertex association between the source face and the target one.
96 * This parameter is optional.
97 * Two vertices must belong to one edge of a face
99 //=============================================================================
101 void StdMeshers_ProjectionSource2D::SetVertexAssociation(const TopoDS_Shape& sourceVertex1,
102 const TopoDS_Shape& sourceVertex2,
103 const TopoDS_Shape& targetVertex1,
104 const TopoDS_Shape& targetVertex2)
105 throw ( SALOME_Exception )
107 if ( sourceVertex1.IsNull() != targetVertex1.IsNull() ||
108 sourceVertex2.IsNull() != targetVertex2.IsNull() ||
109 sourceVertex1.IsNull() != targetVertex2.IsNull() )
110 throw SALOME_Exception(LOCALIZED("Two or none pairs of vertices must be provided"));
112 if ( !sourceVertex1.IsNull() ) {
113 if ( sourceVertex1.ShapeType() != TopAbs_VERTEX ||
114 sourceVertex2.ShapeType() != TopAbs_VERTEX ||
115 targetVertex1.ShapeType() != TopAbs_VERTEX ||
116 targetVertex2.ShapeType() != TopAbs_VERTEX )
117 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
120 if ( !_sourceVertex1.IsSame( sourceVertex1 ) ||
121 !_sourceVertex2.IsSame( sourceVertex2 ) ||
122 !_targetVertex1.IsSame( targetVertex1 ) ||
123 !_targetVertex2.IsSame( targetVertex2 ) )
125 _sourceVertex1 = TopoDS::Vertex( sourceVertex1 );
126 _sourceVertex2 = TopoDS::Vertex( sourceVertex2 );
127 _targetVertex1 = TopoDS::Vertex( targetVertex1 );
128 _targetVertex2 = TopoDS::Vertex( targetVertex2 );
130 NotifySubMeshesHypothesisModification();
134 //=============================================================================
136 * Returns the source face
138 //=============================================================================
140 TopoDS_Face StdMeshers_ProjectionSource2D::GetSourceFace() const
145 //=============================================================================
147 * Returns the vertex associated with the target vertex.
148 * Result may be nil if association not set
150 //=============================================================================
152 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetSourceVertex(int i) const
153 throw ( SALOME_Exception )
156 return _sourceVertex1;
158 return _sourceVertex2;
160 throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
163 //=============================================================================
165 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
166 * Result may be nil if association not set.
168 //=============================================================================
170 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetTargetVertex(int i) const
171 throw ( SALOME_Exception )
174 return _targetVertex1;
176 return _targetVertex2;
178 throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
181 //=============================================================================
185 //=============================================================================
187 ostream & StdMeshers_ProjectionSource2D::SaveTo(ostream & save)
189 // we store it in order to be able to detect that hypo is really modified
190 save << " " << _sourceFace.TShape().operator->() ;
191 save << " " << _sourceVertex1.TShape().operator->();
192 save << " " << _targetVertex1.TShape().operator->();
193 save << " " << _sourceVertex2.TShape().operator->();
194 save << " " << _targetVertex2.TShape().operator->();
195 save << " " << ( _sourceMesh ? _sourceMesh->GetId() : -1 );
199 //=============================================================================
203 //=============================================================================
205 istream & StdMeshers_ProjectionSource2D::LoadFrom(istream & load)
207 // impossible to restore w/o any context
208 // It is done by servant
212 //=============================================================================
216 //=============================================================================
218 ostream & operator <<(ostream & save, StdMeshers_ProjectionSource2D & hyp)
220 return hyp.SaveTo( save );
223 //=============================================================================
227 //=============================================================================
229 istream & operator >>(istream & load, StdMeshers_ProjectionSource2D & hyp)
231 return hyp.LoadFrom( load );
234 //================================================================================
236 * \brief Initialize start and end length by the mesh built on the geometry
237 * \param theMesh - the built mesh
238 * \param theShape - the geometry of interest
239 * \retval bool - true if parameter values have been successfully defined
241 //================================================================================
243 bool StdMeshers_ProjectionSource2D::SetParametersByMesh(const SMESH_Mesh* ,
244 const TopoDS_Shape& )
249 //================================================================================
251 * \brief Return all parameters
253 //================================================================================
255 void StdMeshers_ProjectionSource2D::GetStoreParams(TopoDS_Shape& s1,
259 TopoDS_Shape& s5) const
268 //================================================================================
270 * \brief Set all parameters without notifying on modification
272 //================================================================================
274 void StdMeshers_ProjectionSource2D::RestoreParams(const TopoDS_Shape& s1,
275 const TopoDS_Shape& s2,
276 const TopoDS_Shape& s3,
277 const TopoDS_Shape& s4,
278 const TopoDS_Shape& s5,
281 _sourceFace = TopoDS::Face( s1 );
282 _sourceVertex1 = TopoDS::Vertex( s2 );
283 _sourceVertex2 = TopoDS::Vertex( s3 );
284 _targetVertex1 = TopoDS::Vertex( s4 );
285 _targetVertex2 = TopoDS::Vertex( s5 );