Back to index

salome-smesh  6.5.0
SMESH_Mesh.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SMESH SMESH : implementaion of SMESH idl descriptions
00024 //  File   : SMESH_Mesh.hxx
00025 //  Author : Paul RASCLE, EDF
00026 //  Module : SMESH
00027 //
00028 #ifndef _SMESH_MESH_HXX_
00029 #define _SMESH_MESH_HXX_
00030 
00031 #include "SMESH_SMESH.hxx"
00032 
00033 #include "SMESH_Hypothesis.hxx"
00034 #include "SMESH_Controls.hxx"
00035 
00036 #include "SMESHDS_Mesh.hxx"
00037 #include "SMESHDS_Command.hxx"
00038 #include "SMDSAbs_ElementType.hxx"
00039 
00040 #include "Utils_SALOME_Exception.hxx"
00041 
00042 #include <TopoDS_Shape.hxx>
00043 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
00044 
00045 #include <map>
00046 #include <list>
00047 
00048 #ifdef WNT
00049 #pragma warning(disable:4251) // Warning DLL Interface ...
00050 #pragma warning(disable:4290) // Warning Exception ...
00051 #endif
00052 
00053 class SMESH_Gen;
00054 class SMESHDS_Document;
00055 class SMESH_Group;
00056 class TopTools_ListOfShape;
00057 class SMESH_subMesh;
00058 class SMESH_HypoFilter;
00059 class TopoDS_Solid;
00060 
00061 typedef std::list<int> TListOfInt;
00062 typedef std::list<TListOfInt> TListOfListOfInt;
00063 
00064 class SMESH_EXPORT SMESH_Mesh
00065 {
00066 public:
00067   SMESH_Mesh(int               theLocalId, 
00068              int               theStudyId, 
00069              SMESH_Gen*        theGen,
00070              bool              theIsEmbeddedMode,
00071              SMESHDS_Document* theDocument);
00072   
00073   virtual ~SMESH_Mesh();
00074   
00078   void ShapeToMesh(const TopoDS_Shape & aShape);
00082   TopoDS_Shape GetShapeToMesh() const;
00086   bool HasShapeToMesh() const { return _isShapeToMesh; }
00090   double GetShapeDiagonalSize() const;
00094   static double GetShapeDiagonalSize(const TopoDS_Shape & aShape);
00099   static const TopoDS_Solid& PseudoShape();
00100 
00104   void Load();
00108   void Clear();
00112   void ClearSubMesh(const int theShapeId);
00113 
00117   int UNVToMesh(const char* theFileName);
00118 
00119   int MEDToMesh(const char* theFileName, const char* theMeshName);
00120   
00121   int STLToMesh(const char* theFileName);
00122 
00123   int CGNSToMesh(const char* theFileName, const int theMeshIndex, std::string& theMeshName);
00124   
00125   SMESH_Hypothesis::Hypothesis_Status
00126   AddHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
00127     throw(SALOME_Exception);
00128   
00129   SMESH_Hypothesis::Hypothesis_Status
00130   RemoveHypothesis(const TopoDS_Shape & aSubShape, int anHypId)
00131     throw(SALOME_Exception);
00132   
00133   const std::list <const SMESHDS_Hypothesis * >&
00134   GetHypothesisList(const TopoDS_Shape & aSubShape) const
00135     throw(SALOME_Exception);
00136 
00137   const SMESH_Hypothesis * GetHypothesis(const TopoDS_Shape &    aSubShape,
00138                                          const SMESH_HypoFilter& aFilter,
00139                                          const bool              andAncestors,
00140                                          TopoDS_Shape*           assignedTo=0) const;
00141   
00142   int GetHypotheses(const TopoDS_Shape &                     aSubShape,
00143                     const SMESH_HypoFilter&                  aFilter,
00144                     std::list <const SMESHDS_Hypothesis * >& aHypList,
00145                     const bool                               andAncestors) const;
00146 
00147   const std::list<SMESHDS_Command*> & GetLog() throw(SALOME_Exception);
00148   
00149   void ClearLog() throw(SALOME_Exception);
00150   
00151   int GetId() const          { return _id; }
00152   
00153   bool MeshExists( int meshId ) const;
00154   
00155   SMESHDS_Mesh * GetMeshDS() { return _myMeshDS; }
00156   
00157   const SMESHDS_Mesh * GetMeshDS() const { return _myMeshDS; }
00158   
00159   SMESH_Gen *GetGen()        { return _gen; }
00160 
00161   SMESH_subMesh *GetSubMesh(const TopoDS_Shape & aSubShape)
00162     throw(SALOME_Exception);
00163   
00164   SMESH_subMesh *GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
00165     throw(SALOME_Exception);
00166   
00167   SMESH_subMesh *GetSubMeshContaining(const int aShapeID) const
00168     throw(SALOME_Exception);
00172   std::list<SMESH_subMesh*> GetGroupSubMeshesContaining(const TopoDS_Shape & shape) const
00173     throw(SALOME_Exception);
00177   void NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* theChangedHyp);
00178 
00179   const std::list < SMESH_subMesh * >&
00180   GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp) throw(SALOME_Exception);
00184   bool IsUsedHypothesis(SMESHDS_Hypothesis *  anHyp,
00185                         const SMESH_subMesh * aSubMesh);
00189   bool IsNotConformAllowed() const;
00190   
00191   bool IsMainShape(const TopoDS_Shape& theShape) const;
00196   const TopTools_ListOfShape& GetAncestors(const TopoDS_Shape& theSubShape) const;
00197 
00198   void SetAutoColor(bool theAutoColor) throw(SALOME_Exception);
00199 
00200   bool GetAutoColor() throw(SALOME_Exception);
00201 
00206   void SetIsModified(bool isModified);
00207 
00208   bool GetIsModified() const { return _isModified; }
00209 
00215   bool HasModificationsToDiscard() const;
00216 
00220   typedef TopTools_IndexedDataMapOfShapeListOfShape TAncestorMap;
00221   const TAncestorMap& GetAncestorMap() const { return _mapAncestors; }
00226   bool HasDuplicatedGroupNamesMED();
00227 
00228   void ExportMED(const char *file, 
00229                  const char* theMeshName = NULL, 
00230                  bool theAutoGroups = true, 
00231                  int theVersion = 0,
00232                  const SMESHDS_Mesh* meshPart = 0) 
00233     throw(SALOME_Exception);
00234 
00235   void ExportDAT(const char *        file,
00236                  const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception);
00237   void ExportUNV(const char *        file,
00238                  const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception);
00239   void ExportSTL(const char *        file,
00240                  const bool          isascii,
00241                  const SMESHDS_Mesh* meshPart = 0) throw(SALOME_Exception);
00242   void ExportCGNS(const char *        file,
00243                   const SMESHDS_Mesh* mesh);
00244   void ExportSAUV(const char *file, 
00245                   const char* theMeshName = NULL, 
00246                   bool theAutoGroups = true) throw(SALOME_Exception);
00247   
00248   int NbNodes() const throw(SALOME_Exception);
00249   
00250   int Nb0DElements() const throw(SALOME_Exception);
00251   
00252   int NbEdges(SMDSAbs_ElementOrder order = ORDER_ANY) const throw(SALOME_Exception);
00253   
00254   int NbFaces(SMDSAbs_ElementOrder order = ORDER_ANY) const throw(SALOME_Exception);
00255   
00256   int NbTriangles(SMDSAbs_ElementOrder order = ORDER_ANY) const throw(SALOME_Exception);
00257   
00258   int NbQuadrangles(SMDSAbs_ElementOrder order = ORDER_ANY) const throw(SALOME_Exception);
00259 
00260   int NbBiQuadQuadrangles() const throw(SALOME_Exception);
00261   
00262   int NbPolygons() const throw(SALOME_Exception);
00263   
00264   int NbVolumes(SMDSAbs_ElementOrder order = ORDER_ANY) const throw(SALOME_Exception);
00265   
00266   int NbTetras(SMDSAbs_ElementOrder order = ORDER_ANY) const throw(SALOME_Exception);
00267   
00268   int NbHexas(SMDSAbs_ElementOrder order = ORDER_ANY) const throw(SALOME_Exception);
00269   
00270   int NbTriQuadraticHexas() const throw(SALOME_Exception);
00271   
00272   int NbPyramids(SMDSAbs_ElementOrder order = ORDER_ANY) const throw(SALOME_Exception);
00273 
00274   int NbPrisms(SMDSAbs_ElementOrder order = ORDER_ANY) const throw(SALOME_Exception);
00275   
00276   int NbHexagonalPrisms() const throw(SALOME_Exception);
00277   
00278   int NbPolyhedrons() const throw(SALOME_Exception);
00279   
00280   int NbSubMesh() const throw(SALOME_Exception);
00281   
00282   int NbGroup() const { return _mapGroup.size(); }
00283 
00284   SMESH_Group* AddGroup (const SMDSAbs_ElementType theType,
00285                          const char*               theName,
00286                          int&                      theId,
00287                          const TopoDS_Shape&       theShape=TopoDS_Shape(),
00288                          const SMESH_PredicatePtr& thePredicate=SMESH_PredicatePtr());
00289   
00290   typedef boost::shared_ptr< SMDS_Iterator<SMESH_Group*> > GroupIteratorPtr;
00291   GroupIteratorPtr GetGroups() const;
00292   
00293   std::list<int> GetGroupIds() const;
00294   
00295   SMESH_Group* GetGroup (const int theGroupID);
00296 
00297   bool RemoveGroup (const int theGroupID);
00298 
00299   SMESH_Group* ConvertToStandalone ( int theGroupID );
00300 
00301   struct TCallUp // callback from SMESH to SMESH_I level
00302   {
00303     virtual void RemoveGroup (const int theGroupID)=0;
00304     virtual void HypothesisModified ()=0;
00305     virtual void Load ()=0;
00306     virtual ~TCallUp() {}
00307   };
00308   void SetCallUp( TCallUp * upCaller );
00309 
00310   bool SynchronizeGroups();
00311 
00312 
00313   SMDSAbs_ElementType GetElementType( const int id, const bool iselem );
00314 
00315   void ClearMeshOrder();
00316   void SetMeshOrder(const TListOfListOfInt& theOrder );
00317   const TListOfListOfInt& GetMeshOrder() const;
00318 
00324   bool SortByMeshOrder(std::list<SMESH_subMesh*>& theListToSort) const;
00325 
00326   //
00327   
00328   ostream& Dump(ostream & save);
00329   
00330 private:
00331 
00332   void fillAncestorsMap(const TopoDS_Shape& theShape);
00333   std::list<SMESH_subMesh*> getAncestorsSubMeshes
00334     (const TopoDS_Shape& theSubShape) const;
00335   
00336 protected:
00337   int                        _id;           // id given by creator (unique within the creator instance)
00338   int                        _studyId;
00339   int                        _idDoc;        // id given by SMESHDS_Document
00340   int                        _groupId;      // id generator for group objects
00341   int                        _nbSubShapes;  // initial nb of subshapes in the shape to mesh
00342   bool                       _isShapeToMesh;// set to true when a shape is given (only once)
00343   std::list <SMESH_subMesh*> _subMeshesUsingHypothesisList;
00344   SMESHDS_Document *         _myDocument;
00345   SMESHDS_Mesh *             _myMeshDS;
00346   SMESH_Gen *                _gen;
00347   std::map <int, SMESH_subMesh*> _mapSubMesh;
00348   std::map <int, SMESH_Group*>   _mapGroup;
00349   
00350   bool                       _isAutoColor;
00351   bool                       _isModified; 
00352 
00353   double                     _shapeDiagonal; 
00354   
00355   TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors;
00356 
00357   TListOfListOfInt           _mySubMeshOrder;
00358 
00359   // Struct calling methods at CORBA API implementation level, used to
00360   // 1) make an upper level be consistent with a lower one when group removal
00361   // is invoked by hyp modification (issue 0020918)
00362   // 2) to forget not loaded mesh data at hyp modification
00363   TCallUp*                    _callUp;
00364 
00365 protected:
00366   SMESH_Mesh();
00367   SMESH_Mesh(const SMESH_Mesh&) {};
00368 };
00369 
00370 #endif