Salome HOME
Fix regression of SMESH_TEST/Grids/smesh/imps6/G0
[modules/smesh.git] / src / StdMeshers / StdMeshers_Import_1D.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH : implementaion of SMESH idl descriptions
24 //  File   : StdMeshers_Import_1D.cxx
25 //  Module : SMESH
26 //
27 #include "StdMeshers_Import_1D.hxx"
28 #include "StdMeshers_ImportSource.hxx"
29
30 #include "SMDS_MeshElement.hxx"
31 #include "SMDS_MeshNode.hxx"
32 #include "SMESHDS_Group.hxx"
33 #include "SMESHDS_Mesh.hxx"
34 #include "SMESH_Comment.hxx"
35 #include "SMESH_Gen.hxx"
36 #include "SMESH_Group.hxx"
37 #include "SMESH_HypoFilter.hxx"
38 #include "SMESH_Mesh.hxx"
39 #include "SMESH_MesherHelper.hxx"
40 #include "SMESH_subMesh.hxx"
41 #include "SMESH_subMeshEventListener.hxx"
42
43 #include "Utils_SALOME_Exception.hxx"
44 #include "utilities.h"
45
46 #include <BRep_Builder.hxx>
47 #include <BRep_Tool.hxx>
48 #include <TopExp.hxx>
49 #include <TopExp_Explorer.hxx>
50 #include <TopoDS.hxx>
51 #include <TopoDS_Compound.hxx>
52 #include <TopoDS_Edge.hxx>
53 #include <TopoDS_Vertex.hxx>
54
55 using namespace std;
56
57 //=============================================================================
58 /*!
59  * Creates StdMeshers_Import_1D
60  */
61 //=============================================================================
62
63 StdMeshers_Import_1D::StdMeshers_Import_1D(int hypId, int studyId, SMESH_Gen * gen)
64   :SMESH_1D_Algo(hypId, studyId, gen), _sourceHyp(0)
65 {
66   MESSAGE("StdMeshers_Import_1D::StdMeshers_Import_1D");
67   _name = "Import_1D";
68   _shapeType = (1 << TopAbs_EDGE);
69
70   _compatibleHypothesis.push_back("ImportSource1D");
71 }
72
73 //=============================================================================
74 /*!
75  * Check presence of a hypothesis
76  */
77 //=============================================================================
78
79 bool StdMeshers_Import_1D::CheckHypothesis
80                          (SMESH_Mesh&                          aMesh,
81                           const TopoDS_Shape&                  aShape,
82                           SMESH_Hypothesis::Hypothesis_Status& aStatus)
83 {
84   _sourceHyp = 0;
85
86   const list <const SMESHDS_Hypothesis * >&hyps = GetUsedHypothesis(aMesh, aShape);
87   if ( hyps.size() == 0 )
88   {
89     aStatus = SMESH_Hypothesis::HYP_MISSING;
90     return false;  // can't work with no hypothesis
91   }
92
93   if ( hyps.size() > 1 )
94   {
95     aStatus = SMESH_Hypothesis::HYP_ALREADY_EXIST;
96     return false;
97   }
98
99   const SMESHDS_Hypothesis *theHyp = hyps.front();
100
101   string hypName = theHyp->GetName();
102
103   if (hypName == _compatibleHypothesis.front())
104   {
105     _sourceHyp = (StdMeshers_ImportSource1D *)theHyp;
106     aStatus = SMESH_Hypothesis::HYP_OK;
107     return true;
108   }
109
110   aStatus = SMESH_Hypothesis::HYP_INCOMPATIBLE;
111   return true;
112 }
113
114 //================================================================================
115 namespace // INTERNAL STUFF
116 //================================================================================
117 {
118   int getSubmeshIDForCopiedMesh(const SMESHDS_Mesh* srcMeshDS, SMESH_Mesh* tgtMesh);
119
120   enum _ListenerDataType
121     {
122       WAIT_HYP_MODIF=1, // data indicating awaiting for valid parameters of src hyp
123       LISTEN_SRC_MESH, // data storing submesh depending on source mesh state
124       SRC_HYP // data storing ImportSource hyp
125     };
126   //================================================================================
127   /*!
128    * \brief _ListenerData holding ImportSource hyp holding in its turn
129    *  imported groups
130    */
131   struct _ListenerData : public SMESH_subMeshEventListenerData
132   {
133     const StdMeshers_ImportSource1D* _srcHyp;
134     _ListenerData(const StdMeshers_ImportSource1D* h, _ListenerDataType type=SRC_HYP):
135       SMESH_subMeshEventListenerData(/*isDeletable=*/true), _srcHyp(h)
136     {
137       myType = type;
138     }
139   };
140   //================================================================================
141   /*!
142    * \brief Comparator of sub-meshes
143    */
144   struct _SubLess
145   {
146     bool operator()(const SMESH_subMesh* sm1, const SMESH_subMesh* sm2 ) const
147     {
148       if ( sm1 == sm2 ) return false;
149       if ( !sm1 || !sm2 ) return sm1 < sm2;
150       const TopoDS_Shape& s1 = sm1->GetSubShape();
151       const TopoDS_Shape& s2 = sm2->GetSubShape();
152       TopAbs_ShapeEnum t1 = s1.IsNull() ? TopAbs_SHAPE : s1.ShapeType();
153       TopAbs_ShapeEnum t2 = s2.IsNull() ? TopAbs_SHAPE : s2.ShapeType();
154       if ( t1 == t2)
155         return (sm1 < sm2);
156       return t1 < t2; // to have: face < edge
157     }
158   };
159   //================================================================================
160   /*!
161    * \brief Container of data dedicated to one source mesh
162    */
163   struct _ImportData
164   {
165     const SMESH_Mesh* _srcMesh;
166     StdMeshers_Import_1D::TNodeNodeMap _n2n;
167     StdMeshers_Import_1D::TElemElemMap _e2e;
168
169     set< SMESH_subMesh*, _SubLess > _subM; // submeshes relating to this srcMesh
170     set< SMESH_subMesh*, _SubLess > _copyMeshSubM; // submeshes requesting mesh copying
171     set< SMESH_subMesh*, _SubLess > _copyGroupSubM; // submeshes requesting group copying
172     set< SMESH_subMesh*, _SubLess > _computedSubM;
173
174     SMESHDS_SubMesh*     _importMeshSubDS; // submesh storing a copy of _srcMesh
175     int                  _importMeshSubID; // id of _importMeshSubDS
176
177     _ImportData(const SMESH_Mesh* srcMesh=0):
178       _srcMesh(srcMesh), _importMeshSubDS(0),_importMeshSubID(-1) {}
179
180     void removeImportedMesh( SMESHDS_Mesh* meshDS )
181     {
182       if ( !_importMeshSubDS ) return;
183       SMDS_ElemIteratorPtr eIt = _importMeshSubDS->GetElements();
184       while ( eIt->more() )
185         meshDS->RemoveFreeElement( eIt->next(), 0, /*fromGroups=*/false );
186       SMDS_NodeIteratorPtr nIt = _importMeshSubDS->GetNodes();
187       while ( nIt->more() )
188         meshDS->RemoveFreeNode( nIt->next(), 0, /*fromGroups=*/false );
189       _importMeshSubDS->Clear();
190       _n2n.clear();
191       _e2e.clear();
192     }
193     void removeGroups( SMESH_subMesh* subM, const StdMeshers_ImportSource1D* srcHyp )
194     {
195       if ( !srcHyp ) return;
196       SMESH_Mesh*           tgtMesh = subM->GetFather();
197       const SMESHDS_Mesh* tgtMeshDS = tgtMesh->GetMeshDS();
198       const SMESHDS_Mesh* srcMeshDS = _srcMesh->GetMeshDS();
199       vector<SMESH_Group*>*  groups =
200         const_cast<StdMeshers_ImportSource1D*>(srcHyp)->GetResultGroups(*srcMeshDS,*tgtMeshDS);
201       if ( groups )
202       {
203         for ( unsigned i = 0; i < groups->size(); ++i )
204           tgtMesh->RemoveGroup( groups->at(i)->GetGroupDS()->GetID() );
205         groups->clear();
206       }
207     }
208     void trackHypParams( SMESH_subMesh* sm, const StdMeshers_ImportSource1D* srcHyp )
209     {
210       if ( !srcHyp ) return;
211       bool toCopyMesh, toCopyGroups;
212       srcHyp->GetCopySourceMesh(toCopyMesh, toCopyGroups);
213
214       if ( toCopyMesh )_copyMeshSubM.insert( sm );
215       else             _copyMeshSubM.erase( sm );
216
217       if ( toCopyGroups ) _copyGroupSubM.insert( sm );
218       else                _copyGroupSubM.erase( sm );
219     }
220     void addComputed( SMESH_subMesh* sm )
221     {
222       SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
223                                                                /*complexShapeFirst=*/true);
224       while ( smIt->more() )
225       {
226         sm = smIt->next();
227         switch ( sm->GetSubShape().ShapeType() )
228         {
229         case TopAbs_EDGE:
230         case TopAbs_FACE:
231           _subM.insert( sm );
232           if ( !sm->IsEmpty() )
233             _computedSubM.insert( sm );
234         case TopAbs_VERTEX:
235           break;
236         default:;
237         }
238       }
239     }
240   };
241   //================================================================================
242   /*!
243    * Listener notified on events relating to imported submesh
244    */
245   class _Listener : public SMESH_subMeshEventListener
246   {
247     typedef map< SMESH_Mesh*, list< _ImportData > > TMesh2ImpData;
248     TMesh2ImpData _tgtMesh2ImportData;
249
250     _Listener():SMESH_subMeshEventListener(/*isDeletable=*/false,
251                                            "StdMeshers_Import_1D::_Listener") {}
252
253   public:
254     // return poiter to a static listener
255     static _Listener* get() { static _Listener theListener; return &theListener; }
256
257     static _ImportData* getImportData(const SMESH_Mesh* srcMesh, SMESH_Mesh* tgtMesh);
258
259     static void storeImportSubmesh(SMESH_subMesh*                   importSub,
260                                    const SMESH_Mesh*                srcMesh,
261                                    const StdMeshers_ImportSource1D* srcHyp);
262
263     virtual void ProcessEvent(const int                       event,
264                               const int                       eventType,
265                               SMESH_subMesh*                  subMesh,
266                               SMESH_subMeshEventListenerData* data,
267                               const SMESH_Hypothesis*         hyp);
268     void removeSubmesh( SMESH_subMesh* sm, _ListenerData* data );
269     void clearSubmesh ( SMESH_subMesh* sm, _ListenerData* data, bool clearAllSub );
270     void clearN2N     ( SMESH_Mesh* tgtMesh );
271
272     // mark sm as missing src hyp with valid groups
273     static void waitHypModification(SMESH_subMesh* sm)
274     {
275       sm->SetEventListener
276         (get(), SMESH_subMeshEventListenerData::MakeData( sm, WAIT_HYP_MODIF ), sm);
277     }
278   };
279   //--------------------------------------------------------------------------------
280   /*!
281    * \brief Find or create ImportData for given meshes
282    */
283   _ImportData* _Listener::getImportData(const SMESH_Mesh* srcMesh,
284                                         SMESH_Mesh*       tgtMesh)
285   {
286     list< _ImportData >& dList = get()->_tgtMesh2ImportData[tgtMesh];
287     list< _ImportData >::iterator d = dList.begin();
288     for ( ; d != dList.end(); ++d )
289       if ( d->_srcMesh == srcMesh )
290         return &*d;
291     dList.push_back(_ImportData(srcMesh));
292     return &dList.back();
293   }
294
295   //--------------------------------------------------------------------------------
296   /*!
297    * \brief Remember an imported sub-mesh and set needed even listeners
298    *  \param importSub - submesh computed by Import algo
299    *  \param srcMesh - source mesh
300    *  \param srcHyp - ImportSource hypothesis
301    */
302   void _Listener::storeImportSubmesh(SMESH_subMesh*                   importSub,
303                                      const SMESH_Mesh*                srcMesh,
304                                      const StdMeshers_ImportSource1D* srcHyp)
305   {
306     // set listener to hear events of the submesh computed by "Import" algo
307     importSub->SetEventListener( get(), new _ListenerData(srcHyp), importSub );
308
309     // set listeners to hear events of the source mesh
310     SMESH_subMesh* smToNotify = importSub;
311     vector<SMESH_subMesh*> smToListen = srcHyp->GetSourceSubMeshes( srcMesh );
312     for ( size_t i = 0; i < smToListen.size(); ++i )
313     {
314       SMESH_subMeshEventListenerData* data = new _ListenerData(srcHyp, LISTEN_SRC_MESH);
315       data->mySubMeshes.push_back( smToNotify );
316       importSub->SetEventListener( get(), data, smToListen[i] );
317     }
318     // remember the submesh importSub and its sub-submeshes
319     _ImportData* iData = _Listener::getImportData( srcMesh, importSub->GetFather());
320     iData->trackHypParams( importSub, srcHyp );
321     iData->addComputed( importSub );
322     if ( !iData->_copyMeshSubM.empty() && iData->_importMeshSubID < 1 )
323     {
324       SMESH_Mesh* tgtMesh = importSub->GetFather();
325       iData->_importMeshSubID = getSubmeshIDForCopiedMesh( srcMesh->GetMeshDS(),tgtMesh);
326       iData->_importMeshSubDS = tgtMesh->GetMeshDS()->NewSubMesh( iData->_importMeshSubID );
327     }
328   }
329   //--------------------------------------------------------------------------------
330   /*!
331    * \brief Remove imported mesh and/or groups if needed
332    *  \param sm - submesh loosing Import algo
333    *  \param data - data holding imported groups
334    */
335   void _Listener::removeSubmesh( SMESH_subMesh* sm, _ListenerData* data )
336   {
337     list< _ImportData > &  dList = _tgtMesh2ImportData[ sm->GetFather() ];
338     list< _ImportData >::iterator d = dList.begin();
339     for ( ; d != dList.end(); ++d )
340       if ( (*d)._subM.erase( sm ))
341       {
342         d->_computedSubM.erase( sm );
343         bool rmMesh   = d->_copyMeshSubM.erase( sm ) && d->_copyMeshSubM.empty();
344         bool rmGroups = (d->_copyGroupSubM.erase( sm ) && d->_copyGroupSubM.empty()) || rmMesh;
345         if ( rmMesh )
346           d->removeImportedMesh( sm->GetFather()->GetMeshDS() );
347         if ( rmGroups && data )
348           d->removeGroups( sm, data->_srcHyp );
349       }
350   }
351   //--------------------------------------------------------------------------------
352   /*!
353    * \brief Clear _ImportData::_n2n.
354    *        _n2n is usefull within one mesh.Compute() only
355    */
356   void _Listener::clearN2N( SMESH_Mesh* tgtMesh )
357   {
358     list< _ImportData >& dList = get()->_tgtMesh2ImportData[tgtMesh];
359     list< _ImportData >::iterator d = dList.begin();
360     for ( ; d != dList.end(); ++d )
361       d->_n2n.clear();
362   }
363   //--------------------------------------------------------------------------------
364   /*!
365    * \brief Clear submeshes and remove imported mesh and/or groups if necessary
366    *  \param sm - cleared submesh
367    *  \param data - data holding imported groups
368    */
369   void _Listener::clearSubmesh(SMESH_subMesh* sm, _ListenerData* data, bool clearAllSub)
370   {
371     list< _ImportData > &  dList = _tgtMesh2ImportData[ sm->GetFather() ];
372     list< _ImportData >::iterator d = dList.begin();
373     for ( ; d != dList.end(); ++d )
374     {
375       if ( !d->_subM.count( sm )) continue;
376       if ( (*d)._computedSubM.erase( sm ) )
377       {
378         bool copyMesh = !d->_copyMeshSubM.empty();
379         if ( copyMesh || clearAllSub )
380         {
381           // remove imported mesh and groups
382           d->removeImportedMesh( sm->GetFather()->GetMeshDS() );
383
384           if ( data )
385             d->removeGroups( sm, data->_srcHyp );
386
387           // clear the rest submeshes
388           if ( !d->_computedSubM.empty() )
389           {
390             d->_computedSubM.clear();
391             set< SMESH_subMesh*, _SubLess>::iterator sub = d->_subM.begin();
392             for ( ; sub != d->_subM.end(); ++sub )
393             {
394               SMESH_subMesh* subM = *sub;
395               _ListenerData* hypData = (_ListenerData*) subM->GetEventListenerData( get() );
396               if ( hypData )
397                 d->removeGroups( sm, hypData->_srcHyp );
398
399               subM->ComputeStateEngine( SMESH_subMesh::CLEAN );
400               if ( subM->GetSubShape().ShapeType() == TopAbs_FACE )
401                 subM->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
402             }
403           }
404         }
405         sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
406         if ( sm->GetSubShape().ShapeType() == TopAbs_FACE )
407           sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
408       }
409       if ( data )
410         d->trackHypParams( sm, data->_srcHyp );
411       d->_n2n.clear();
412       d->_e2e.clear();
413     }
414   }
415   //--------------------------------------------------------------------------------
416   /*!
417    * \brief Remove imported mesh and/or groups
418    */
419   void _Listener::ProcessEvent(const int                       event,
420                                const int                       eventType,
421                                SMESH_subMesh*                  subMesh,
422                                SMESH_subMeshEventListenerData* data,
423                                const SMESH_Hypothesis*         /*hyp*/)
424   {
425     if ( data && data->myType == WAIT_HYP_MODIF )
426     {
427       // event of Import submesh
428       if ( SMESH_subMesh::MODIF_HYP  == event &&
429            SMESH_subMesh::ALGO_EVENT == eventType )
430       {
431         // re-call SetEventListener() to take into account valid parameters
432         // of ImportSource hypothesis
433         if ( SMESH_Algo* algo = subMesh->GetAlgo() )
434           algo->SetEventListener( subMesh );
435       }
436     }
437     else if ( data && data->myType == LISTEN_SRC_MESH )
438     {
439       // event of source mesh
440       if ( SMESH_subMesh::COMPUTE_EVENT == eventType )
441       {
442         switch ( event ) {
443         case SMESH_subMesh::CLEAN:
444           // source mesh cleaned -> clean target mesh
445           clearSubmesh( data->mySubMeshes.front(), (_ListenerData*) data, /*all=*/true );
446           break;
447         case SMESH_subMesh::SUBMESH_COMPUTED: {
448           // source mesh computed -> reset FAILED state of Import submeshes to
449           // READY_TO_COMPUTE
450           SMESH_Mesh* srcMesh = subMesh->GetFather();
451           if ( srcMesh->NbEdges() > 0 || srcMesh->NbFaces() > 0 )
452           {
453             SMESH_Mesh* m = data->mySubMeshes.front()->GetFather();
454             if ( SMESH_subMesh* sm1 = m->GetSubMeshContaining(1))
455             {
456               sm1->ComputeStateEngine(SMESH_subMesh::SUBMESH_COMPUTED );
457               sm1->ComputeSubMeshStateEngine( SMESH_subMesh::SUBMESH_COMPUTED );
458             }
459           }
460           break;
461         }
462         default:;
463         }
464       }
465       if ( !data->mySubMeshes.empty() )
466         clearN2N( data->mySubMeshes.front()->GetFather() );
467     }
468     else // event of Import submesh
469     {
470       // find out what happens: import hyp modified or removed
471       bool removeImport = false, modifHyp = false;
472       if ( SMESH_subMesh::ALGO_EVENT == eventType )
473         modifHyp = true;
474       if ( subMesh->GetAlgoState() != SMESH_subMesh::HYP_OK )
475       {
476         removeImport = true;
477       }
478       else if (( SMESH_subMesh::REMOVE_ALGO == event ||
479                  SMESH_subMesh::REMOVE_FATHER_ALGO == event ) &&
480                SMESH_subMesh::ALGO_EVENT == eventType )
481       {
482         SMESH_Algo* algo = subMesh->GetAlgo();
483         removeImport = ( strncmp( "Import", algo->GetName(), 6 ) != 0 );
484       }
485
486       if ( removeImport )
487       {
488         // treate removal of Import algo from subMesh
489         removeSubmesh( subMesh, (_ListenerData*) data );
490       }
491       else if ( modifHyp ||
492                 ( SMESH_subMesh::CLEAN         == event &&
493                   SMESH_subMesh::COMPUTE_EVENT == eventType))
494       {
495         // treate modification of ImportSource hypothesis
496         clearSubmesh( subMesh, (_ListenerData*) data, /*all=*/false );
497       }
498       else if ( SMESH_subMesh::CHECK_COMPUTE_STATE == event &&
499                 SMESH_subMesh::COMPUTE_EVENT       == eventType )
500       {
501         // check compute state of all submeshes impoting from same src mesh;
502         // this is to take into account 1D computed submeshes hidden by 2D import algo;
503         // else source mesh is not copied as _subM.size != _computedSubM.size()
504         list< _ImportData > &  dList = _tgtMesh2ImportData[ subMesh->GetFather() ];
505         list< _ImportData >::iterator d = dList.begin();
506         for ( ; d != dList.end(); ++d )
507           if ( d->_subM.count( subMesh ))
508           {
509             set<SMESH_subMesh*,_SubLess>::iterator smIt = d->_subM.begin();
510             for( ; smIt != d->_subM.end(); ++smIt )
511               if ( (*smIt)->IsMeshComputed() )
512                 d->_computedSubM.insert( *smIt);
513           }
514       }
515       // Clear _ImportData::_n2n if it's no more useful, i.e. when
516       // the event is not within mesh.Compute()
517       if ( SMESH_subMesh::ALGO_EVENT == eventType )
518         clearN2N( subMesh->GetFather() );
519     }
520   }
521
522   //================================================================================
523   /*!
524    * \brief Return an ID of submesh to store nodes and elements of a copied mesh
525    */
526   //================================================================================
527
528   int getSubmeshIDForCopiedMesh(const SMESHDS_Mesh* srcMeshDS,
529                                 SMESH_Mesh*         tgtMesh)
530   {
531     // To get SMESH_subMesh corresponding to srcMeshDS we need to have a shape
532     // for which SMESHDS_Mesh::IsGroupOfSubShapes() returns true.
533     // And this shape must be different from sub-shapes of the main shape.
534     // So we create a compound containing
535     // 1) some sub-shapes of SMESH_Mesh::PseudoShape() corresponding to
536     //    srcMeshDS->GetPersistentId()
537     // 2) the 1-st vertex of the main shape to assure
538     //    SMESHDS_Mesh::IsGroupOfSubShapes(shape)==true
539     TopoDS_Shape shapeForSrcMesh;
540     TopTools_IndexedMapOfShape pseudoSubShapes;
541     TopExp::MapShapes( SMESH_Mesh::PseudoShape(), pseudoSubShapes );
542
543     // index of pseudoSubShapes corresponding to srcMeshDS
544     int    subIndex = 1 + srcMeshDS->GetPersistentId() % pseudoSubShapes.Extent();
545     int nbSubShapes = 1 + srcMeshDS->GetPersistentId() / pseudoSubShapes.Extent();
546
547     // try to find already present shapeForSrcMesh
548     SMESHDS_Mesh* tgtMeshDS = tgtMesh->GetMeshDS();
549     for ( int i = tgtMeshDS->MaxShapeIndex(); i > 0 && shapeForSrcMesh.IsNull(); --i )
550     {
551       const TopoDS_Shape& s = tgtMeshDS->IndexToShape(i);
552       if ( s.ShapeType() != TopAbs_COMPOUND ) break;
553       TopoDS_Iterator sSubIt( s );
554       for ( int iSub = 0; iSub < nbSubShapes && sSubIt.More(); ++iSub, sSubIt.Next() )
555         if ( pseudoSubShapes( subIndex+iSub ).IsSame( sSubIt.Value()))
556           if ( iSub+1 == nbSubShapes )
557           {
558             shapeForSrcMesh = s;
559             break;
560           }
561     }
562     if ( shapeForSrcMesh.IsNull() )
563     {
564       // make a new shapeForSrcMesh
565       BRep_Builder aBuilder;
566       TopoDS_Compound comp;
567       aBuilder.MakeCompound( comp );
568       shapeForSrcMesh = comp;
569       for ( int iSub = 0; iSub < nbSubShapes; ++iSub )
570         aBuilder.Add( comp, pseudoSubShapes( subIndex+iSub ));
571       TopExp_Explorer vExp( tgtMeshDS->ShapeToMesh(), TopAbs_VERTEX );
572       aBuilder.Add( comp, vExp.Current() );
573     }
574     SMESH_subMesh* sm = tgtMesh->GetSubMesh( shapeForSrcMesh );
575     SMESHDS_SubMesh* smDS = sm->GetSubMeshDS();
576     if ( !smDS )
577       smDS = tgtMeshDS->NewSubMesh( sm->GetId() );
578
579     // make ordinary submesh from a complex one
580     if ( smDS->IsComplexSubmesh() )
581     {
582       list< const SMESHDS_SubMesh* > subSM;
583       SMESHDS_SubMeshIteratorPtr smIt = smDS->GetSubMeshIterator();
584       while ( smIt->more() ) subSM.push_back( smIt->next() );
585       list< const SMESHDS_SubMesh* >::iterator sub = subSM.begin();
586       for ( ; sub != subSM.end(); ++sub)
587         smDS->RemoveSubMesh( *sub );
588     }
589     return sm->GetId();
590   }
591
592   //================================================================================
593   /*!
594    * \brief Return a submesh to store nodes and elements of a copied mesh
595    * and set event listeners in order to clear
596    * imported mesh and groups as soon as submesh state requires it
597    */
598   //================================================================================
599
600   SMESHDS_SubMesh* getSubmeshForCopiedMesh(const SMESH_Mesh*                    srcMesh,
601                                            SMESH_Mesh*                          tgtMesh,
602                                            const TopoDS_Shape&                  tgtShape,
603                                            StdMeshers_Import_1D::TNodeNodeMap*& n2n,
604                                            StdMeshers_Import_1D::TElemElemMap*& e2e,
605                                            bool &                               toCopyGroups)
606   {
607     StdMeshers_Import_1D::getMaps( srcMesh, tgtMesh, n2n,e2e );
608
609     _ImportData* iData = _Listener::getImportData(srcMesh,tgtMesh);
610
611     SMESH_subMesh* importedSM = tgtMesh->GetSubMesh( tgtShape );
612     iData->addComputed( importedSM );
613     if ( iData->_computedSubM.size() != iData->_subM.size() )
614       return 0; // not all submeshes computed yet
615
616     toCopyGroups = !iData->_copyGroupSubM.empty();
617
618     if ( !iData->_copyMeshSubM.empty())
619     {
620       // make submesh to store a copied mesh
621       int smID = getSubmeshIDForCopiedMesh( srcMesh->GetMeshDS(), tgtMesh );
622       SMESHDS_SubMesh* subDS = tgtMesh->GetMeshDS()->NewSubMesh( smID );
623
624       iData->_importMeshSubID = smID;
625       iData->_importMeshSubDS = subDS;
626       return subDS;
627     }
628     return 0;
629   }
630
631 } // namespace
632
633
634 //=============================================================================
635 /*!
636  * Import elements from the other mesh
637  */
638 //=============================================================================
639
640 bool StdMeshers_Import_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & theShape)
641 {
642   if ( !_sourceHyp ) return false;
643
644   //MESSAGE("---------> StdMeshers_Import_1D::Compute");
645   const vector<SMESH_Group*>& srcGroups = _sourceHyp->GetGroups(/*loaded=*/true);
646   if ( srcGroups.empty() )
647     return error("Invalid source groups");
648
649   SMESH_MesherHelper helper(theMesh);
650   helper.SetSubShape(theShape);
651   SMESHDS_Mesh* tgtMesh = theMesh.GetMeshDS();
652
653   const TopoDS_Edge& geomEdge = TopoDS::Edge( theShape );
654   const double edgeTol = BRep_Tool::Tolerance( geomEdge );
655   const int shapeID = tgtMesh->ShapeToIndex( geomEdge );
656
657   set<int> subShapeIDs;
658   subShapeIDs.insert( shapeID );
659
660   // get nodes on vertices
661   list < SMESH_TNodeXYZ > vertexNodes;
662   list < SMESH_TNodeXYZ >::iterator vNIt;
663   TopExp_Explorer vExp( theShape, TopAbs_VERTEX );
664   for ( ; vExp.More(); vExp.Next() )
665   {
666     const TopoDS_Vertex& v = TopoDS::Vertex( vExp.Current() );
667     if ( !subShapeIDs.insert( tgtMesh->ShapeToIndex( v )).second )
668       continue; // closed edge
669     const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, tgtMesh );
670     if ( !n )
671     {
672       _gen->Compute(theMesh,v,/*anUpward=*/true);
673       n = SMESH_Algo::VertexNode( v, tgtMesh );
674       //MESSAGE("_gen->Compute " << n);
675       if ( !n ) return false; // very strange
676     }
677     vertexNodes.push_back( SMESH_TNodeXYZ( n ));
678     //MESSAGE("SMESH_Algo::VertexNode " << n->GetID() << " " << n->X() << " " << n->Y() << " " << n->Z() );
679   }
680
681   // import edges from groups
682   TNodeNodeMap* n2n;
683   TElemElemMap* e2e;
684   for ( int iG = 0; iG < srcGroups.size(); ++iG )
685   {
686     const SMESHDS_GroupBase* srcGroup = srcGroups[iG]->GetGroupDS();
687
688     const int meshID = srcGroup->GetMesh()->GetPersistentId();
689     const SMESH_Mesh* srcMesh = GetMeshByPersistentID( meshID );
690     if ( !srcMesh ) continue;
691     getMaps( srcMesh, &theMesh, n2n, e2e );
692
693     SMDS_ElemIteratorPtr srcElems = srcGroup->GetElements();
694     vector<const SMDS_MeshNode*> newNodes;
695     SMDS_MeshNode *tmpNode = helper.AddNode(0,0,0);
696     double u = 0.314159; // "random" value between 0 and 1, avoid 0 and 1, false detection possible on edge restrictions
697     while ( srcElems->more() ) // loop on group contents
698     {
699       const SMDS_MeshElement* edge = srcElems->next();
700       // find or create nodes of a new edge
701       newNodes.resize( edge->NbNodes() );
702       //MESSAGE("edge->NbNodes " << edge->NbNodes());
703       newNodes.back() = 0;
704       SMDS_MeshElement::iterator node = edge->begin_nodes();
705       SMESH_TNodeXYZ a(edge->GetNode(0));
706       // --- define a tolerance relative to the length of an edge
707       double mytol = a.Distance(edge->GetNode(edge->NbNodes()-1))/25;
708       //mytol = max(1.E-5, 10*edgeTol); // too strict and not necessary
709       //MESSAGE("mytol = " << mytol);
710       for ( unsigned i = 0; i < newNodes.size(); ++i, ++node )
711       {
712         TNodeNodeMap::iterator n2nIt = n2n->insert( make_pair( *node, (SMDS_MeshNode*)0 )).first;
713         if ( n2nIt->second )
714         {
715           if ( !subShapeIDs.count( n2nIt->second->getshapeId() ))
716             break;
717         }
718         else
719         {
720           // find an existing vertex node
721           double checktol = max(1.E-10, 10*edgeTol*edgeTol);
722           for ( vNIt = vertexNodes.begin(); vNIt != vertexNodes.end(); ++vNIt)
723             if ( vNIt->SquareDistance( *node ) < checktol)
724             {
725               //MESSAGE("SquareDistance " << vNIt->SquareDistance( *node ) << " checktol " << checktol <<" "<<vNIt->X()<<" "<<vNIt->Y()<<" "<<vNIt->Z());
726               (*n2nIt).second = vNIt->_node;
727               vertexNodes.erase( vNIt );
728               break;
729             }
730             else if ( vNIt->SquareDistance( *node ) < 10*checktol)
731               MESSAGE("SquareDistance missed" << vNIt->SquareDistance( *node ) << " checktol " << checktol <<" "<<vNIt->X()<<" "<<vNIt->Y()<<" "<<vNIt->Z());
732         }
733         if ( !n2nIt->second )
734         {
735           // find out if node lies on theShape
736           //double dxyz[4];
737           tmpNode->setXYZ( (*node)->X(), (*node)->Y(), (*node)->Z());
738           if ( helper.CheckNodeU( geomEdge, tmpNode, u, mytol, /*force=*/true)) // , dxyz )) // dxyz used for debug purposes
739           {
740             SMDS_MeshNode* newNode = tgtMesh->AddNode( (*node)->X(), (*node)->Y(), (*node)->Z());
741             n2nIt->second = newNode;
742             tgtMesh->SetNodeOnEdge( newNode, shapeID, u );
743             //MESSAGE("u=" << u << " " << newNode->X()<< " " << newNode->Y()<< " " << newNode->Z());
744             //MESSAGE("d=" << dxyz[0] << " " << dxyz[1] << " " << dxyz[2] << " " << dxyz[3]);
745           }
746         }
747         if ( !(newNodes[i] = n2nIt->second ))
748           break;
749       }
750       if ( !newNodes.back() )
751       {
752         //MESSAGE("not all nodes of edge lie on theShape");
753         continue; // not all nodes of edge lie on theShape
754       }
755
756       // make a new edge
757       SMDS_MeshElement * newEdge;
758       if ( newNodes.size() == 3 )
759         newEdge = tgtMesh->AddEdge( newNodes[0], newNodes[1], newNodes[2] );
760       else
761         newEdge = tgtMesh->AddEdge( newNodes[0], newNodes[1]);
762       //MESSAGE("add Edge " << newNodes[0]->GetID() << " " << newNodes[1]->GetID());
763       tgtMesh->SetMeshElementOnShape( newEdge, shapeID );
764       e2e->insert( make_pair( edge, newEdge ));
765     }
766     helper.GetMeshDS()->RemoveNode(tmpNode);
767   }
768   if ( n2n->empty())
769     return error("Empty source groups");
770
771   // check if the whole geom edge is covered by imported segments;
772   // the check consist in passing by segments from one vetrex node to another
773   bool isEdgeMeshed = false;
774   if ( SMESHDS_SubMesh* tgtSM = tgtMesh->MeshElements( theShape ))
775   {
776     const TopoDS_Vertex& v = ( vExp.ReInit(), TopoDS::Vertex( vExp.Current() ));
777     const SMDS_MeshNode* n = SMESH_Algo::VertexNode( v, tgtMesh );
778     const SMDS_MeshElement* seg = 0;
779     SMDS_ElemIteratorPtr segIt = n->GetInverseElementIterator(SMDSAbs_Edge);
780     while ( segIt->more() && !seg )
781       if ( !tgtSM->Contains( seg = segIt->next()))
782         seg = 0;
783     int nbPassedSegs = 0;
784     while ( seg )
785     {
786       ++nbPassedSegs;
787       const SMDS_MeshNode* n2 = seg->GetNode(0);
788       n = ( n2 == n ? seg->GetNode(1) : n2 );
789       if ( n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX )
790         break;
791       const SMDS_MeshElement* seg2 = 0;
792       segIt = n->GetInverseElementIterator(SMDSAbs_Edge);
793       while ( segIt->more() && !seg2 )
794         if ( seg == ( seg2 = segIt->next()))
795           seg2 = 0;
796       seg = seg2;
797     }
798     if (nbPassedSegs > 0 && tgtSM->NbElements() > nbPassedSegs )
799       return error( "Source elements overlap one another");
800
801     isEdgeMeshed = ( tgtSM->NbElements() == nbPassedSegs &&
802                      n->GetPosition()->GetTypeOfPosition() == SMDS_TOP_VERTEX );
803   }
804   if ( !isEdgeMeshed )
805     return error( "Source elements don't cover totally the geometrical edge" );
806
807   // copy meshes
808   vector<SMESH_Mesh*> srcMeshes = _sourceHyp->GetSourceMeshes();
809   for ( unsigned i = 0; i < srcMeshes.size(); ++i )
810     importMesh( srcMeshes[i], theMesh, _sourceHyp, theShape );
811
812   return true;
813 }
814
815 //================================================================================
816 /*!
817  * \brief Copy mesh and groups
818  */
819 //================================================================================
820
821 void StdMeshers_Import_1D::importMesh(const SMESH_Mesh*          srcMesh,
822                                       SMESH_Mesh &               tgtMesh,
823                                       StdMeshers_ImportSource1D* srcHyp,
824                                       const TopoDS_Shape&        tgtShape)
825 {
826   // get submesh to store the imported mesh
827   TNodeNodeMap* n2n;
828   TElemElemMap* e2e;
829   bool toCopyGroups;
830   SMESHDS_SubMesh* tgtSubMesh =
831     getSubmeshForCopiedMesh( srcMesh, &tgtMesh, tgtShape, n2n, e2e, toCopyGroups );
832   if ( !tgtSubMesh || tgtSubMesh->NbNodes() + tgtSubMesh->NbElements() > 0 )
833     return; // not to copy srcMeshDS twice
834
835   SMESHDS_Mesh* tgtMeshDS = tgtMesh.GetMeshDS();
836   SMESH_MeshEditor additor( &tgtMesh );
837
838   // 1. Copy mesh
839
840   vector<const SMDS_MeshNode*> newNodes;
841   const SMESHDS_Mesh* srcMeshDS = srcMesh->GetMeshDS();
842   SMDS_ElemIteratorPtr eIt = srcMeshDS->elementsIterator();
843   while ( eIt->more() )
844   {
845     const SMDS_MeshElement* elem = eIt->next();
846     TElemElemMap::iterator e2eIt = e2e->insert( make_pair( elem, (SMDS_MeshElement*)0 )).first;
847     if ( e2eIt->second ) continue; // already copied by Compute()
848     newNodes.resize( elem->NbNodes() );
849     SMDS_MeshElement::iterator node = elem->begin_nodes();
850     for ( unsigned i = 0; i < newNodes.size(); ++i, ++node )
851     {
852       TNodeNodeMap::iterator n2nIt = n2n->insert( make_pair( *node, (SMDS_MeshNode*)0 )).first;
853       if ( !n2nIt->second )
854       {
855         (*n2nIt).second = tgtMeshDS->AddNode( (*node)->X(), (*node)->Y(), (*node)->Z());
856         tgtSubMesh->AddNode( n2nIt->second );
857       }
858       newNodes[i] = n2nIt->second;
859     }
860     const SMDS_MeshElement* newElem =
861       tgtMeshDS->FindElement( newNodes, elem->GetType(), /*noMedium=*/false );
862     if ( !newElem )
863     {
864       newElem = additor.AddElement( newNodes, elem->GetType(), elem->IsPoly());
865       tgtSubMesh->AddElement( newElem );
866     }
867     if ( toCopyGroups )
868       (*e2eIt).second = newElem;
869   }
870   // copy free nodes
871   if ( srcMeshDS->NbNodes() > n2n->size() )
872   {
873     SMDS_NodeIteratorPtr nIt = srcMeshDS->nodesIterator();
874     while( nIt->more() )
875     {
876       const SMDS_MeshNode* node = nIt->next();
877       if ( node->NbInverseElements() == 0 )
878       {
879         const SMDS_MeshNode* newNode = tgtMeshDS->AddNode( node->X(), node->Y(), node->Z());
880         n2n->insert( make_pair( node, newNode ));
881         tgtSubMesh->AddNode( newNode );
882       }
883     }
884   }
885
886   // 2. Copy groups
887
888   vector<SMESH_Group*> resultGroups;
889   if ( toCopyGroups )
890   {
891     // collect names of existing groups to assure uniqueness of group names within a type
892     map< SMDSAbs_ElementType, set<string> > namesByType;
893     SMESH_Mesh::GroupIteratorPtr groupIt = tgtMesh.GetGroups();
894     while ( groupIt->more() )
895     {
896       SMESH_Group* tgtGroup = groupIt->next();
897       namesByType[ tgtGroup->GetGroupDS()->GetType() ].insert( tgtGroup->GetName() );
898     }
899     if (srcMesh)
900     {
901       SMESH_Mesh::GroupIteratorPtr groupIt = srcMesh->GetGroups();
902       while ( groupIt->more() )
903       {
904         SMESH_Group* srcGroup = groupIt->next();
905         SMESHDS_GroupBase* srcGroupDS = srcGroup->GetGroupDS();
906         string name = srcGroup->GetName();
907         int nb = 1;
908         while ( !namesByType[ srcGroupDS->GetType() ].insert( name ).second )
909           name = SMESH_Comment(srcGroup->GetName()) << "_imported_" << nb++;
910         SMESH_Group* newGroup = tgtMesh.AddGroup( srcGroupDS->GetType(), name.c_str(), nb );
911         SMESHDS_Group* newGroupDS = (SMESHDS_Group*)newGroup->GetGroupDS();
912         resultGroups.push_back( newGroup );
913
914         eIt = srcGroupDS->GetElements();
915         if ( srcGroupDS->GetType() == SMDSAbs_Node )
916           while (eIt->more())
917           {
918             TNodeNodeMap::iterator n2nIt = n2n->find((const SMDS_MeshNode*) eIt->next() );
919             if ( n2nIt != n2n->end() && n2nIt->second )
920               newGroupDS->SMDSGroup().Add((*n2nIt).second );
921           }
922         else
923           while (eIt->more())
924           {
925             TElemElemMap::iterator e2eIt = e2e->find( eIt->next() );
926             if ( e2eIt != e2e->end() && e2eIt->second )
927               newGroupDS->SMDSGroup().Add((*e2eIt).second );
928           }
929       }
930     }
931   }
932   n2n->clear();
933   e2e->clear();
934
935   // Remember created groups in order to remove them as soon as the srcHyp is
936   // modified or something other similar happens. This imformation must be persistent,
937   // for that store them in a hypothesis as it stores its values in the file anyway
938   srcHyp->StoreResultGroups( resultGroups, *srcMeshDS, *tgtMeshDS );
939 }
940
941 //=============================================================================
942 /*!
943  * \brief Set needed event listeners and create a submesh for a copied mesh
944  *
945  * This method is called only if a submesh has HYP_OK algo_state.
946  */
947 //=============================================================================
948
949 void StdMeshers_Import_1D::setEventListener(SMESH_subMesh*             subMesh,
950                                             StdMeshers_ImportSource1D* sourceHyp)
951 {
952   if ( sourceHyp )
953   {
954     vector<SMESH_Mesh*> srcMeshes = sourceHyp->GetSourceMeshes();
955     if ( srcMeshes.empty() )
956       _Listener::waitHypModification( subMesh );
957     for ( unsigned i = 0; i < srcMeshes.size(); ++i )
958       // set a listener to remove the imported mesh and groups
959       _Listener::storeImportSubmesh( subMesh, srcMeshes[i], sourceHyp );
960   }
961 }
962 void StdMeshers_Import_1D::SetEventListener(SMESH_subMesh* subMesh)
963 {
964   if ( !_sourceHyp )
965   {
966     const TopoDS_Shape& tgtShape = subMesh->GetSubShape();
967     SMESH_Mesh*         tgtMesh  = subMesh->GetFather();
968     Hypothesis_Status aStatus;
969     CheckHypothesis( *tgtMesh, tgtShape, aStatus );
970   }
971   setEventListener( subMesh, _sourceHyp );
972 }
973
974 void StdMeshers_Import_1D::SubmeshRestored(SMESH_subMesh* subMesh)
975 {
976   SetEventListener(subMesh);
977 }
978
979 //=============================================================================
980 /*!
981  * Predict nb of mesh entities created by Compute()
982  */
983 //=============================================================================
984
985 bool StdMeshers_Import_1D::Evaluate(SMESH_Mesh &         theMesh,
986                                     const TopoDS_Shape & theShape,
987                                     MapShapeNbElems&     aResMap)
988 {
989   if ( !_sourceHyp ) return false;
990
991   const vector<SMESH_Group*>& srcGroups = _sourceHyp->GetGroups();
992   if ( srcGroups.empty() )
993     return error("Invalid source groups");
994
995   vector<int> aVec(SMDSEntity_Last,0);
996
997   bool toCopyMesh, toCopyGroups;
998   _sourceHyp->GetCopySourceMesh(toCopyMesh, toCopyGroups);
999   if ( toCopyMesh ) // the whole mesh is copied
1000   {
1001     vector<SMESH_Mesh*> srcMeshes = _sourceHyp->GetSourceMeshes();
1002     for ( unsigned i = 0; i < srcMeshes.size(); ++i )
1003     {
1004       SMESH_subMesh* sm = getSubMeshOfCopiedMesh( theMesh, *srcMeshes[i]);
1005       if ( !sm || aResMap.count( sm )) continue; // already counted
1006       aVec.assign( SMDSEntity_Last, 0);
1007       const SMDS_MeshInfo& aMeshInfo = srcMeshes[i]->GetMeshDS()->GetMeshInfo();
1008       for (int i = 0; i < SMDSEntity_Last; i++)
1009         aVec[i] = aMeshInfo.NbEntities((SMDSAbs_EntityType)i);
1010     }
1011   }
1012   else
1013   {
1014     SMESH_MesherHelper helper(theMesh);
1015
1016     const TopoDS_Edge& geomEdge = TopoDS::Edge( theShape );
1017     const double edgeTol = helper.MaxTolerance( geomEdge );
1018
1019     // take into account nodes on vertices
1020     TopExp_Explorer vExp( theShape, TopAbs_VERTEX );
1021     for ( ; vExp.More(); vExp.Next() )
1022       theMesh.GetSubMesh( vExp.Current())->Evaluate( aResMap );
1023
1024     // count edges imported from groups
1025     int nbEdges = 0, nbQuadEdges = 0;
1026     for ( int iG = 0; iG < srcGroups.size(); ++iG )
1027     {
1028       const SMESHDS_GroupBase* srcGroup = srcGroups[iG]->GetGroupDS();
1029       SMDS_ElemIteratorPtr srcElems = srcGroup->GetElements();
1030       SMDS_MeshNode *tmpNode = helper.AddNode(0,0,0);
1031       while ( srcElems->more() ) // loop on group contents
1032       {
1033         const SMDS_MeshElement* edge = srcElems->next();
1034         // find out if edge is located on geomEdge by projecting
1035         // a middle of edge to geomEdge
1036         SMESH_TNodeXYZ p1( edge->GetNode(0));
1037         SMESH_TNodeXYZ p2( edge->GetNode(1));
1038         gp_XYZ middle = ( p1 + p2 ) / 2.;
1039         tmpNode->setXYZ( middle.X(), middle.Y(), middle.Z());
1040         double u = 0;
1041         if ( helper.CheckNodeU( geomEdge, tmpNode, u, 10 * edgeTol, /*force=*/true ))
1042           ++( edge->IsQuadratic() ? nbQuadEdges : nbEdges);
1043       }
1044       helper.GetMeshDS()->RemoveNode(tmpNode);
1045     }
1046
1047     int nbNodes = nbEdges + 2 * nbQuadEdges - 1;
1048
1049     aVec[SMDSEntity_Node     ] = nbNodes;
1050     aVec[SMDSEntity_Edge     ] = nbEdges;
1051     aVec[SMDSEntity_Quad_Edge] = nbQuadEdges;
1052   }
1053
1054   SMESH_subMesh * sm = theMesh.GetSubMesh(theShape);
1055   aResMap.insert(make_pair(sm,aVec));
1056
1057   return true;
1058 }
1059
1060 //================================================================================
1061 /*!
1062  * \brief Return node-node and element-element maps for import of geiven source mesh
1063  */
1064 //================================================================================
1065
1066 void StdMeshers_Import_1D::getMaps(const SMESH_Mesh* srcMesh,
1067                                    SMESH_Mesh*       tgtMesh,
1068                                    TNodeNodeMap*&    n2n,
1069                                    TElemElemMap*&    e2e)
1070 {
1071   _ImportData* iData = _Listener::getImportData(srcMesh,tgtMesh);
1072   n2n = &iData->_n2n;
1073   e2e = &iData->_e2e;
1074   if ( iData->_copyMeshSubM.empty() )
1075   {
1076     // n2n->clear(); -- for sharing nodes on EDGEs
1077     e2e->clear();
1078   }
1079 }
1080
1081 //================================================================================
1082 /*!
1083  * \brief Return submesh corresponding to the copied mesh
1084  */
1085 //================================================================================
1086
1087 SMESH_subMesh* StdMeshers_Import_1D::getSubMeshOfCopiedMesh( SMESH_Mesh& tgtMesh,
1088                                                              SMESH_Mesh& srcMesh )
1089 {
1090   _ImportData* iData = _Listener::getImportData(&srcMesh,&tgtMesh);
1091   if ( iData->_copyMeshSubM.empty() ) return 0;
1092   SMESH_subMesh* sm = tgtMesh.GetSubMeshContaining( iData->_importMeshSubID );
1093   return sm;
1094 }
1095