Back to index

salome-smesh  6.5.0
StdMeshers_ProjectionSource2D.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESH : idl implementation based on 'SMESH' unit's classes
00024 //  File   : StdMeshers_ProjectionSource2D.cxx
00025 //  Author : Edward AGAPOV
00026 //  Module : SMESH
00027 //
00028 #include "StdMeshers_ProjectionSource2D.hxx"
00029 
00030 #include "SMESH_Mesh.hxx"
00031 #include "StdMeshers_ProjectionUtils.hxx"
00032 
00033 #include "utilities.h"
00034 
00035 #include <TopoDS.hxx>
00036 
00037 using namespace std;
00038 
00039 //=============================================================================
00045 //=============================================================================
00046 
00047 StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D(int hypId, int studyId,
00048                                                              SMESH_Gen * gen)
00049   : SMESH_Hypothesis(hypId, studyId, gen)
00050 {
00051   _name = "ProjectionSource2D"; // used by Projection_2D
00052   _param_algo_dim = 2; // 2D
00053   _sourceMesh = 0;
00054 }
00055 
00056 //=============================================================================
00062 //=============================================================================
00063 
00064 StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D()
00065 {
00066   MESSAGE( "StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D" );
00067 }
00068 
00069 //=============================================================================
00073 //=============================================================================
00074 
00075 void StdMeshers_ProjectionSource2D::SetSourceFace(const TopoDS_Shape& Face)
00076   throw ( SALOME_Exception )
00077 {
00078   if ( Face.IsNull() )
00079     throw SALOME_Exception(LOCALIZED("Null Face is not allowed"));
00080 
00081   if ( Face.ShapeType() != TopAbs_FACE && Face.ShapeType() != TopAbs_COMPOUND )
00082     throw SALOME_Exception(LOCALIZED("Wrong shape type"));
00083 
00084   if ( !_sourceFace.IsSame( Face ) )
00085   {
00086     _sourceFace = Face;
00087 
00088     NotifySubMeshesHypothesisModification();
00089   }
00090 }
00091 
00092 //=============================================================================
00098 //=============================================================================
00099 
00100 void StdMeshers_ProjectionSource2D::SetVertexAssociation(const TopoDS_Shape& sourceVertex1,
00101                                                          const TopoDS_Shape& sourceVertex2,
00102                                                          const TopoDS_Shape& targetVertex1,
00103                                                          const TopoDS_Shape& targetVertex2)
00104   throw ( SALOME_Exception )
00105 {
00106   if ( sourceVertex1.IsNull() != targetVertex1.IsNull() ||
00107        sourceVertex2.IsNull() != targetVertex2.IsNull() )
00108     throw SALOME_Exception(LOCALIZED("Vertices must be provided in couples"));
00109 
00110   if ( sourceVertex1.IsNull() != sourceVertex2.IsNull() )
00111   {
00112     // possibly there is only 1 vertex in the face
00113     if ( !_sourceFace.IsNull() &&
00114          StdMeshers_ProjectionUtils::Count( _sourceFace, TopAbs_VERTEX, /*ignoreSame=*/true) != 1 )
00115       throw SALOME_Exception(LOCALIZED("Two or none pairs of vertices must be provided"));
00116   }
00117 
00118   if ( !sourceVertex1.IsNull() )
00119     if ( sourceVertex1.ShapeType() != TopAbs_VERTEX ||
00120          targetVertex1.ShapeType() != TopAbs_VERTEX )
00121       throw SALOME_Exception(LOCALIZED("Wrong shape type"));
00122 
00123   if ( !sourceVertex2.IsNull() )
00124     if ( sourceVertex2.ShapeType() != TopAbs_VERTEX ||
00125          targetVertex2.ShapeType() != TopAbs_VERTEX )
00126       throw SALOME_Exception(LOCALIZED("Wrong shape type"));
00127 
00128 
00129   if ( !_sourceVertex1.IsSame( sourceVertex1 ) ||
00130        !_sourceVertex2.IsSame( sourceVertex2 ) ||
00131        !_targetVertex1.IsSame( targetVertex1 ) ||
00132        !_targetVertex2.IsSame( targetVertex2 ) )
00133   {
00134     _sourceVertex1 = TopoDS::Vertex( sourceVertex1 );
00135     _sourceVertex2 = TopoDS::Vertex( sourceVertex2 );
00136     _targetVertex1 = TopoDS::Vertex( targetVertex1 );
00137     _targetVertex2 = TopoDS::Vertex( targetVertex2 );
00138 
00139     NotifySubMeshesHypothesisModification();
00140   }
00141 }
00142 
00143 //=============================================================================
00147 //=============================================================================
00148 
00149 void StdMeshers_ProjectionSource2D::SetSourceMesh(SMESH_Mesh* mesh)
00150 {
00151   if ( _sourceMesh != mesh ) {
00152     _sourceMesh = mesh;
00153     NotifySubMeshesHypothesisModification();
00154   }
00155 }
00156 
00157 //=============================================================================
00161 //=============================================================================
00162 
00163 TopoDS_Shape StdMeshers_ProjectionSource2D::GetSourceFace() const
00164 {
00165   return _sourceFace;
00166 }
00167 
00168 //=============================================================================
00173 //=============================================================================
00174 
00175 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetSourceVertex(int i) const
00176   throw ( SALOME_Exception )
00177 {
00178   if ( i == 1 )
00179     return _sourceVertex1;
00180   else if ( i == 2 )
00181     return _sourceVertex2;
00182   else
00183     throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
00184 }
00185 
00186 //=============================================================================
00191 //=============================================================================
00192 
00193 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetTargetVertex(int i) const
00194   throw ( SALOME_Exception )
00195 {
00196   if ( i == 1 )
00197     return _targetVertex1;
00198   else if ( i == 2 )
00199     return _targetVertex2;
00200   else
00201     throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
00202 }
00203 
00204 //=============================================================================
00208 //=============================================================================
00209 
00210 ostream & StdMeshers_ProjectionSource2D::SaveTo(ostream & save)
00211 {
00212   // we store it in order to be able to detect that hypo is really modified
00213   save << " " << _sourceFace.TShape().operator->()  ;
00214   save << " " << _sourceVertex1.TShape().operator->();
00215   save << " " << _targetVertex1.TShape().operator->();
00216   save << " " << _sourceVertex2.TShape().operator->();
00217   save << " " << _targetVertex2.TShape().operator->();
00218   save << " " << ( _sourceMesh ? _sourceMesh->GetId() : -1 );
00219   return save;
00220 }
00221 
00222 //=============================================================================
00226 //=============================================================================
00227 
00228 istream & StdMeshers_ProjectionSource2D::LoadFrom(istream & load)
00229 {
00230   // impossible to restore w/o any context
00231   // It is done by servant
00232   return load;
00233 }
00234 
00235 //=============================================================================
00239 //=============================================================================
00240 
00241 ostream & operator <<(ostream & save, StdMeshers_ProjectionSource2D & hyp)
00242 {
00243   return hyp.SaveTo( save );
00244 }
00245 
00246 //=============================================================================
00250 //=============================================================================
00251 
00252 istream & operator >>(istream & load, StdMeshers_ProjectionSource2D & hyp)
00253 {
00254   return hyp.LoadFrom( load );
00255 }
00256 
00257 //================================================================================
00264 //================================================================================
00265 
00266 bool StdMeshers_ProjectionSource2D::SetParametersByMesh(const SMESH_Mesh*   ,
00267                                                         const TopoDS_Shape& )
00268 {
00269   return false;
00270 }
00271 
00272 //================================================================================
00276 //================================================================================
00277 
00278 void StdMeshers_ProjectionSource2D::GetStoreParams(TopoDS_Shape& s1,
00279                                                    TopoDS_Shape& s2,
00280                                                    TopoDS_Shape& s3,
00281                                                    TopoDS_Shape& s4,
00282                                                    TopoDS_Shape& s5) const
00283 {
00284   s1 = _sourceFace;
00285   s2 = _sourceVertex1;
00286   s3 = _sourceVertex2;
00287   s4 = _targetVertex1;
00288   s5 = _targetVertex2;
00289 }
00290 
00291 //================================================================================
00295 //================================================================================
00296 
00297 void StdMeshers_ProjectionSource2D::RestoreParams(const TopoDS_Shape& s1,
00298                                                   const TopoDS_Shape& s2,
00299                                                   const TopoDS_Shape& s3,
00300                                                   const TopoDS_Shape& s4,
00301                                                   const TopoDS_Shape& s5,
00302                                                   SMESH_Mesh*         mesh)
00303 {
00304   _sourceFace    = s1;
00305   _sourceVertex1 = TopoDS::Vertex( s2 );
00306   _sourceVertex2 = TopoDS::Vertex( s3 );
00307   _targetVertex1 = TopoDS::Vertex( s4 );
00308   _targetVertex2 = TopoDS::Vertex( s5 );
00309   _sourceMesh   = mesh;
00310 }
00311 
00312 //================================================================================
00317 //================================================================================
00318 
00319 bool StdMeshers_ProjectionSource2D::SetParametersByDefaults(const TDefaults&  /*dflts*/,
00320                                                             const SMESH_Mesh* /*theMesh*/)
00321 {
00322   return false;
00323 }
00324