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
28 #include "StdMeshers_ProjectionSource2D.hxx"
30 #include "SMESH_Mesh.hxx"
32 #include "utilities.h"
38 //=============================================================================
40 * StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D
44 //=============================================================================
46 StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D(int hypId, int studyId,
48 : SMESH_Hypothesis(hypId, studyId, gen)
50 _name = "ProjectionSource2D"; // used by Projection_2D
51 _param_algo_dim = 2; // 2D
55 //=============================================================================
57 * StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D
61 //=============================================================================
63 StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D()
65 MESSAGE( "StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D" );
68 //=============================================================================
70 * Sets a source <face> to take a mesh pattern from
72 //=============================================================================
74 void StdMeshers_ProjectionSource2D::SetSourceFace(const TopoDS_Shape& Face)
75 throw ( SALOME_Exception )
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)
103 throw ( SALOME_Exception )
105 if ( sourceVertex1.IsNull() != targetVertex1.IsNull() ||
106 sourceVertex2.IsNull() != targetVertex2.IsNull() ||
107 sourceVertex1.IsNull() != targetVertex2.IsNull() )
108 throw SALOME_Exception(LOCALIZED("Two or none pairs of vertices must be provided"));
110 if ( !sourceVertex1.IsNull() ) {
111 if ( sourceVertex1.ShapeType() != TopAbs_VERTEX ||
112 sourceVertex2.ShapeType() != TopAbs_VERTEX ||
113 targetVertex1.ShapeType() != TopAbs_VERTEX ||
114 targetVertex2.ShapeType() != TopAbs_VERTEX )
115 throw SALOME_Exception(LOCALIZED("Wrong shape type"));
118 if ( !_sourceVertex1.IsSame( sourceVertex1 ) ||
119 !_sourceVertex2.IsSame( sourceVertex2 ) ||
120 !_targetVertex1.IsSame( targetVertex1 ) ||
121 !_targetVertex2.IsSame( targetVertex2 ) )
123 _sourceVertex1 = TopoDS::Vertex( sourceVertex1 );
124 _sourceVertex2 = TopoDS::Vertex( sourceVertex2 );
125 _targetVertex1 = TopoDS::Vertex( targetVertex1 );
126 _targetVertex2 = TopoDS::Vertex( targetVertex2 );
128 NotifySubMeshesHypothesisModification();
132 //=============================================================================
134 * Sets source <mesh> to take a mesh pattern from
136 //=============================================================================
138 void StdMeshers_ProjectionSource2D::SetSourceMesh(SMESH_Mesh* mesh)
140 if ( _sourceMesh != mesh )
141 NotifySubMeshesHypothesisModification();
145 //=============================================================================
147 * Returns the source face
149 //=============================================================================
151 TopoDS_Shape StdMeshers_ProjectionSource2D::GetSourceFace() const
156 //=============================================================================
158 * Returns the vertex associated with the target vertex.
159 * Result may be nil if association not set
161 //=============================================================================
163 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetSourceVertex(int i) const
164 throw ( SALOME_Exception )
167 return _sourceVertex1;
169 return _sourceVertex2;
171 throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
174 //=============================================================================
176 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
177 * Result may be nil if association not set.
179 //=============================================================================
181 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetTargetVertex(int i) const
182 throw ( SALOME_Exception )
185 return _targetVertex1;
187 return _targetVertex2;
189 throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
192 //=============================================================================
196 //=============================================================================
198 ostream & StdMeshers_ProjectionSource2D::SaveTo(ostream & save)
200 // we store it in order to be able to detect that hypo is really modified
201 save << " " << _sourceFace.TShape().operator->() ;
202 save << " " << _sourceVertex1.TShape().operator->();
203 save << " " << _targetVertex1.TShape().operator->();
204 save << " " << _sourceVertex2.TShape().operator->();
205 save << " " << _targetVertex2.TShape().operator->();
206 save << " " << ( _sourceMesh ? _sourceMesh->GetId() : -1 );
210 //=============================================================================
214 //=============================================================================
216 istream & StdMeshers_ProjectionSource2D::LoadFrom(istream & load)
218 // impossible to restore w/o any context
219 // It is done by servant
223 //=============================================================================
227 //=============================================================================
229 ostream & operator <<(ostream & save, StdMeshers_ProjectionSource2D & hyp)
231 return hyp.SaveTo( save );
234 //=============================================================================
238 //=============================================================================
240 istream & operator >>(istream & load, StdMeshers_ProjectionSource2D & hyp)
242 return hyp.LoadFrom( load );
245 //================================================================================
247 * \brief Initialize start and end length by the mesh built on the geometry
248 * \param theMesh - the built mesh
249 * \param theShape - the geometry of interest
250 * \retval bool - true if parameter values have been successfully defined
252 //================================================================================
254 bool StdMeshers_ProjectionSource2D::SetParametersByMesh(const SMESH_Mesh* ,
255 const TopoDS_Shape& )
260 //================================================================================
262 * \brief Return all parameters
264 //================================================================================
266 void StdMeshers_ProjectionSource2D::GetStoreParams(TopoDS_Shape& s1,
270 TopoDS_Shape& s5) const
279 //================================================================================
281 * \brief Set all parameters without notifying on modification
283 //================================================================================
285 void StdMeshers_ProjectionSource2D::RestoreParams(const TopoDS_Shape& s1,
286 const TopoDS_Shape& s2,
287 const TopoDS_Shape& s3,
288 const TopoDS_Shape& s4,
289 const TopoDS_Shape& s5,
293 _sourceVertex1 = TopoDS::Vertex( s2 );
294 _sourceVertex2 = TopoDS::Vertex( s3 );
295 _targetVertex1 = TopoDS::Vertex( s4 );
296 _targetVertex2 = TopoDS::Vertex( s5 );