1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 // SMESH SMESH : implementation of SMESH idl descriptions
24 // File : StdMeshers_SegmentLengthAroundVertex.cxx
27 #include "StdMeshers_SegmentLengthAroundVertex.hxx"
29 #include "SMESH_Mesh.hxx"
30 #include "SMESH_Algo.hxx"
31 #include "SMDS_MeshNode.hxx"
32 #include "SMESHDS_Mesh.hxx"
33 #include "SMESHDS_SubMesh.hxx"
34 #include "SMESH_MeshEditor.hxx"
35 #include "SMESH_MesherHelper.hxx"
37 #include "utilities.h"
39 #include <BRepAdaptor_Curve.hxx>
40 #include <GCPnts_AbscissaPoint.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <TopoDS_Edge.hxx>
47 //=============================================================================
51 //=============================================================================
53 StdMeshers_SegmentLengthAroundVertex::StdMeshers_SegmentLengthAroundVertex
54 (int hypId, SMESH_Gen * gen)
55 :SMESH_Hypothesis(hypId, gen)
58 _name = "SegmentLengthAroundVertex";
59 _param_algo_dim = 0; // is used by StdMeshers_SegmentAroundVertex_0D
62 //=============================================================================
66 //=============================================================================
68 StdMeshers_SegmentLengthAroundVertex::~StdMeshers_SegmentLengthAroundVertex()
72 //=============================================================================
76 //=============================================================================
78 void StdMeshers_SegmentLengthAroundVertex::SetLength(double length) throw(SALOME_Exception)
81 throw SALOME_Exception(LOCALIZED("length must be positive"));
82 if (_length != length) {
84 NotifySubMeshesHypothesisModification();
88 //=============================================================================
92 //=============================================================================
94 double StdMeshers_SegmentLengthAroundVertex::GetLength() const
99 //=============================================================================
103 //=============================================================================
105 ostream & StdMeshers_SegmentLengthAroundVertex::SaveTo(ostream & save)
107 save << this->_length;
111 //=============================================================================
115 //=============================================================================
117 istream & StdMeshers_SegmentLengthAroundVertex::LoadFrom(istream & load)
121 isOK = static_cast<bool>(load >> a);
125 load.clear(ios::badbit | load.rdstate());
129 //=============================================================================
133 //=============================================================================
135 ostream & operator <<(ostream & save, StdMeshers_SegmentLengthAroundVertex & hyp)
137 return hyp.SaveTo( save );
140 //=============================================================================
144 //=============================================================================
146 istream & operator >>(istream & load, StdMeshers_SegmentLengthAroundVertex & hyp)
148 return hyp.LoadFrom( load );
151 //================================================================================
153 * \brief Initialize segment length by the mesh built on the geometry
154 * \param theMesh - the built mesh
155 * \param theShape - the geometry of interest
156 * \retval bool - true if parameter values have been successfully defined
158 //================================================================================
160 bool StdMeshers_SegmentLengthAroundVertex::SetParametersByMesh(const SMESH_Mesh* theMesh,
161 const TopoDS_Shape& theShape)
163 if ( !theMesh || theShape.IsNull() || theShape.ShapeType() != TopAbs_VERTEX )
166 SMESH_MeshEditor editor( const_cast<SMESH_Mesh*>( theMesh ) );
167 SMESH_MesherHelper helper( *editor.GetMesh() );
169 // get node built on theShape vertex
170 SMESHDS_Mesh* meshDS = editor.GetMeshDS();
171 SMESHDS_SubMesh* smV = meshDS->MeshElements( theShape );
172 if ( !smV || smV->NbNodes() == 0 )
174 const SMDS_MeshNode* vNode = smV->GetNodes()->next();
176 // calculate average length of segments sharing vNode
181 SMDS_ElemIteratorPtr segIt = vNode->GetInverseElementIterator(SMDSAbs_Edge);
182 while ( segIt->more() ) {
183 const SMDS_MeshElement* seg = segIt->next();
185 int shapeID = editor.FindShape( seg );
186 if (!shapeID) continue;
187 const TopoDS_Shape& s = meshDS->IndexToShape( shapeID );
188 if ( s.IsNull() || s.ShapeType() != TopAbs_EDGE ) continue;
189 const TopoDS_Edge& edge = TopoDS::Edge( s );
190 // params of edge ends
191 double u0 = helper.GetNodeU( edge, seg->GetNode(0) );
192 double u1 = helper.GetNodeU( edge, seg->GetNode(1) );
194 BRepAdaptor_Curve AdaptCurve( edge );
195 _length += GCPnts_AbscissaPoint::Length( AdaptCurve, u0, u1);
205 //================================================================================
207 * \brief Initialize my parameter values by default parameters.
208 * \retval bool - true if parameter values have been successfully defined
210 //================================================================================
212 bool StdMeshers_SegmentLengthAroundVertex::SetParametersByDefaults(const TDefaults&,