Salome HOME
IPAL54700: TC-9.6.0: 0D Mesh - several items are missed in the OB popup menu
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.cxx
index 52f7e9e9cd067d516207c2aca19b839a7a43eb7a..8455f6b4681a3886ab21329db943221ea44f882f 100644 (file)
@@ -568,7 +568,7 @@ namespace
 
 //================================================================================
 /*!
- * \brief Import data from a GMF file and Return an error description
+ * \brief Import data from a GMF file and return an error description
  */
 //================================================================================
 
@@ -649,11 +649,12 @@ SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr       aSubShape,
   throw(SALOME::SALOME_Exception)
 {
   Unexpect aCatch(SALOME_SalomeException);
+
+  const int prevNbMeshEnt = NbNodes() + NbElements();
+
   if ( _preMeshInfo )
     _preMeshInfo->ForgetOrLoad();
 
-  const int prevNbMeshEnt = _impl->NbNodes() + _impl->GetMeshDS()->NbElements();
-
   std::string error;
   SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShape, anHyp, &error );
   anErrorText = error.c_str();
@@ -1212,6 +1213,9 @@ void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup
       if ( n->NbInverseElements() == 0 )
         _impl->GetMeshDS()->RemoveFreeNode( n, /*sm=*/0 );
 
+  _impl->GetMeshDS()->Modified();
+  _impl->SetIsModified( true );
+
   // Update Python script (theGroup must be alive for this)
   pyDump << SMESH::SMESH_Mesh_var(_this())
          << ".RemoveGroupWithContents( " << theGroup << " )";
@@ -2052,18 +2056,17 @@ void SMESH_Mesh_i::ReplaceShape(GEOM::GEOM_Object_ptr theNewGeom)
   bool geomChanged = true;
   GEOM::GEOM_Object_var oldGeom = GetShapeToMesh();
   if ( !theNewGeom->_is_nil() && !oldGeom->_is_nil() )
-    geomChanged = ( //oldGeom->_is_equivalent( theNewGeom ) ||
-                   oldGeom->GetTick() < theNewGeom->GetTick() );
+    geomChanged = ( oldGeom->GetTick() != theNewGeom->GetTick() );
 
   TopoDS_Shape S = _impl->GetShapeToMesh();
   GEOM_Client* geomClient = _gen_i->GetShapeReader();
   TCollection_AsciiString aIOR;
-  CORBA::String_var ior;
   if ( geomClient->Find( S, aIOR ))
     geomClient->RemoveShapeFromBuffer( aIOR );
 
   // clear buffer also for sub-groups
-  const std::set<SMESHDS_GroupBase*>& groups = _impl->GetMeshDS()->GetGroups();
+  SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
+  const std::set<SMESHDS_GroupBase*>& groups = meshDS->GetGroups();
   std::set<SMESHDS_GroupBase*>::const_iterator g = groups.begin();
   for (; g != groups.end(); ++g)
     if (const SMESHDS_GroupOnGeom* group = dynamic_cast<SMESHDS_GroupOnGeom*>(*g))
@@ -2073,12 +2076,21 @@ void SMESH_Mesh_i::ReplaceShape(GEOM::GEOM_Object_ptr theNewGeom)
         geomClient->RemoveShapeFromBuffer( aIOR );
     }
 
+  // clear buffer also for sub-meshes
+  std::map<int, SMESH_subMesh_i*>::const_iterator aSubMeshIter = _mapSubMesh_i.cbegin();
+  for(; aSubMeshIter != _mapSubMesh_i.cend(); aSubMeshIter++) {
+    int aShapeID = aSubMeshIter->first;
+    const TopoDS_Shape& aSubShape = meshDS->IndexToShape(aShapeID);
+    TCollection_AsciiString aShapeIOR;
+    if ( geomClient->Find( aSubShape, aShapeIOR ))
+      geomClient->RemoveShapeFromBuffer( aShapeIOR );
+  }
+
   typedef struct {
     int shapeID, fromID, toID; // indices of elements of a sub-mesh
   } TRange;
   std::vector< TRange > elemRanges, nodeRanges; // elements of sub-meshes
   std::vector< SMDS_PositionPtr > positions; // node positions
