- MESSAGE("StdMeshers_Regular_1D::Compute");
-
- SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
- SMESH_subMesh *theSubMesh = aMesh.GetSubMesh(aShape);
-
- const TopoDS_Edge & EE = TopoDS::Edge(aShape);
- TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
-
- double f, l;
- Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
-
- TopoDS_Vertex VFirst, VLast;
- TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
-
- double length = EdgeLength(E);
- //SCRUTE(length);
-
- double eltSize = 1;
-// if (_localLength > 0) eltSize = _localLength;
- if (_localLength > 0)
- {
- double nbseg = ceil(length / _localLength); // integer sup
- if (nbseg <= 0)
- nbseg = 1; // degenerated edge
- eltSize = length / nbseg;
- }
- else
- {
- ASSERT(_numberOfSegments > 0);
- eltSize = length / _numberOfSegments;
- }
-
- ASSERT(!VFirst.IsNull());
- SMDS_NodeIteratorPtr lid= aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes();
- const SMDS_MeshNode * idFirst = lid->next();
-
- ASSERT(!VLast.IsNull());
- lid=aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes();
- const SMDS_MeshNode * idLast = lid->next();
-
- if (!Curve.IsNull())
- {
- GeomAdaptor_Curve C3d(Curve);
- GCPnts_UniformAbscissa Discret(C3d, eltSize, f, l);
- int NbPoints = Discret.NbPoints();
- //MESSAGE("nb points on edge : "<<NbPoints);
-
- // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
- // only internal nodes receive an edge position with param on curve
-
- const SMDS_MeshNode * idPrev = idFirst;
- for (int i = 2; i < NbPoints; i++)
- {
- double param = Discret.Parameter(i);
-
- if (_numberOfSegments > 1)
- {
- double epsilon = 0.001;
- if (fabs(_scaleFactor - 1.0) > epsilon)
- {
- double alpha =
- pow(_scaleFactor, 1.0 / (_numberOfSegments - 1));
- double d =
- length * (1 - pow(alpha, i - 1)) / (1 - pow(alpha,
- _numberOfSegments));
- param = d;
- }
- }
-
- gp_Pnt P = Curve->Value(param);
-
- //Add the Node in the DataStructure
- //MESSAGE("point "<<nodeId<<" "<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<" - "<<i<<" "<<param);
- SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
- meshDS->SetNodeOnEdge(node, E);
-
- // **** edgePosition associe au point = param.
- SMDS_EdgePosition* epos =
- dynamic_cast<SMDS_EdgePosition *>(node->GetPosition().get());
- epos->SetUParameter(param);
-
- SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
- meshDS->SetMeshElementOnShape(edge, E);
- idPrev = node;
- }
- SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
- meshDS->SetMeshElementOnShape(edge, E);
- }
- else
- {
-// MESSAGE ("Edge Degeneree non traitee --- arret");
-// ASSERT(0);
- if (BRep_Tool::Degenerated(E))
- {
- // Edge is a degenerated Edge : We put n = 5 points on the edge.
- int NbPoints = 5;
- BRep_Tool::Range(E, f, l);
- double du = (l - f) / (NbPoints - 1);
- MESSAGE("************* Degenerated edge! *****************");
-
- TopoDS_Vertex V1, V2;
- TopExp::Vertices(E, V1, V2);
- gp_Pnt P = BRep_Tool::Pnt(V1);
-
- const SMDS_MeshNode * idPrev = idFirst;
- for (int i = 2; i < NbPoints; i++)
- {
- double param = f + (i - 1) * du;
- SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
- meshDS->SetNodeOnEdge(node, E);
-
-// Handle (SMDS_EdgePosition) epos
-// = new SMDS_EdgePosition(theSubMesh->GetId(),param);
-// node->SetPosition(epos);
- SMDS_EdgePosition* epos =
- dynamic_cast<SMDS_EdgePosition*>(node->GetPosition().get());
- epos->SetUParameter(param);
-
- SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
- meshDS->SetMeshElementOnShape(edge, E);
- idPrev = node;
- }
- SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
- meshDS->SetMeshElementOnShape(edge, E);
- }
- else
- ASSERT(0);
- }
- return true;
+ MESSAGE("StdMeshers_Regular_1D::Compute");
+
+ if ( _hypType == NONE )
+ return false;
+
+ SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
+ aMesh.GetSubMesh(aShape);
+
+ const TopoDS_Edge & EE = TopoDS::Edge(aShape);
+ TopoDS_Edge E = TopoDS::Edge(EE.Oriented(TopAbs_FORWARD));
+ int shapeID = meshDS->ShapeToIndex( E );
+
+ double f, l;
+ Handle(Geom_Curve) Curve = BRep_Tool::Curve(E, f, l);
+
+ TopoDS_Vertex VFirst, VLast;
+ TopExp::Vertices(E, VFirst, VLast); // Vfirst corresponds to f and Vlast to l
+
+ ASSERT(!VFirst.IsNull());
+ SMDS_NodeIteratorPtr lid= aMesh.GetSubMesh(VFirst)->GetSubMeshDS()->GetNodes();
+ if (!lid->more())
+ {
+ MESSAGE (" NO NODE BUILT ON VERTEX ");
+ return false;
+ }
+ const SMDS_MeshNode * idFirst = lid->next();
+
+ ASSERT(!VLast.IsNull());
+ lid=aMesh.GetSubMesh(VLast)->GetSubMeshDS()->GetNodes();
+ if (!lid->more())
+ {
+ MESSAGE (" NO NODE BUILT ON VERTEX ");
+ return false;
+ }
+ const SMDS_MeshNode * idLast = lid->next();
+
+ if (!Curve.IsNull())
+ {
+ list< double > params;
+ bool reversed = false;
+ if ( !_mainEdge.IsNull() )
+ reversed = aMesh.IsReversedInChain( EE, _mainEdge );
+ try {
+ if ( ! computeInternalParameters( E, params, reversed ))
+ return false;
+ }
+ catch ( Standard_Failure ) {
+ return false;
+ }
+
+ // edge extrema (indexes : 1 & NbPoints) already in SMDS (TopoDS_Vertex)
+ // only internal nodes receive an edge position with param on curve
+
+ const SMDS_MeshNode * idPrev = idFirst;
+
+ for (list<double>::iterator itU = params.begin(); itU != params.end(); itU++)
+ {
+ double param = *itU;
+ gp_Pnt P = Curve->Value(param);
+
+ //Add the Node in the DataStructure
+ SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
+ meshDS->SetNodeOnEdge(node, shapeID, param);
+
+ SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
+ meshDS->SetMeshElementOnShape(edge, shapeID);
+ idPrev = node;
+ }
+ SMDS_MeshEdge* edge = meshDS->AddEdge(idPrev, idLast);
+ meshDS->SetMeshElementOnShape(edge, shapeID);
+ }
+ else
+ {
+ // Edge is a degenerated Edge : We put n = 5 points on the edge.
+ int NbPoints = 5;
+ BRep_Tool::Range(E, f, l);
+ double du = (l - f) / (NbPoints - 1);
+ //MESSAGE("************* Degenerated edge! *****************");
+
+ TopoDS_Vertex V1, V2;
+ TopExp::Vertices(E, V1, V2);
+ gp_Pnt P = BRep_Tool::Pnt(V1);
+
+ const SMDS_MeshNode * idPrev = idFirst;
+ for (int i = 2; i < NbPoints; i++)
+ {
+ double param = f + (i - 1) * du;
+ SMDS_MeshNode * node = meshDS->AddNode(P.X(), P.Y(), P.Z());
+ meshDS->SetNodeOnEdge(node, shapeID, param);
+
+ SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, node);
+ meshDS->SetMeshElementOnShape(edge, shapeID);
+ idPrev = node;
+ }
+ SMDS_MeshEdge * edge = meshDS->AddEdge(idPrev, idLast);
+ meshDS->SetMeshElementOnShape(edge, shapeID);
+ }
+ return true;
+}
+
+//=============================================================================
+/*!
+ * See comments in SMESH_Algo.cxx
+ */
+//=============================================================================
+
+const list <const SMESHDS_Hypothesis *> & StdMeshers_Regular_1D::GetUsedHypothesis(
+ SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
+{
+ _usedHypList.clear();
+ _usedHypList = GetAppliedHypothesis(aMesh, aShape); // copy
+ int nbHyp = _usedHypList.size();
+ _mainEdge.Nullify();
+ if (nbHyp == 0)
+ {
+ // Check, if propagated from some other edge
+ if (aShape.ShapeType() == TopAbs_EDGE &&
+ aMesh.IsPropagatedHypothesis(aShape, _mainEdge))
+ {
+ // Propagation of 1D hypothesis from <aMainEdge> on this edge
+ //_usedHypList = GetAppliedHypothesis(aMesh, _mainEdge); // copy
+ // use a general method in order not to nullify _mainEdge
+ _usedHypList = SMESH_Algo::GetUsedHypothesis(aMesh, _mainEdge); // copy
+ nbHyp = _usedHypList.size();
+ }
+ }
+ if (nbHyp == 0)
+ {
+ TopTools_ListIteratorOfListOfShape ancIt( aMesh.GetAncestors( aShape ));
+ for (; ancIt.More(); ancIt.Next())
+ {
+ const TopoDS_Shape& ancestor = ancIt.Value();
+ _usedHypList = GetAppliedHypothesis(aMesh, ancestor); // copy
+ nbHyp = _usedHypList.size();
+ if (nbHyp == 1)
+ break;
+ }
+ }
+ if (nbHyp > 1)
+ _usedHypList.clear(); //only one compatible hypothesis allowed
+ return _usedHypList;