+ // --- iterates on elements to be replicated and get elements by back references from their nodes
+
+ TIDSortedElemSet::const_iterator elemItr = theElems.begin();
+ int ielem = 1;
+ for ( ; elemItr != theElems.end(); ++elemItr )
+ {
+ SMDS_MeshElement* anElem = (SMDS_MeshElement*)*elemItr;
+ if (!anElem || (anElem->GetType() != SMDSAbs_Face))
+ continue;
+ gp_XYZ normal;
+ SMESH_Algo::FaceNormal( anElem, normal, /*normalized=*/true );
+ MESSAGE("element " << ielem++ << " normal " << normal.X() << " " << normal.Y() << " " << normal.Z());
+ std::set<const SMDS_MeshNode*> nodesElem;
+ nodesElem.clear();
+ SMDS_ElemIteratorPtr nodeItr = anElem->nodesIterator();
+ while ( nodeItr->more() )
+ {
+ const SMDS_MeshNode* aNode = cast2Node(nodeItr->next());
+ nodesElem.insert(aNode);
+ }
+ std::set<const SMDS_MeshNode*>::iterator nodit = nodesElem.begin();
+ for (; nodit != nodesElem.end(); nodit++)
+ {
+ MESSAGE(" noeud ");
+ const SMDS_MeshNode* aNode = *nodit;
+ if ( !aNode || theNodesNot.find(aNode) != theNodesNot.end() )
+ continue;
+ if (alreadyCheckedNodes.find(aNode) != alreadyCheckedNodes.end())
+ continue;
+ alreadyCheckedNodes.insert(aNode);
+ SMDS_ElemIteratorPtr backElemItr = aNode->GetInverseElementIterator();
+ while ( backElemItr->more() )
+ {
+ MESSAGE(" backelem ");
+ const SMDS_MeshElement* curElem = backElemItr->next();
+ if (alreadyCheckedElems.find(curElem) != alreadyCheckedElems.end())
+ continue;
+ if (theElems.find(curElem) != theElems.end())
+ continue;
+ alreadyCheckedElems.insert(curElem);
+ double x=0, y=0, z=0;
+ int nb = 0;
+ SMDS_ElemIteratorPtr nodeItr2 = curElem->nodesIterator();
+ while ( nodeItr2->more() )
+ {
+ const SMDS_MeshNode* anotherNode = cast2Node(nodeItr2->next());
+ x += anotherNode->X();
+ y += anotherNode->Y();
+ z += anotherNode->Z();
+ nb++;
+ }
+ gp_XYZ p;
+ p.SetCoord( x/nb -aNode->X(),
+ y/nb -aNode->Y(),
+ z/nb -aNode->Z() );
+ MESSAGE(" check " << p.X() << " " << p.Y() << " " << p.Z());
+ if (normal*p > 0)
+ {
+ MESSAGE(" --- inserted")
+ theAffectedElems.insert( curElem );
+ }
+ else if (curElem->GetType() == SMDSAbs_Edge)
+ edgesToCheck.insert(curElem);
+ }
+ }
+ }
+ // --- add also edges lying on the set of faces (all nodes in alreadyCheckedNodes)
+ std::set<const SMDS_MeshElement*>::iterator eit = edgesToCheck.begin();
+ for( ; eit != edgesToCheck.end(); eit++)
+ {
+ bool onside = true;
+ const SMDS_MeshElement* anEdge = *eit;
+ SMDS_ElemIteratorPtr nodeItr = anEdge->nodesIterator();
+ while ( nodeItr->more() )
+ {
+ const SMDS_MeshNode* aNode = cast2Node(nodeItr->next());
+ if (alreadyCheckedNodes.find(aNode) == alreadyCheckedNodes.end())
+ {
+ onside = false;
+ break;
+ }
+ }
+ if (onside)
+ {
+ MESSAGE(" --- edge onside inserted")
+ theAffectedElems.insert(anEdge);
+ }
+ }
+ }
+ else