Back to index

salome-smesh  6.5.0
StdMeshers_ProjectionSource1D.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_ProjectionSource1D.cxx
00025 //  Author : Edward AGAPOV
00026 //  Module : SMESH
00027 //
00028 #include "StdMeshers_ProjectionSource1D.hxx"
00029 
00030 #include "SMESH_Mesh.hxx"
00031 
00032 #include "utilities.h"
00033 
00034 #include <TopoDS.hxx>
00035 
00036 using namespace std;
00037 
00038 
00039 //=============================================================================
00045 //=============================================================================
00046 
00047 StdMeshers_ProjectionSource1D::StdMeshers_ProjectionSource1D(int hypId, int studyId,
00048                                                              SMESH_Gen * gen)
00049   : SMESH_Hypothesis(hypId, studyId, gen)
00050 {
00051   _name = "ProjectionSource1D"; // used by Projection_1D
00052   _param_algo_dim = 1; // 1D
00053   _sourceMesh = 0;
00054 }
00055 
00056 //=============================================================================
00062 //=============================================================================
00063 
00064 StdMeshers_ProjectionSource1D::~StdMeshers_ProjectionSource1D()
00065 {
00066   MESSAGE( "StdMeshers_ProjectionSource1D::~StdMeshers_ProjectionSource1D" );
00067 }
00068 
00069 //=============================================================================
00073 //=============================================================================
00074 
00075 void StdMeshers_ProjectionSource1D::SetSourceEdge(const TopoDS_Shape& edge)
00076   throw ( SALOME_Exception )
00077 {
00078   if ( edge.IsNull() )
00079     throw SALOME_Exception(LOCALIZED("Null edge is not allowed"));
00080 
00081   if ( edge.ShapeType() != TopAbs_EDGE && edge.ShapeType() != TopAbs_COMPOUND )
00082     throw SALOME_Exception(LOCALIZED("Wrong shape type"));
00083 
00084   if ( !_sourceEdge.IsSame( edge ) )
00085   {
00086     _sourceEdge = edge;
00087 
00088     NotifySubMeshesHypothesisModification();
00089   }
00090 }
00091 
00092 //=============================================================================
00097 //=============================================================================
00098 
00099 void StdMeshers_ProjectionSource1D::SetVertexAssociation(const TopoDS_Shape& sourceVertex,
00100                                                          const TopoDS_Shape& targetVertex)
00101   throw ( SALOME_Exception )
00102 {
00103   if ( sourceVertex.IsNull() != targetVertex.IsNull() )
00104     throw SALOME_Exception(LOCALIZED("Two or none vertices must be provided"));
00105 
00106   if ( !sourceVertex.IsNull() ) {
00107     if ( sourceVertex.ShapeType() != TopAbs_VERTEX ||
00108          targetVertex.ShapeType() != TopAbs_VERTEX )
00109       throw SALOME_Exception(LOCALIZED("Wrong shape type"));
00110   }
00111 
00112   if ( !_sourceVertex.IsSame( sourceVertex ) ||
00113        !_targetVertex.IsSame( targetVertex ) )
00114   {
00115     _sourceVertex = TopoDS::Vertex( sourceVertex );
00116     _targetVertex = TopoDS::Vertex( targetVertex );
00117 
00118     NotifySubMeshesHypothesisModification();
00119   }
00120 }
00121 
00122 //=============================================================================
00126 //=============================================================================
00127 
00128 void StdMeshers_ProjectionSource1D::SetSourceMesh(SMESH_Mesh* mesh)
00129 {
00130   if ( _sourceMesh != mesh ) {
00131     _sourceMesh = mesh;
00132     NotifySubMeshesHypothesisModification();
00133   }
00134 }
00135 
00136 //=============================================================================
00140 //=============================================================================
00141 
00142 ostream & StdMeshers_ProjectionSource1D::SaveTo(ostream & save)
00143 {
00144   // we store it in order to be able to detect that hypo is really modified
00145   save << " " << _sourceEdge.TShape().operator->()  ;
00146   save << " " << _sourceVertex.TShape().operator->();
00147   save << " " << _targetVertex.TShape().operator->();
00148   save << " " << ( _sourceMesh ? _sourceMesh->GetId() : -1 );
00149   return save;
00150 }
00151 
00152 //=============================================================================
00156 //=============================================================================
00157 
00158 istream & StdMeshers_ProjectionSource1D::LoadFrom(istream & load)
00159 {
00160   // impossible to restore w/o any context
00161   return load;
00162 }
00163 
00164 //=============================================================================
00168 //=============================================================================
00169 
00170 ostream & operator <<(ostream & save, StdMeshers_ProjectionSource1D & hyp)
00171 {
00172   return hyp.SaveTo( save );
00173 }
00174 
00175 //=============================================================================
00179 //=============================================================================
00180 
00181 istream & operator >>(istream & load, StdMeshers_ProjectionSource1D & hyp)
00182 {
00183   return hyp.LoadFrom( load );
00184 }
00185 
00186 //================================================================================
00193 //================================================================================
00194 
00195 bool StdMeshers_ProjectionSource1D::SetParametersByMesh(const SMESH_Mesh*   ,
00196                                                         const TopoDS_Shape& )
00197 {
00198   return false;
00199 }
00200 
00201 //================================================================================
00205 //================================================================================
00206 
00207 void StdMeshers_ProjectionSource1D::GetStoreParams(TopoDS_Shape& s1,
00208                                                    TopoDS_Shape& s2,
00209                                                    TopoDS_Shape& s3) const
00210 {
00211   s1 = _sourceEdge;
00212   s2 = _sourceVertex;
00213   s3 = _targetVertex;
00214 }
00215 
00216 //================================================================================
00220 //================================================================================
00221 
00222 void StdMeshers_ProjectionSource1D::RestoreParams(const TopoDS_Shape& s1,
00223                                                   const TopoDS_Shape& s2,
00224                                                   const TopoDS_Shape& s3,
00225                                                   SMESH_Mesh*         mesh)
00226 {
00227   _sourceEdge   = s1;
00228   _sourceVertex = TopoDS::Vertex( s2 );
00229   _targetVertex = TopoDS::Vertex( s3 );
00230   _sourceMesh   = mesh;
00231 }
00232 
00233 //================================================================================
00238 //================================================================================
00239 
00240 bool StdMeshers_ProjectionSource1D::SetParametersByDefaults(const TDefaults&  /*dflts*/,
00241                                                             const SMESH_Mesh* /*theMesh*/)
00242 {
00243   return false;
00244 }
00245