-  SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
   if ( !geomChanged )
   {
     // store positions of elements on geometry
@@ -3424,12 +3436,17 @@ namespace
   {
     SMESH_Mesh_i* _mesh;
     TCallUp_i(SMESH_Mesh_i* mesh):_mesh(mesh) {}
-    virtual void RemoveGroup (const int theGroupID) { _mesh->removeGroup( theGroupID ); }
-    virtual void HypothesisModified( int hypID,
-                                     bool updIcons) { _mesh->onHypothesisModified( hypID,
-                                                                                   updIcons ); }
-    virtual void Load ()                            { _mesh->Load(); }
-    virtual bool IsLoaded()                         { return _mesh->IsLoaded(); }
+    void RemoveGroup (const int theGroupID) override { _mesh->removeGroup( theGroupID ); }
+    void HypothesisModified( int hypID,
+                             bool updIcons) override { _mesh->onHypothesisModified( hypID,
+                                                                                    updIcons ); }
+    void Load ()                            override { _mesh->Load(); }
+    bool IsLoaded()                         override { return _mesh->IsLoaded(); }
+    TopoDS_Shape GetShapeByEntry(const std::string& entry) override
+    {
+      GEOM::GEOM_Object_var go = SMESH_Gen_i::GetGeomObjectByEntry( entry );
+      return SMESH_Gen_i::GeomObjectToShape( go );
+    }
   };
 }
 
@@ -3765,7 +3782,7 @@ void SMESH_Mesh_i::ExportMED(const char*        file,
   TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportMED( r'"
                 << file << "', "
                 << "auto_groups=" <<auto_groups << ", "
-                << "minor=" << version <<  ", "
+                << "version=" << version <<  ", "
                 << "overwrite=" << overwrite << ", "
                 << "meshPart=None, "
                 << "autoDimension=" << autoDimension << " )";
@@ -4972,7 +4989,7 @@ SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID)
 //=============================================================================
 /*!
  * Return ID of nodes for given sub-mesh
- * If param all==true - Return all nodes, else -
+ * If param all==true - return all nodes, else -
  * Return only nodes on shapes.
  */
 //=============================================================================
@@ -5079,7 +5096,7 @@ CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
 //=============================================================================
 /*!
  * Get XYZ coordinates of node as list of double
- * If there is not node for given ID - Return empty list
+ * If there is not node for given ID - return empty list
  */
 //=============================================================================
 
@@ -5109,8 +5126,8 @@ SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
 
 //=============================================================================
 /*!
- * For given node Return list of IDs of inverse elements
- * If there is not node for given ID - Return empty list
+ * For given node return list of IDs of inverse elements
+ * If there is not node for given ID - return empty list
  */
 //=============================================================================
 
@@ -5243,8 +5260,8 @@ SMESH::ElementPosition SMESH_Mesh_i::GetElementPosition(CORBA::Long ElemID)
 
 //=============================================================================
 /*!
- * If given element is node Return IDs of shape from position
- * If there is not node for given ID - Return -1
+ * If given element is node return IDs of shape from position
+ * If there is not node for given ID - return -1
  */
 //=============================================================================
 
@@ -5271,7 +5288,7 @@ CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
 /*!
  * For given element return ID of result shape after
  * ::FindShape() from SMESH_MeshEditor
- * If there is not element for given ID - Return -1
+ * If there is not element for given ID - return -1
  */
 //=============================================================================
 
@@ -5301,7 +5318,7 @@ CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
 //=============================================================================
 /*!
  * Return number of nodes for given element
- * If there is not element for given ID - Return -1
+ * If there is not element for given ID - return -1
  */
 //=============================================================================
 
@@ -5322,8 +5339,8 @@ CORBA::Long SMESH_Mesh_i::GetElemNbNodes(const CORBA::Long id)
 //=============================================================================
 /*!
  * Return ID of node by given index for given element
- * If there is not element for given ID - Return -1
- * If there is not node for given index - Return -2
+ * If there is not element for given ID - return -1
+ * If there is not node for given index - return -2
  */
 //=============================================================================
 
@@ -5821,15 +5838,21 @@ void SMESH_Mesh_i::CreateGroupServants()
     GEOM::GEOM_Object_var shapeVar = _gen_i->ShapeToGeomObject( shape );
     _gen_i->PublishGroup( aMesh, groupVar, shapeVar, group->GetName());
   }
+
   if ( !addedIDs.empty() )
   {
     // python dump
-    set<int>::iterator id = addedIDs.begin();
-    for ( ; id != addedIDs.end(); ++id )
+    map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_grp = _mapGroups.begin();
+    for ( int index = 0; i_grp != _mapGroups.end(); ++index, ++i_grp )
     {
-      map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.find(*id);
-      int i = std::distance( _mapGroups.begin(), it );
-      TPythonDump() << it->second << " = " << aMesh << ".GetGroups()[ "<< i << " ]";
+      set<int>::iterator it = addedIDs.find( i_grp->first );
+      if ( it != addedIDs.end() )
+      {
+        TPythonDump() << i_grp->second << " = " << aMesh << ".GetGroups()[ "<< index << " ]";
+        addedIDs.erase( it );
+        if ( addedIDs.empty() )
+          break;
+      }
     }
   }
 }
