smesh/src/StdMeshers/StdMeshers_ProjectionSource2D.cxx

326 lines
11 KiB
C++
Raw Normal View History

2015-02-13 13:38:35 +05:00
// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
2012-08-09 16:03:55 +06:00
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
2014-02-20 18:25:37 +06:00
// version 2.1 of the License, or (at your option) any later version.
//
2012-08-09 16:03:55 +06:00
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
2012-08-09 16:03:55 +06:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
2012-08-09 16:03:55 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2009-02-17 10:27:49 +05:00
//
2012-08-09 16:03:55 +06:00
2009-02-17 10:27:49 +05:00
// SMESH SMESH : idl implementation based on 'SMESH' unit's classes
// File : StdMeshers_ProjectionSource2D.cxx
// Author : Edward AGAPOV
// Module : SMESH
2012-08-09 16:03:55 +06:00
//
#include "StdMeshers_ProjectionSource2D.hxx"
#include "SMESH_Mesh.hxx"
2013-02-12 20:37:44 +06:00
#include "SMESH_MesherHelper.hxx"
2012-08-09 16:03:55 +06:00
#include "StdMeshers_ProjectionUtils.hxx"
#include "utilities.h"
#include <TopoDS.hxx>
using namespace std;
//=============================================================================
/*!
* StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D
*
* Constructor
*/
//=============================================================================
StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D(int hypId, int studyId,
SMESH_Gen * gen)
: SMESH_Hypothesis(hypId, studyId, gen)
{
_name = "ProjectionSource2D"; // used by Projection_2D
_param_algo_dim = 2; // 2D
_sourceMesh = 0;
}
//=============================================================================
/*!
* StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D
*
* Destructor
*/
//=============================================================================
StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D()
{
MESSAGE( "StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D" );
}
//=============================================================================
/*!
* Sets a source <face> to take a mesh pattern from
*/
//=============================================================================
void StdMeshers_ProjectionSource2D::SetSourceFace(const TopoDS_Shape& Face)
throw ( SALOME_Exception )
{
if ( Face.IsNull() )
throw SALOME_Exception(LOCALIZED("Null Face is not allowed"));
if ( Face.ShapeType() != TopAbs_FACE && Face.ShapeType() != TopAbs_COMPOUND )
throw SALOME_Exception(LOCALIZED("Wrong shape type"));
if ( !_sourceFace.IsSame( Face ) )
{
_sourceFace = Face;
NotifySubMeshesHypothesisModification();
}
}
//=============================================================================
/*!
* Sets vertex association between the source face and the target one.
* This parameter is optional.
* Two vertices must belong to one edge of a face
*/
//=============================================================================
void StdMeshers_ProjectionSource2D::SetVertexAssociation(const TopoDS_Shape& sourceVertex1,
const TopoDS_Shape& sourceVertex2,
const TopoDS_Shape& targetVertex1,
const TopoDS_Shape& targetVertex2)
throw ( SALOME_Exception )
{
if ( sourceVertex1.IsNull() != targetVertex1.IsNull() ||
2012-08-09 16:03:55 +06:00
sourceVertex2.IsNull() != targetVertex2.IsNull() )
throw SALOME_Exception(LOCALIZED("Vertices must be provided in couples"));
if ( sourceVertex1.IsNull() != sourceVertex2.IsNull() )
{
// possibly there is only 1 vertex in the face
if ( !_sourceFace.IsNull() &&
2013-02-12 20:37:44 +06:00
SMESH_MesherHelper::Count( _sourceFace, TopAbs_VERTEX, /*ignoreSame=*/true) != 1 )
2012-08-09 16:03:55 +06:00
throw SALOME_Exception(LOCALIZED("Two or none pairs of vertices must be provided"));
}
2012-08-09 16:03:55 +06:00
if ( !sourceVertex1.IsNull() )
if ( sourceVertex1.ShapeType() != TopAbs_VERTEX ||
2012-08-09 16:03:55 +06:00
targetVertex1.ShapeType() != TopAbs_VERTEX )
throw SALOME_Exception(LOCALIZED("Wrong shape type"));
if ( !sourceVertex2.IsNull() )
if ( sourceVertex2.ShapeType() != TopAbs_VERTEX ||
targetVertex2.ShapeType() != TopAbs_VERTEX )
throw SALOME_Exception(LOCALIZED("Wrong shape type"));
2012-08-09 16:03:55 +06:00
if ( !_sourceVertex1.IsSame( sourceVertex1 ) ||
!_sourceVertex2.IsSame( sourceVertex2 ) ||
!_targetVertex1.IsSame( targetVertex1 ) ||
!_targetVertex2.IsSame( targetVertex2 ) )
{
_sourceVertex1 = TopoDS::Vertex( sourceVertex1 );
_sourceVertex2 = TopoDS::Vertex( sourceVertex2 );
_targetVertex1 = TopoDS::Vertex( targetVertex1 );
_targetVertex2 = TopoDS::Vertex( targetVertex2 );
NotifySubMeshesHypothesisModification();
}
}
//=============================================================================
/*!
* Sets source <mesh> to take a mesh pattern from
*/
//=============================================================================
void StdMeshers_ProjectionSource2D::SetSourceMesh(SMESH_Mesh* mesh)
{
2012-08-09 16:03:55 +06:00
if ( _sourceMesh != mesh ) {
_sourceMesh = mesh;
NotifySubMeshesHypothesisModification();
2012-08-09 16:03:55 +06:00
}
}
//=============================================================================
/*!
* Returns the source face
*/
//=============================================================================
TopoDS_Shape StdMeshers_ProjectionSource2D::GetSourceFace() const
{
return _sourceFace;
}
//=============================================================================
/*!
* Returns the vertex associated with the target vertex.
* Result may be nil if association not set
*/
//=============================================================================
TopoDS_Vertex StdMeshers_ProjectionSource2D::GetSourceVertex(int i) const
throw ( SALOME_Exception )
{
if ( i == 1 )
return _sourceVertex1;
else if ( i == 2 )
return _sourceVertex2;
else
throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
}
//=============================================================================
/*!
* Returns the <i>-th target vertex associated with the <i>-th source vertex.
* Result may be nil if association not set.
*/
//=============================================================================
TopoDS_Vertex StdMeshers_ProjectionSource2D::GetTargetVertex(int i) const
throw ( SALOME_Exception )
{
if ( i == 1 )
return _targetVertex1;
else if ( i == 2 )
return _targetVertex2;
else
throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
}
//=============================================================================
/*!
*
*/
//=============================================================================
ostream & StdMeshers_ProjectionSource2D::SaveTo(ostream & save)
{
// we store it in order to be able to detect that hypo is really modified
save << " " << _sourceFace.TShape().operator->() ;
save << " " << _sourceVertex1.TShape().operator->();
save << " " << _targetVertex1.TShape().operator->();
save << " " << _sourceVertex2.TShape().operator->();
save << " " << _targetVertex2.TShape().operator->();
save << " " << ( _sourceMesh ? _sourceMesh->GetId() : -1 );
return save;
}
//=============================================================================
/*!
*
*/
//=============================================================================
istream & StdMeshers_ProjectionSource2D::LoadFrom(istream & load)
{
// impossible to restore w/o any context
// It is done by servant
return load;
}
//=============================================================================
/*!
*
*/
//=============================================================================
ostream & operator <<(ostream & save, StdMeshers_ProjectionSource2D & hyp)
{
return hyp.SaveTo( save );
}
//=============================================================================
/*!
*
*/
//=============================================================================
istream & operator >>(istream & load, StdMeshers_ProjectionSource2D & hyp)
{
return hyp.LoadFrom( load );
}
//================================================================================
/*!
* \brief Initialize start and end length by the mesh built on the geometry
* \param theMesh - the built mesh
* \param theShape - the geometry of interest
* \retval bool - true if parameter values have been successfully defined
*/
//================================================================================
bool StdMeshers_ProjectionSource2D::SetParametersByMesh(const SMESH_Mesh* ,
const TopoDS_Shape& )
{
return false;
}
//================================================================================
/*!
* \brief Return all parameters
*/
//================================================================================
void StdMeshers_ProjectionSource2D::GetStoreParams(TopoDS_Shape& s1,
TopoDS_Shape& s2,
TopoDS_Shape& s3,
TopoDS_Shape& s4,
TopoDS_Shape& s5) const
{
s1 = _sourceFace;
s2 = _sourceVertex1;
s3 = _sourceVertex2;
s4 = _targetVertex1;
s5 = _targetVertex2;
}
//================================================================================
/*!
* \brief Set all parameters without notifying on modification
*/
//================================================================================
void StdMeshers_ProjectionSource2D::RestoreParams(const TopoDS_Shape& s1,
const TopoDS_Shape& s2,
const TopoDS_Shape& s3,
const TopoDS_Shape& s4,
const TopoDS_Shape& s5,
SMESH_Mesh* mesh)
{
_sourceFace = s1;
_sourceVertex1 = TopoDS::Vertex( s2 );
_sourceVertex2 = TopoDS::Vertex( s3 );
_targetVertex1 = TopoDS::Vertex( s4 );
_targetVertex2 = TopoDS::Vertex( s5 );
_sourceMesh = mesh;
}
2009-02-17 10:27:49 +05:00
//================================================================================
/*!
* \brief Initialize my parameter values by default parameters.
* \retval bool - true if parameter values have been successfully defined
*/
//================================================================================
bool StdMeshers_ProjectionSource2D::SetParametersByDefaults(const TDefaults& /*dflts*/,
const SMESH_Mesh* /*theMesh*/)
{
return false;
}