Salome HOME
52456: Propagation does not work
[modules/smesh.git] / src / StdMeshers / StdMeshers_Propagation.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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_Propagation.cxx
25 //  Module : SMESH
26 //
27 #include "StdMeshers_Propagation.hxx"
28
29 #include "utilities.h"
30
31 #include "SMDS_SetIterator.hxx"
32 #include "SMESH_Algo.hxx"
33 #include "SMESH_Gen.hxx"
34 #include "SMESH_HypoFilter.hxx"
35 #include "SMESH_Mesh.hxx"
36 #include "SMESH_subMesh.hxx"
37
38 #include <BRepTools_WireExplorer.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
40 #include <TopTools_MapOfShape.hxx>
41 #include <TopoDS.hxx>
42
43 #define DBGMSG(txt) \
44   //  cout << txt << endl;
45
46 using namespace std;
47
48 namespace {
49
50   // =======================================================================
51   /*!
52    * \brief Listener managing propagation of 1D hypotheses
53    */
54   // =======================================================================
55
56   class PropagationMgr: public SMESH_subMeshEventListener
57   {
58   public:
59     static PropagationMgr* GetListener();
60     /*!
61      * \brief Set listener on edge submesh
62      */
63     static void Set(SMESH_subMesh * submesh);
64     /*!
65      * \brief Return an edge from which hypotheses are propagated from
66      */
67     static TopoDS_Edge GetSource(SMESH_subMesh * submesh,
68                                  bool&           isPropagOfDistribution);
69     /*!
70      * \brief Does it's main job
71      */
72     void ProcessEvent(const int          event,
73                       const int          eventType,
74                       SMESH_subMesh*     subMesh,
75                       SMESH_subMeshEventListenerData* data,
76                       const SMESH_Hypothesis*         hyp = 0);
77   private:
78     PropagationMgr();
79   };
80 }
81
82 //=============================================================================
83 /*!
84  * StdMeshers_Propagation Implementation
85  */
86 //=============================================================================
87
88 StdMeshers_Propagation::StdMeshers_Propagation (int hypId, int studyId, SMESH_Gen * gen)
89   : SMESH_Hypothesis(hypId, studyId, gen)
90 {
91   _name = GetName();
92   _param_algo_dim = -1; // 1D auxiliary
93 }
94 StdMeshers_PropagOfDistribution::StdMeshers_PropagOfDistribution (int hypId,
95                                                                   int studyId,
96                                                                   SMESH_Gen * gen)
97   : StdMeshers_Propagation(hypId, studyId, gen)                        { _name = GetName(); }
98 StdMeshers_Propagation::~StdMeshers_Propagation()                      {}
99 string StdMeshers_Propagation::GetName ()                              { return "Propagation"; }
100 string StdMeshers_PropagOfDistribution::GetName ()                     { return "PropagOfDistribution"; }
101 ostream & StdMeshers_Propagation::SaveTo (ostream & save)              { return save; }
102 istream & StdMeshers_Propagation::LoadFrom (istream & load)            { return load; }
103 bool StdMeshers_Propagation::SetParametersByMesh(const SMESH_Mesh*,
104                                                  const TopoDS_Shape& ) { return false; }
105 bool StdMeshers_Propagation::SetParametersByDefaults(const TDefaults&,const SMESH_Mesh*) { return false; }
106 void StdMeshers_Propagation::SetPropagationMgr(SMESH_subMesh* subMesh) { PropagationMgr::Set( subMesh ); }
107 /*!
108  * \brief Return an edge from which hypotheses are propagated
109  */
110 TopoDS_Edge StdMeshers_Propagation::GetPropagationSource(SMESH_Mesh&         theMesh,
111                                                          const TopoDS_Shape& theEdge,
112                                                          bool&               isPropagOfDistribution)
113 {
114   return PropagationMgr::GetSource( theMesh.GetSubMeshContaining( theEdge ),
115                                     isPropagOfDistribution);
116 }
117
118 //=============================================================================
119 //=============================================================================
120 // PROPAGATION MANAGEMENT
121 //=============================================================================
122 //=============================================================================
123
124 namespace {
125
126   enum SubMeshState { WAIT_PROPAG_HYP, // propagation hyp or local 1D hyp is missing
127                       HAS_PROPAG_HYP,  // propag hyp on this submesh
128                       IN_CHAIN,        // submesh is in propagation chain
129                       LAST_IN_CHAIN,   // submesh with local 1D hyp breaking a chain
130                       MEANINGLESS_LAST };          // meaningless
131
132   struct PropagationMgrData : public EventListenerData
133   {
134     bool myForward; //!< true if a curve of edge in chain is codirected with one of source edge
135     bool myIsPropagOfDistribution; //!< type of Propagation hyp
136     PropagationMgrData( SubMeshState state=WAIT_PROPAG_HYP ): EventListenerData(true) {
137       myType = state; myForward = true; myIsPropagOfDistribution = false;
138     }
139     void Init() {
140       myType = WAIT_PROPAG_HYP;  mySubMeshes.clear(); myForward = true;
141       myIsPropagOfDistribution = false;
142     }
143     SubMeshState State() const {
144       return (SubMeshState) myType;
145     }
146     void SetState(SubMeshState state) {
147       myType = state;
148     }
149     void SetSource(SMESH_subMesh* sm ) {
150       mySubMeshes.clear(); if ( sm ) mySubMeshes.push_back( sm );
151     }
152     void AddSource(SMESH_subMesh* sm ) {
153       if ( sm ) mySubMeshes.push_back( sm );
154     }
155     void SetChain(list< SMESH_subMesh* >& chain ) {
156       mySubMeshes.clear(); mySubMeshes.splice( mySubMeshes.end(), chain );
157     }
158     SMESH_subMeshIteratorPtr GetChain() const;
159     SMESH_subMesh* GetSource() const;
160   };
161
162   //=============================================================================
163   /*!
164    * \brief return static PropagationMgr
165    */
166   PropagationMgr* PropagationMgr::GetListener()
167   {
168     static PropagationMgr theListener;
169     return &theListener;
170   }
171   PropagationMgr* getListener()
172   {
173     return PropagationMgr::GetListener();
174   }
175   //=============================================================================
176   /*!
177    * \brief return PropagationMgrData found on a submesh
178    */
179   PropagationMgrData* findData(SMESH_subMesh* sm)
180   {
181     if ( sm )
182       return static_cast< PropagationMgrData* >( sm->GetEventListenerData( getListener() ));
183     return 0;
184   }
185   //=============================================================================
186   /*!
187    * \brief return PropagationMgrData found on theEdge submesh
188    */
189   PropagationMgrData* findData(SMESH_Mesh& theMesh, const TopoDS_Shape& theEdge)
190   {
191     if ( theEdge.ShapeType() == TopAbs_EDGE )
192       return findData( theMesh.GetSubMeshContaining( theEdge ) );
193     return 0;
194   }
195   //=============================================================================
196   /*!
197    * \brief return existing or a new PropagationMgrData
198    */
199   PropagationMgrData* getData(SMESH_subMesh* sm)
200   {
201     PropagationMgrData* data = findData( sm );
202     if ( !data && sm ) {
203       data = new PropagationMgrData();
204       sm->SetEventListener( getListener(), data, sm );
205     }
206     return data;
207   }
208   //=============================================================================
209   /*!
210    * \brief Returns a local 1D hypothesis used for theEdge
211    */
212   const SMESH_Hypothesis* getLocal1DHyp (SMESH_Mesh&         theMesh,
213                                          const TopoDS_Shape& theEdge,
214                                          TopoDS_Shape*       theSssignedTo=0)
215   {
216     static SMESH_HypoFilter hypo;
217     hypo.Init( hypo.HasDim( 1 )).
218       AndNot ( hypo.IsAlgo() ).
219       AndNot ( hypo.IsAssignedTo( theMesh.GetShapeToMesh() ));
220
221     return theMesh.GetHypothesis( theEdge, hypo, true, theSssignedTo );
222   }
223   //=============================================================================
224   /*!
225    * \brief Returns a propagation hypothesis assigned to theEdge
226    */
227   const SMESH_Hypothesis* getProagationHyp (SMESH_Mesh&         theMesh,
228                                             const TopoDS_Shape& theEdge)
229   {
230     static SMESH_HypoFilter propagHypFilter;
231     if ( propagHypFilter.IsEmpty() )
232     {
233       propagHypFilter.
234         Init( SMESH_HypoFilter::HasName( StdMeshers_Propagation::GetName ())).
235         Or  ( SMESH_HypoFilter::HasName( StdMeshers_PropagOfDistribution::GetName ()));
236     }
237     return theMesh.GetHypothesis( theEdge, propagHypFilter, true );
238   }
239   //================================================================================
240   /*!
241    * \brief Return an iterator on a list of submeshes
242    */
243   SMESH_subMeshIteratorPtr iterate( list<SMESH_subMesh*>::const_iterator from,
244                                     list<SMESH_subMesh*>::const_iterator to)
245   {
246     typedef SMESH_subMesh* TsubMesh;
247     typedef SMDS_SetIterator< TsubMesh, list< TsubMesh >::const_iterator > TIterator;
248     return SMESH_subMeshIteratorPtr ( new TIterator( from, to ));
249   }
250   //================================================================================
251   /*!
252    * \brief Build propagation chain
253     * \param theMainSubMesh - the submesh with Propagation hypothesis
254    */
255   bool buildPropagationChain ( SMESH_subMesh* theMainSubMesh )
256   {
257     DBGMSG( "buildPropagationChain from " << theMainSubMesh->GetId() );
258     const TopoDS_Shape& theMainEdge = theMainSubMesh->GetSubShape();
259     if (theMainEdge.ShapeType() != TopAbs_EDGE) return true;
260
261     SMESH_Mesh* mesh = theMainSubMesh->GetFather();
262
263     TopoDS_Shape shapeOfHyp1D; // shape to which an hyp being propagated is assigned
264     const SMESH_Hypothesis* hyp1D = getLocal1DHyp( *mesh, theMainEdge, &shapeOfHyp1D );
265     SMESH_HypoFilter moreLocalCheck( SMESH_HypoFilter::IsMoreLocalThan( shapeOfHyp1D, *mesh ));
266
267     PropagationMgrData* chainData = getData( theMainSubMesh );
268     chainData->SetState( HAS_PROPAG_HYP );
269
270     if ( const SMESH_Hypothesis * propagHyp = getProagationHyp( *mesh, theMainEdge ))
271       chainData->myIsPropagOfDistribution =
272         ( StdMeshers_PropagOfDistribution::GetName() == propagHyp->GetName() );
273
274     // Edge submeshes, to which the 1D hypothesis will be propagated from theMainEdge
275     list<SMESH_subMesh*> & chain = chainData->mySubMeshes;
276     chain.clear();
277     chain.push_back( theMainSubMesh );
278
279     TopTools_MapOfShape checkedShapes;
280     checkedShapes.Add( theMainEdge );
281
282     list<SMESH_subMesh*>::iterator smIt = chain.begin();
283     for ( ; smIt != chain.end(); ++smIt )
284     {
285       const TopoDS_Edge& anE = TopoDS::Edge( (*smIt)->GetSubShape() );
286       PropagationMgrData* data = findData( *smIt );
287       if ( !data ) continue;
288
289       // Iterate on faces, having edge <anE>
290       TopTools_ListIteratorOfListOfShape itA (mesh->GetAncestors(anE));
291       for (; itA.More(); itA.Next())
292       {
293         // there are objects of different type among the ancestors of edge
294         if ( itA.Value().ShapeType() != TopAbs_WIRE /*|| !checkedShapes.Add( itA.Value() )*/)
295           continue;
296
297         // Get ordered edges and find index of anE in a sequence
298         BRepTools_WireExplorer aWE (TopoDS::Wire(itA.Value()));
299         vector<TopoDS_Edge> edges;
300         edges.reserve(4);
301         int edgeIndex = 0;
302         for (; aWE.More(); aWE.Next()) {
303           TopoDS_Edge edge = aWE.Current();
304           edge.Orientation( aWE.Orientation() );
305           if ( edge.IsSame( anE ))
306             edgeIndex = edges.size();
307           edges.push_back( edge );
308         }
309
310         // Find an edge opposite to anE
311         TopoDS_Edge anOppE;
312         if ( edges.size() < 4 ) {
313           continue; // too few edges
314         }
315         else if ( edges.size() == 4 ) {
316           int oppIndex = ( edgeIndex + 2 ) % 4;
317           anOppE = edges[ oppIndex ];
318         }
319         else {
320           // count nb sides
321           TopoDS_Edge prevEdge = anE;
322           int nbSide = 0, eIndex = edgeIndex + 1;
323           for ( int i = 0; i < edges.size(); ++i, ++eIndex )
324           {
325             if ( eIndex == edges.size() )
326               eIndex = 0;
327             if ( !SMESH_Algo::IsContinuous( prevEdge, edges[ eIndex ])) {
328               nbSide++;
329             }
330             else {
331               // check that anE is not a part of a composite side
332               if ( anE.IsSame( prevEdge ) || anE.IsSame( edges[ eIndex ])) {
333                 anOppE.Nullify(); break;
334               }
335             }
336             if ( nbSide == 2 ) { // opposite side
337               if ( !anOppE.IsNull() ) {
338                 // composite opposite side -> stop propagation
339                 anOppE.Nullify(); break;
340               }
341               anOppE = edges[ eIndex ];
342             }
343             if ( nbSide == 5 ) {
344               anOppE.Nullify(); break; // too many sides
345             }
346             prevEdge = edges[ eIndex ];
347           }
348           if ( anOppE.IsNull() )
349             continue;
350           if ( nbSide != 4 ) {
351             DBGMSG( nbSide << " sides in wire #" << mesh->GetMeshDS()->ShapeToIndex( itA.Value() ) << " - SKIP" );
352             continue;
353           }
354         }
355         if ( anOppE.IsNull() || !checkedShapes.Add( anOppE ))
356           continue;
357         SMESH_subMesh* oppSM = mesh->GetSubMesh( anOppE );
358         PropagationMgrData* oppData = getData( oppSM );
359
360         // Add anOppE to aChain if ...
361         if ( oppData->State() == WAIT_PROPAG_HYP ) // ... anOppE is not in any chain
362         {
363           oppData->SetSource( theMainSubMesh );
364           if ( ! (hyp1D = getLocal1DHyp( *mesh, anOppE, &shapeOfHyp1D )) || //...no 1d hyp on anOppE
365                ! (moreLocalCheck.IsOk( hyp1D, shapeOfHyp1D ))) // ... or hyp1D is "more global"
366           {
367             oppData->myForward = data->myForward;
368             if ( edges[ edgeIndex ].Orientation() == anOppE.Orientation() )
369               oppData->myForward = !oppData->myForward;
370             chain.push_back( oppSM );
371             oppSM->ComputeStateEngine( SMESH_subMesh::CLEAN );
372             oppData->SetState( IN_CHAIN );
373             DBGMSG( "set IN_CHAIN on " << oppSM->GetId() );
374             if ( oppSM->GetAlgoState() != SMESH_subMesh::HYP_OK )
375               // make oppSM check algo state
376               if ( SMESH_Algo* algo = mesh->GetGen()->GetAlgo( *mesh, anOppE ))
377                 oppSM->AlgoStateEngine(SMESH_subMesh::ADD_FATHER_ALGO,algo);
378           }
379           else {
380             oppData->SetState( LAST_IN_CHAIN );
381             DBGMSG( "set LAST_IN_CHAIN on " << oppSM->GetId() );
382           }
383         }
384         else if ( oppData->State() == LAST_IN_CHAIN ) // anOppE breaks other chain
385         {
386           DBGMSG( "encounters LAST_IN_CHAIN on " << oppSM->GetId() );
387           oppData->AddSource( theMainSubMesh );
388         }
389       } // loop on face ancestors
390     } // loop on the chain
391
392     // theMainSubMesh must not be in a chain
393     chain.pop_front();
394
395     return true;
396   }
397   //================================================================================
398   /*!
399    * \brief Clear propagation chain
400    */
401   bool clearPropagationChain( SMESH_subMesh* subMesh )
402   {
403     DBGMSG( "clearPropagationChain from " << subMesh->GetId() );
404     if ( PropagationMgrData* data = findData( subMesh ))
405     {
406       switch ( data->State() ) {
407       case IN_CHAIN:
408         return clearPropagationChain( data->GetSource() );
409
410       case HAS_PROPAG_HYP: {
411         SMESH_subMeshIteratorPtr smIt = data->GetChain();
412         while ( smIt->more() ) {
413           SMESH_subMesh* sm = smIt->next();
414           getData( sm )->Init();
415           sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
416         }
417         data->Init();
418         break;
419       }
420       case LAST_IN_CHAIN: {
421         SMESH_subMeshIteratorPtr smIt = iterate( data->mySubMeshes.begin(),
422                                                  data->mySubMeshes.end());
423         while ( smIt->more() )
424           clearPropagationChain( smIt->next() );
425         data->Init();
426         break;
427       }
428       default:;
429       }
430       return true;
431     }
432     return false;
433   }
434
435
436   //================================================================================
437   /*!
438    * \brief Return an iterator on chain submeshes
439    */
440   //================================================================================
441
442   SMESH_subMeshIteratorPtr PropagationMgrData::GetChain() const
443   {
444     switch ( State() ) {
445     case HAS_PROPAG_HYP:
446       return iterate( mySubMeshes.begin(), mySubMeshes.end() );
447     case IN_CHAIN:
448       if ( mySubMeshes.empty() ) break;
449       return getData( mySubMeshes.front() )->GetChain();
450     default:;
451     }
452     return iterate( mySubMeshes.end(), mySubMeshes.end() );
453   }
454   //================================================================================
455   /*!
456    * \brief Return a propagation source submesh
457    */
458   //================================================================================
459
460   SMESH_subMesh* PropagationMgrData::GetSource() const
461   {
462     if ( myType == IN_CHAIN )
463       if ( !mySubMeshes.empty() ) 
464         return mySubMeshes.front();
465     return 0;
466   }
467
468
469   //================================================================================
470   /*!
471    * \brief Constructor
472    */
473   //================================================================================
474
475   PropagationMgr::PropagationMgr()
476     : SMESH_subMeshEventListener( false, // won't be deleted by submesh
477                                   "StdMeshers_Propagation::PropagationMgr")
478   {}
479   //================================================================================
480   /*!
481    * \brief Set PropagationMgr on a submesh
482    */
483   //================================================================================
484
485   void PropagationMgr::Set(SMESH_subMesh * submesh)
486   {
487     if ( findData( submesh )) return;
488     DBGMSG( "PropagationMgr::Set() on  " << submesh->GetId() );
489     PropagationMgrData* data = new PropagationMgrData();
490     submesh->SetEventListener( getListener(), data, submesh );
491
492     const SMESH_Hypothesis * propagHyp =
493       getProagationHyp( *submesh->GetFather(), submesh->GetSubShape() );
494     if ( propagHyp )
495     {
496       data->myIsPropagOfDistribution =
497         ( StdMeshers_PropagOfDistribution::GetName() == propagHyp->GetName() );
498       getListener()->ProcessEvent( SMESH_subMesh::ADD_HYP,
499                                    SMESH_subMesh::ALGO_EVENT,
500                                    submesh,
501                                    data,
502                                    propagHyp);
503     }
504   }
505   //================================================================================
506   /*!
507    * \brief Return an edge from which hypotheses are propagated
508    */
509   //================================================================================
510
511   TopoDS_Edge PropagationMgr::GetSource(SMESH_subMesh * submesh,
512                                         bool&           isPropagOfDistribution)
513   {
514     if ( PropagationMgrData* data = findData( submesh )) {
515       if ( data->State() == IN_CHAIN ) {
516         if ( SMESH_subMesh* sm = data->GetSource() )
517         {
518           TopoDS_Shape edge = sm->GetSubShape();
519           edge = edge.Oriented( data->myForward ? TopAbs_FORWARD : TopAbs_REVERSED );
520           DBGMSG( " GetSource() = edge " << sm->GetId() << " REV = " << (!data->myForward));
521           isPropagOfDistribution = false;
522           if ( PropagationMgrData* data = findData( sm ))
523             isPropagOfDistribution = data->myIsPropagOfDistribution;
524           if ( edge.ShapeType() == TopAbs_EDGE )
525             return TopoDS::Edge( edge );
526         }
527       }
528     }
529     return TopoDS_Edge();
530   }
531   //================================================================================
532   /*!
533    * \brief React on events on 1D submeshes
534    */
535   //================================================================================
536
537   void PropagationMgr::ProcessEvent(const int                       event,
538                                     const int                       eventType,
539                                     SMESH_subMesh*                  subMesh,
540                                     SMESH_subMeshEventListenerData* listenerData,
541                                     const SMESH_Hypothesis*         hyp)
542   {
543     if ( !listenerData )
544       return;
545     if ( !hyp || hyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO || hyp->GetDim() != 1 )
546       return;
547     if ( eventType != SMESH_subMesh::ALGO_EVENT )
548       return;
549     DBGMSG( "PropagationMgr::ProcessEvent() on  " << subMesh->GetId() );
550
551     bool isPropagHyp = ( StdMeshers_Propagation::GetName()          == hyp->GetName() ||
552                          StdMeshers_PropagOfDistribution::GetName() == hyp->GetName() );
553
554     PropagationMgrData* data = static_cast<PropagationMgrData*>( listenerData );
555     switch ( data->State() ) {
556
557     case WAIT_PROPAG_HYP: { // propagation hyp or local 1D hyp is missing
558       // --------------------------------------------------------
559       bool hasPropagHyp = ( isPropagHyp ||
560                             getProagationHyp( *subMesh->GetFather(), subMesh->GetSubShape()) );
561       if ( !hasPropagHyp )
562         return;
563       bool hasLocal1DHyp =  getLocal1DHyp( *subMesh->GetFather(), subMesh->GetSubShape());
564       if ( !hasLocal1DHyp )
565         return;
566       if ( event == SMESH_subMesh::ADD_HYP ||
567            event == SMESH_subMesh::ADD_FATHER_HYP ) // add local or propagation hyp
568       {
569         DBGMSG( "ADD_HYP propagation to WAIT_PROPAG_HYP " << subMesh->GetId() );
570         // build propagation chain
571         buildPropagationChain( subMesh );
572       }
573       return;
574     }
575     case HAS_PROPAG_HYP: {  // propag hyp on this submesh
576       // --------------------------------------------------------
577       switch ( event ) {
578       case SMESH_subMesh::REMOVE_HYP:
579       case SMESH_subMesh::REMOVE_FATHER_HYP: // remove propagation hyp
580         if ( isPropagHyp && !getProagationHyp( *subMesh->GetFather(), subMesh->GetSubShape()) )
581         {
582           DBGMSG( "REMOVE_HYP propagation from HAS_PROPAG_HYP " << subMesh->GetId() );
583           // clear propagation chain
584           clearPropagationChain( subMesh );
585         }
586         // return; -- hyp is modified any way
587       default:
588         //case SMESH_subMesh::MODIF_HYP: // hyp modif
589         // clear mesh in a chain
590         DBGMSG( "MODIF_HYP on HAS_PROPAG_HYP " << subMesh->GetId() );
591         SMESH_subMeshIteratorPtr smIt = data->GetChain();
592         while ( smIt->more() ) {
593           SMESH_subMesh* smInChain = smIt->next();
594           smInChain->AlgoStateEngine( SMESH_subMesh::MODIF_HYP,
595                                       (SMESH_Hypothesis*) hyp );
596         }
597         return;
598       }
599       return;
600     }
601     case IN_CHAIN: {       // submesh is in propagation chain
602       // --------------------------------------------------------
603       if ( event == SMESH_subMesh::ADD_HYP ) { // add local hypothesis
604         if ( isPropagHyp ) { // propagation hyp added
605           DBGMSG( "ADD_HYP propagation on IN_CHAIN " << subMesh->GetId() );
606           // collision - do nothing
607         }
608         else { // 1D hyp added
609           // rebuild propagation chain
610           DBGMSG( "ADD_HYP 1D on IN_CHAIN " << subMesh->GetId() );
611           SMESH_subMesh* sourceSM = data->GetSource();
612           clearPropagationChain( sourceSM );
613           buildPropagationChain( sourceSM );
614         }
615       }
616       return;
617     }
618     case LAST_IN_CHAIN: { // submesh with local 1D hyp, breaking a chain
619       // --------------------------------------------------------
620       if ( event == SMESH_subMesh::REMOVE_HYP ) { // remove local hyp
621         // rebuild propagation chain
622         DBGMSG( "REMOVE_HYP 1D from LAST_IN_CHAIN " << subMesh->GetId() );
623         list<SMESH_subMesh*> sourceSM = data->mySubMeshes;
624         clearPropagationChain( subMesh );
625         SMESH_subMeshIteratorPtr smIt = iterate( sourceSM.begin(), sourceSM.end());
626         while ( smIt->more() )
627           buildPropagationChain( smIt->next() );
628       }
629       return;
630     }
631     } // switch by SubMeshState
632   }
633
634 } // namespace