@@ -6045,7 +6068,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Mesh_i::GetMesh()
 
 //================================================================================
 /*!
- * \brief Return false if GetMeshInfo() Return incorrect information that may
+ * \brief Return false if GetMeshInfo() return incorrect information that may
  *        happen if mesh data is not yet fully loaded from the file of study.
  * 
  * 
@@ -6425,8 +6448,8 @@ class SMESH_DimHyp
   //! fields
   int _dim;    //!< a dimension the algo can build (concurrent dimension)
   int _ownDim; //!< dimension of shape of _subMesh (>=_dim)
-  TopTools_MapOfShape _shapeMap;
-  SMESH_subMesh*      _subMesh;
+  TopTools_MapOfShape  _shapeMap; //!< [sub-]shapes of dimension == _dim
+  const SMESH_subMesh* _subMesh;
   list<const SMESHDS_Hypothesis*> _hypotheses; //!< algo is first, then its parameters
 
   //-----------------------------------------------------------------------------
@@ -6440,7 +6463,7 @@ class SMESH_DimHyp
                const int            theDim,
                const TopoDS_Shape&  theShape)
   {
-    _subMesh = (SMESH_subMesh*)theSubMesh;
+    _subMesh = theSubMesh;
     SetShape( theDim, theShape );
   }
 
@@ -6522,9 +6545,11 @@ class SMESH_DimHyp
     bool isSame = checkAlgo( a1, a2 );
     if ( !isSame )
     {
-      if ( !a1 || !a2 )
-        return false; // pb?
-      return a1->GetDim() == a2->GetDim(); // different algorithms of same dim -> concurrency !
+      return true;
+      // commented off for IPAL54678
+      // if ( !a1 || !a2 )
+      //   return false; // pb?
+      // return a1->GetDim() == a2->GetDim(); // different algorithms of same dim -> concurrency !
     }
 
     // check hypothesises for concurrence (skip first as algorithm)
@@ -6565,8 +6590,12 @@ void addDimHypInstance(const int                               theDim,
                        const list <const SMESHDS_Hypothesis*>& theHypList,
                        TDimHypList*                            theDimHypListArr )
 {
+  if ( !theAlgo->NeedDiscreteBoundary() &&
+       theAlgo->NeedLowerHyps( theDim )) // IPAL54678
+    return;
   TDimHypList& listOfdimHyp = theDimHypListArr[theDim];
-  if ( listOfdimHyp.empty() || listOfdimHyp.back()->_subMesh != theSubMesh ) {
+  if ( listOfdimHyp.empty() || listOfdimHyp.back()->_subMesh != theSubMesh )
+  {
     SMESH_DimHyp* dimHyp = new SMESH_DimHyp( theSubMesh, theDim, theShape );
     dimHyp->_hypotheses.push_front(theAlgo);
     listOfdimHyp.push_back( dimHyp );
@@ -6622,7 +6651,8 @@ void unionLists(TListOfInt&       theListOfId,
                 const int         theIndx )
 {
   TListOfListOfInt::iterator it = theListOfListOfId.begin();
-  for ( int i = 0; it != theListOfListOfId.end(); it++, i++ ) {
+  for ( int i = 0; it != theListOfListOfId.end(); it++, i++ )
+  {
     if ( i < theIndx )
       continue; //skip already treated lists
     // check if other list has any same submesh object
@@ -6707,7 +6737,7 @@ CORBA::Boolean SMESH_Mesh_i::IsUnorderedSubMesh(CORBA::Long submeshID)
 
 //=============================================================================
 /*!
- * \brief Return submesh objects list in meshing order
+ * \brief Return sub-mesh objects list in meshing order
  */
 //=============================================================================
 
