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