@@ -6745,81 +6775,86 @@ TListOfListOfInt SMESH_Mesh_i::findConcurrentSubMeshes()
 {
   TListOfListOfInt anOrder;
   ::SMESH_Mesh& mesh = GetImpl();
-  {
-    // collect submeshes and detect concurrent algorithms and hypothesises
-    TDimHypList dimHypListArr[4]; // dimHyp list for each shape dimension
-
-    map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
-    for ( ; i_sm != _mapSubMesh.end(); i_sm++ ) {
-      ::SMESH_subMesh* sm = (*i_sm).second;
-      // shape of submesh
-      const TopoDS_Shape& aSubMeshShape = sm->GetSubShape();
-
-      // list of assigned hypothesises
-      const list <const SMESHDS_Hypothesis*>& hypList = mesh.GetHypothesisList(aSubMeshShape);
-      // Find out dimensions where the submesh can be concurrent.
-      // We define the dimensions by algo of each of hypotheses in hypList
-      list <const SMESHDS_Hypothesis*>::const_iterator hypIt = hypList.begin();
-      for( ; hypIt != hypList.end(); hypIt++ ) {
-        SMESH_Algo* anAlgo = 0;
-        const SMESH_Hypothesis* hyp = dynamic_cast<const SMESH_Hypothesis*>(*hypIt);
-        if ( hyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO )
-          // hyp it-self is algo
-          anAlgo = (SMESH_Algo*)dynamic_cast<const SMESH_Algo*>(hyp);
-        else {
-          // try to find algorithm with help of sub-shapes
-          TopExp_Explorer anExp( aSubMeshShape, shapeTypeByDim(hyp->GetDim()) );
-          for ( ; !anAlgo && anExp.More(); anExp.Next() )
-            anAlgo = mesh.GetGen()->GetAlgo( mesh, anExp.Current() );
-        }
-        if (!anAlgo)
-          continue; // no algorithm assigned to a current submesh
 
-        int dim = anAlgo->GetDim(); // top concurrent dimension (see comment to SMESH_DimHyp)
-        // the submesh can concurrent at <dim> (or lower dims if !anAlgo->NeedDiscreteBoundary())
+  // collect submeshes and detect concurrent algorithms and hypothesises
+  TDimHypList dimHypListArr[4]; // dimHyp list for each shape dimension
 
-        // create instance of dimension-hypothesis for found concurrent dimension(s) and algorithm
-        for ( int j = anAlgo->NeedDiscreteBoundary() ? dim : 1, jn = dim; j <= jn; j++ )
-          addDimHypInstance( j, aSubMeshShape, anAlgo, sm, hypList, dimHypListArr );
+  map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
+  for ( ; i_sm != _mapSubMesh.end(); i_sm++ )
+  {
+    ::SMESH_subMesh* sm = (*i_sm).second;
+    // shape of submesh
+    const TopoDS_Shape& aSubMeshShape = sm->GetSubShape();
+
+    // list of assigned hypothesises
+    const list <const SMESHDS_Hypothesis*>& hypList = mesh.GetHypothesisList(aSubMeshShape);
+    // Find out dimensions where the submesh can be concurrent.
+    // We define the dimensions by algo of each of hypotheses in hypList
+    list <const SMESHDS_Hypothesis*>::const_iterator hypIt = hypList.begin();
+    for( ; hypIt != hypList.end(); hypIt++ )
+    {
+      SMESH_Algo* anAlgo = 0;
+      const SMESH_Hypothesis* hyp = dynamic_cast<const SMESH_Hypothesis*>(*hypIt);
+      if ( hyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO )
+        // hyp it-self is algo
+        anAlgo = (SMESH_Algo*)dynamic_cast<const SMESH_Algo*>(hyp);
+      else {
+        // try to find algorithm with help of sub-shapes
+        TopExp_Explorer anExp( aSubMeshShape, shapeTypeByDim(hyp->GetDim()) );
+        for ( ; !anAlgo && anExp.More(); anExp.Next() )
+          anAlgo = mesh.GetGen()->GetAlgo( mesh, anExp.Current() );
       }
-    } // end iterations on submesh
+      if (!anAlgo)
+        continue; // no algorithm assigned to a current submesh
+
+      int dim = anAlgo->GetDim(); // top concurrent dimension (see comment to SMESH_DimHyp)
+      // the submesh can concurrent at <dim> (or lower dims if !anAlgo->NeedDiscreteBoundary()
+      // and !anAlgo->NeedLowerHyps( dim ))
+
+      // create instance of dimension-hypothesis for found concurrent dimension(s) and algorithm
+      for ( int j = anAlgo->NeedDiscreteBoundary() ? dim : 1, jn = dim; j <= jn; j++ )
+        addDimHypInstance( j, aSubMeshShape, anAlgo, sm, hypList, dimHypListArr );
+    }
+  } // end iterations on submesh
 
     // iterate on created dimension-hypotheses and check for concurrents
-    for ( int i = 0; i < 4; i++ ) {
-      const TDimHypList& listOfDimHyp = dimHypListArr[i];
-      // check for concurrents in own and other dimensions (step-by-step)
-      TDimHypList::const_iterator dhIt = listOfDimHyp.begin();
-      for ( ; dhIt != listOfDimHyp.end(); dhIt++ ) {
-        const SMESH_DimHyp* dimHyp = *dhIt;
-        TDimHypList listOfConcurr;
-        set<int>    setOfConcurrIds;
-        // looking for concurrents and collect into own list
-        for ( int j = i; j < 4; j++ )
-          findConcurrents( dimHyp, dimHypListArr[j], listOfConcurr, setOfConcurrIds );
-        // check if any concurrents found
-        if ( listOfConcurr.size() > 0 ) {
-          // add own submesh to list of concurrent
-          addInOrderOfPriority( dimHyp, listOfConcurr );
-          list<int> listOfConcurrIds;
-          TDimHypList::iterator hypIt = listOfConcurr.begin();
-          for ( ; hypIt != listOfConcurr.end(); ++hypIt )
-            listOfConcurrIds.push_back( (*hypIt)->_subMesh->GetId() );
-          anOrder.push_back( listOfConcurrIds );
-        }
+  for ( int i = 0; i < 4; i++ )
+  {
+    const TDimHypList& listOfDimHyp = dimHypListArr[i];
+    // check for concurrents in own and other dimensions (step-by-step)
+    TDimHypList::const_iterator dhIt = listOfDimHyp.begin();
+    for ( ; dhIt != listOfDimHyp.end(); dhIt++ )
+    {
+      const SMESH_DimHyp* dimHyp = *dhIt;
+      TDimHypList listOfConcurr;
+      set<int>    setOfConcurrIds;
+      // looking for concurrents and collect into own list
+      for ( int j = i; j < 4; j++ )
+        findConcurrents( dimHyp, dimHypListArr[j], listOfConcurr, setOfConcurrIds );
+      // check if any concurrents found
+      if ( listOfConcurr.size() > 0 )
+      {
+        // add own submesh to list of concurrent
+        addInOrderOfPriority( dimHyp, listOfConcurr );
+        list<int> listOfConcurrIds;
+        TDimHypList::iterator hypIt = listOfConcurr.begin();
+        for ( ; hypIt != listOfConcurr.end(); ++hypIt )
+          listOfConcurrIds.push_back( (*hypIt)->_subMesh->GetId() );
+        anOrder.push_back( listOfConcurrIds );
       }
     }
+  }
 
-    removeDimHyps(dimHypListArr);
+  removeDimHyps(dimHypListArr);
 
-    // now, minimize the number of concurrent groups
-    // Here we assume that lists of submeshes can have same submesh
-    // in case of multi-dimension algorithms, as result
-    //  list with common submesh has to be united into one list
-    int listIndx = 0;
-    TListOfListOfInt::iterator listIt = anOrder.begin();
-    for(; listIt != anOrder.end(); listIt++, listIndx++ )
-      unionLists( *listIt,  anOrder, listIndx + 1 );
-  }
+  // now, minimize the number of concurrent groups
+  // Here we assume that lists of submeshes can have same submesh
+  // in case of multi-dimension algorithms, as result
+  //  list with common submesh has to be united into one list
+  int listIndx = 0;
+  TListOfListOfInt::iterator listIt = anOrder.begin();
+  for(; listIt != anOrder.end(); listIt++, listIndx++ )
+    unionLists( *listIt,  anOrder, listIndx + 1 );
 
   return anOrder;
 }
@@ -6907,7 +6942,8 @@ void SMESH_Mesh_i::convertMeshOrder (const TListOfListOfInt&     theIdsOrder,
   theResOrder.length(nbSet);
   TListOfListOfInt::const_iterator it = theIdsOrder.begin();
   int listIndx = 0;
-  for( ; it != theIdsOrder.end(); it++ ) {
+  for( ; it != theIdsOrder.end(); it++ )
+  {
     // translate submesh identificators into submesh objects
     //  takeing into account real number of concurrent lists
     const TListOfInt& aSubOrder = (*it);
@@ -6920,7 +6956,8 @@ void SMESH_Mesh_i::convertMeshOrder (const TListOfListOfInt&     theIdsOrder,
     aResSubSet->length(aSubOrder.size());
     TListOfInt::const_iterator subIt = aSubOrder.begin();
     int j;
-    for( j = 0; subIt != aSubOrder.end(); subIt++ ) {
+    for( j = 0; subIt != aSubOrder.end(); subIt++ )
+    {
       if ( _mapSubMeshIor.find(*subIt) == _mapSubMeshIor.end() )
         continue;
       SMESH::SMESH_subMesh_var subMesh =