From cd6f3c42cf2646211a847746149c3929251f2132 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 11 Oct 2005 13:41:58 +0000 Subject: [PATCH] This commit was generated by cvs2git to create branch 'BR-D5-38-2003'. Cherrypick from master 2005-10-11 13:41:57 UTC eap 'PAL10196. use renamed GetGroupNames()->GetGroupNamesAndTypes() of MED Driver': src/Controls/SMESH_ControlsDef.hxx src/DriverMED/DriverMED_Family.h src/DriverMED/DriverMED_R_SMESHDS_Mesh.h src/OBJECT/SMESH_Actor.cxx src/OBJECT/SMESH_Actor.h src/SMDS/SMDS_VolumeTool.hxx src/SMESH/SMESH_Mesh.cxx src/SMESH/SMESH_Mesh.hxx src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx src/SMESHGUI/SMESHGUI_FilterUtils.cxx src/SMESHGUI/SMESHGUI_FilterUtils.h src/SMESH_I/SMESH_MEDFamily_i.hxx src/SMESH_I/SMESH_MEDSupport_i.hxx --- src/Controls/SMESH_ControlsDef.hxx | 660 ++++++++ src/DriverMED/DriverMED_Family.h | 120 ++ src/DriverMED/DriverMED_R_SMESHDS_Mesh.h | 69 + src/OBJECT/SMESH_Actor.cxx | 1627 ++++++++++++++++++++ src/OBJECT/SMESH_Actor.h | 121 ++ src/SMDS/SMDS_VolumeTool.hxx | 265 ++++ src/SMESH/SMESH_Mesh.cxx | 1430 +++++++++++++++++ src/SMESH/SMESH_Mesh.hxx | 256 +++ src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx | 1133 ++++++++++++++ src/SMESHGUI/SMESHGUI_FilterUtils.cxx | 37 + src/SMESHGUI/SMESHGUI_FilterUtils.h | 34 + src/SMESH_I/SMESH_MEDFamily_i.hxx | 90 ++ src/SMESH_I/SMESH_MEDSupport_i.hxx | 111 ++ 13 files changed, 5953 insertions(+) create mode 100644 src/Controls/SMESH_ControlsDef.hxx create mode 100644 src/DriverMED/DriverMED_Family.h create mode 100644 src/DriverMED/DriverMED_R_SMESHDS_Mesh.h create mode 100644 src/OBJECT/SMESH_Actor.cxx create mode 100644 src/OBJECT/SMESH_Actor.h create mode 100644 src/SMDS/SMDS_VolumeTool.hxx create mode 100644 src/SMESH/SMESH_Mesh.cxx create mode 100644 src/SMESH/SMESH_Mesh.hxx create mode 100644 src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx create mode 100644 src/SMESHGUI/SMESHGUI_FilterUtils.cxx create mode 100644 src/SMESHGUI/SMESHGUI_FilterUtils.h create mode 100644 src/SMESH_I/SMESH_MEDFamily_i.hxx create mode 100644 src/SMESH_I/SMESH_MEDSupport_i.hxx diff --git a/src/Controls/SMESH_ControlsDef.hxx b/src/Controls/SMESH_ControlsDef.hxx new file mode 100644 index 000000000..576b1e8e0 --- /dev/null +++ b/src/Controls/SMESH_ControlsDef.hxx @@ -0,0 +1,660 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org + +#ifndef _SMESH_CONTROLSDEF_HXX_ +#define _SMESH_CONTROLSDEF_HXX_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SMDSAbs_ElementType.hxx" +#include "SMDS_MeshNode.hxx" + +#include "SMESH_Controls.hxx" + +class SMDS_MeshElement; +class SMDS_MeshFace; +class SMDS_MeshNode; +class SMDS_Mesh; + +class SMESHDS_Mesh; +class SMESHDS_SubMesh; + +class gp_Pnt; +class TopoDS_Shape; + + +namespace SMESH{ + namespace Controls{ + + class TSequenceOfXYZ: public std::vector + { + public: + typedef std::vector TSuperClass; + TSequenceOfXYZ() + {} + + TSequenceOfXYZ(size_type n): + TSuperClass(n) + {} + + TSequenceOfXYZ(size_type n, const value_type& t): + TSuperClass(n,t) + {} + + TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ): + TSuperClass(theSequenceOfXYZ) + {} + + template + TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd): + TSuperClass(theBegin,theEnd) + {} + + TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){ + TSuperClass::operator=(theSequenceOfXYZ); + return *this; + } + + reference operator()(size_type n){ + return TSuperClass::operator[](n-1); + } + + const_reference operator()(size_type n) const{ + return TSuperClass::operator[](n-1); + } + + private: + reference operator[](size_type n); + + const_reference operator[](size_type n) const; + }; + + /* + Class : Functor + Description : Root of all Functors + */ + class Functor + { + public: + ~Functor(){} + virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0; + virtual SMDSAbs_ElementType GetType() const = 0; + }; + + /* + Class : NumericalFunctor + Description : Root of all Functors returning numeric value + */ + class NumericalFunctor: public virtual Functor{ + public: + NumericalFunctor(); + virtual void SetMesh( const SMDS_Mesh* theMesh ); + virtual double GetValue( long theElementId ); + virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;}; + virtual SMDSAbs_ElementType GetType() const = 0; + virtual double GetBadRate( double Value, int nbNodes ) const = 0; + long GetPrecision() const; + void SetPrecision( const long thePrecision ); + + bool GetPoints(const int theId, + TSequenceOfXYZ& theRes) const; + static bool GetPoints(const SMDS_MeshElement* theElem, + TSequenceOfXYZ& theRes); + protected: + const SMDS_Mesh* myMesh; + long myPrecision; + }; + + + /* + Class : Volume + Description : Functor calculating volume of 3D mesh element + */ + class Volume: public virtual NumericalFunctor{ + public: + virtual double GetValue( long theElementId ); + //virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : SMESH_MinimumAngle + Description : Functor for calculation of minimum angle + */ + class MinimumAngle: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : AspectRatio + Description : Functor for calculating aspect ratio + */ + class AspectRatio: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : AspectRatio3D + Description : Functor for calculating aspect ratio of 3D elems. + */ + class AspectRatio3D: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : Warping + Description : Functor for calculating warping + */ + class Warping: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + + private: + double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const; + }; + + + /* + Class : Taper + Description : Functor for calculating taper + */ + class Taper: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : Skew + Description : Functor for calculating skew in degrees + */ + class Skew: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : Area + Description : Functor for calculating area + */ + class Area: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + + /* + Class : Length + Description : Functor for calculating length of edge + */ + class Length: public virtual NumericalFunctor{ + public: + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + /* + Class : Length2D + Description : Functor for calculating length of edge + */ + class Length2D: public virtual NumericalFunctor{ + public: + virtual double GetValue( long theElementId ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + struct Value{ + double myLength; + long myPntId[2]; + Value(double theLength, long thePntId1, long thePntId2); + bool operator<(const Value& x) const; + }; + typedef std::set TValues; + void GetValues(TValues& theValues); + + }; + typedef boost::shared_ptr Length2DPtr; + + /* + Class : MultiConnection + Description : Functor for calculating number of faces conneted to the edge + */ + class MultiConnection: public virtual NumericalFunctor{ + public: + virtual double GetValue( long theElementId ); + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + }; + + /* + Class : MultiConnection2D + Description : Functor for calculating number of faces conneted to the edge + */ + class MultiConnection2D: public virtual NumericalFunctor{ + public: + virtual double GetValue( long theElementId ); + virtual double GetValue( const TSequenceOfXYZ& thePoints ); + virtual double GetBadRate( double Value, int nbNodes ) const; + virtual SMDSAbs_ElementType GetType() const; + struct Value{ + long myPntId[2]; + Value(long thePntId1, long thePntId2); + bool operator<(const Value& x) const; + }; + typedef std::map MValues; + + void GetValues(MValues& theValues); + }; + typedef boost::shared_ptr MultiConnection2DPtr; + /* + PREDICATES + */ + /* + Class : Predicate + Description : Base class for all predicates + */ + class Predicate: public virtual Functor{ + public: + virtual bool IsSatisfy( long theElementId ) = 0; + virtual SMDSAbs_ElementType GetType() const = 0; + }; + + + + /* + Class : FreeBorders + Description : Predicate for free borders + */ + class FreeBorders: public virtual Predicate{ + public: + FreeBorders(); + virtual void SetMesh( const SMDS_Mesh* theMesh ); + virtual bool IsSatisfy( long theElementId ); + virtual SMDSAbs_ElementType GetType() const; + + protected: + const SMDS_Mesh* myMesh; + }; + + + /* + Class : BadOrientedVolume + Description : Predicate bad oriented volumes + */ + class BadOrientedVolume: public virtual Predicate{ + public: + BadOrientedVolume(); + virtual void SetMesh( const SMDS_Mesh* theMesh ); + virtual bool IsSatisfy( long theElementId ); + virtual SMDSAbs_ElementType GetType() const; + + protected: + const SMDS_Mesh* myMesh; + }; + + + /* + Class : FreeEdges + Description : Predicate for free Edges + */ + class FreeEdges: public virtual Predicate{ + public: + FreeEdges(); + virtual void SetMesh( const SMDS_Mesh* theMesh ); + virtual bool IsSatisfy( long theElementId ); + virtual SMDSAbs_ElementType GetType() const; + static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId ); + typedef long TElemId; + struct Border{ + TElemId myElemId; + TElemId myPntId[2]; + Border(long theElemId, long thePntId1, long thePntId2); + bool operator<(const Border& x) const; + }; + typedef std::set TBorders; + void GetBoreders(TBorders& theBorders); + + protected: + const SMDS_Mesh* myMesh; + }; + typedef boost::shared_ptr FreeEdgesPtr; + + + /* + Class : RangeOfIds + Description : Predicate for Range of Ids. + Range may be specified with two ways. + 1. Using AddToRange method + 2. With SetRangeStr method. Parameter of this method is a string + like as "1,2,3,50-60,63,67,70-" + */ + class RangeOfIds: public virtual Predicate + { + public: + RangeOfIds(); + virtual void SetMesh( const SMDS_Mesh* theMesh ); + virtual bool IsSatisfy( long theNodeId ); + virtual SMDSAbs_ElementType GetType() const; + virtual void SetType( SMDSAbs_ElementType theType ); + + bool AddToRange( long theEntityId ); + void GetRangeStr( TCollection_AsciiString& ); + bool SetRangeStr( const TCollection_AsciiString& ); + + protected: + const SMDS_Mesh* myMesh; + + TColStd_SequenceOfInteger myMin; + TColStd_SequenceOfInteger myMax; + TColStd_MapOfInteger myIds; + + SMDSAbs_ElementType myType; + }; + + typedef boost::shared_ptr RangeOfIdsPtr; + + + /* + Class : Comparator + Description : Base class for comparators + */ + class Comparator: public virtual Predicate{ + public: + Comparator(); + virtual ~Comparator(); + virtual void SetMesh( const SMDS_Mesh* theMesh ); + virtual void SetMargin(double theValue); + virtual void SetNumFunctor(NumericalFunctorPtr theFunct); + virtual bool IsSatisfy( long theElementId ) = 0; + virtual SMDSAbs_ElementType GetType() const; + double GetMargin(); + + protected: + double myMargin; + NumericalFunctorPtr myFunctor; + }; + typedef boost::shared_ptr ComparatorPtr; + + + /* + Class : LessThan + Description : Comparator "<" + */ + class LessThan: public virtual Comparator{ + public: + virtual bool IsSatisfy( long theElementId ); + }; + + + /* + Class : MoreThan + Description : Comparator ">" + */ + class MoreThan: public virtual Comparator{ + public: + virtual bool IsSatisfy( long theElementId ); + }; + + + /* + Class : EqualTo + Description : Comparator "=" + */ + class EqualTo: public virtual Comparator{ + public: + EqualTo(); + virtual bool IsSatisfy( long theElementId ); + virtual void SetTolerance( double theTol ); + virtual double GetTolerance(); + + private: + double myToler; + }; + typedef boost::shared_ptr EqualToPtr; + + + /* + Class : LogicalNOT + Description : Logical NOT predicate + */ + class LogicalNOT: public virtual Predicate{ + public: + LogicalNOT(); + virtual ~LogicalNOT(); + virtual bool IsSatisfy( long theElementId ); + virtual void SetMesh( const SMDS_Mesh* theMesh ); + virtual void SetPredicate(PredicatePtr thePred); + virtual SMDSAbs_ElementType GetType() const; + + private: + PredicatePtr myPredicate; + }; + typedef boost::shared_ptr LogicalNOTPtr; + + + /* + Class : LogicalBinary + Description : Base class for binary logical predicate + */ + class LogicalBinary: public virtual Predicate{ + public: + LogicalBinary(); + virtual ~LogicalBinary(); + virtual void SetMesh( const SMDS_Mesh* theMesh ); + virtual void SetPredicate1(PredicatePtr thePred); + virtual void SetPredicate2(PredicatePtr thePred); + virtual SMDSAbs_ElementType GetType() const; + + protected: + PredicatePtr myPredicate1; + PredicatePtr myPredicate2; + }; + typedef boost::shared_ptr LogicalBinaryPtr; + + + /* + Class : LogicalAND + Description : Logical AND + */ + class LogicalAND: public virtual LogicalBinary{ + public: + virtual bool IsSatisfy( long theElementId ); + }; + + + /* + Class : LogicalOR + Description : Logical OR + */ + class LogicalOR: public virtual LogicalBinary{ + public: + virtual bool IsSatisfy( long theElementId ); + }; + + + /* + Class : ManifoldPart + Description : Predicate for manifold part of mesh + */ + class ManifoldPart: public virtual Predicate{ + public: + + /* internal class for algorithm uses */ + class Link + { + public: + Link( SMDS_MeshNode* theNode1, + SMDS_MeshNode* theNode2 ); + ~Link(); + + bool IsEqual( const ManifoldPart::Link& theLink ) const; + bool operator<(const ManifoldPart::Link& x) const; + + SMDS_MeshNode* myNode1; + SMDS_MeshNode* myNode2; + }; + + bool IsEqual( const ManifoldPart::Link& theLink1, + const ManifoldPart::Link& theLink2 ); + + typedef std::set TMapOfLink; + typedef std::vector TVectorOfFacePtr; + typedef std::vector TVectorOfLink; + typedef std::map TDataMapFacePtrInt; + typedef std::map TDataMapOfLinkFacePtr; + + ManifoldPart(); + ~ManifoldPart(); + virtual void SetMesh( const SMDS_Mesh* theMesh ); + // inoke when all parameters already set + virtual bool IsSatisfy( long theElementId ); + virtual SMDSAbs_ElementType GetType() const; + + void SetAngleTolerance( const double theAngToler ); + double GetAngleTolerance() const; + void SetIsOnlyManifold( const bool theIsOnly ); + void SetStartElem( const long theStartElemId ); + + private: + bool process(); + bool findConnected( const TDataMapFacePtrInt& theAllFacePtrInt, + SMDS_MeshFace* theStartFace, + TMapOfLink& theNonManifold, + TColStd_MapOfInteger& theResFaces ); + bool isInPlane( const SMDS_MeshFace* theFace1, + const SMDS_MeshFace* theFace2 ); + void expandBoundary( TMapOfLink& theMapOfBoundary, + TVectorOfLink& theSeqOfBoundary, + TDataMapOfLinkFacePtr& theDMapLinkFacePtr, + TMapOfLink& theNonManifold, + SMDS_MeshFace* theNextFace ) const; + + void getFacesByLink( const Link& theLink, + TVectorOfFacePtr& theFaces ) const; + + private: + const SMDS_Mesh* myMesh; + TColStd_MapOfInteger myMapIds; + TColStd_MapOfInteger myMapBadGeomIds; + TVectorOfFacePtr myAllFacePtr; + TDataMapFacePtrInt myAllFacePtrIntDMap; + double myAngToler; + bool myIsOnlyManifold; + long myStartElemId; + + }; + typedef boost::shared_ptr ManifoldPartPtr; + + + /* + Class : ElementsOnSurface + Description : Predicate elements that lying on indicated surface + (plane or cylinder) + */ + class ElementsOnSurface : public virtual Predicate { + public: + ElementsOnSurface(); + ~ElementsOnSurface(); + virtual void SetMesh( const SMDS_Mesh* theMesh ); + virtual bool IsSatisfy( long theElementId ); + virtual SMDSAbs_ElementType GetType() const; + + void SetTolerance( const double theToler ); + double GetTolerance() const; + void SetSurface( const TopoDS_Shape& theShape, + const SMDSAbs_ElementType theType ); + + private: + void process(); + void process( const SMDS_MeshElement* theElem ); + bool isOnSurface( const SMDS_MeshNode* theNode ) const; + + private: + const SMDS_Mesh* myMesh; + TColStd_MapOfInteger myIds; + SMDSAbs_ElementType myType; + Handle(Geom_Surface) mySurf; + double myToler; + }; + + typedef boost::shared_ptr ElementsOnSurfacePtr; + + + /* + FILTER + */ + class Filter{ + public: + Filter(); + virtual ~Filter(); + virtual void SetPredicate(PredicatePtr thePred); + + typedef std::vector TIdSequence; + + virtual + void + GetElementsId( const SMDS_Mesh* theMesh, + TIdSequence& theSequence ); + + static + void + GetElementsId( const SMDS_Mesh* theMesh, + PredicatePtr thePredicate, + TIdSequence& theSequence ); + + protected: + PredicatePtr myPredicate; + }; + }; +}; + + +#endif diff --git a/src/DriverMED/DriverMED_Family.h b/src/DriverMED/DriverMED_Family.h new file mode 100644 index 000000000..1632ccb3b --- /dev/null +++ b/src/DriverMED/DriverMED_Family.h @@ -0,0 +1,120 @@ +// SMESH DriverMED : tool to split groups on families +// +// Copyright (C) 2003 CEA +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org or email : webmaster.salome@opencascade.org +// +// +// +// File : DriverMED_Family.hxx +// Author : Julia DOROVSKIKH +// Module : SMESH +// $Header$ + +#ifndef _INCLUDE_DRIVERMED_FAMILY +#define _INCLUDE_DRIVERMED_FAMILY + +#include "SMDS_Mesh.hxx" +#include "SMESHDS_GroupBase.hxx" +#include "SMESHDS_SubMesh.hxx" +#include "MED_Common.hxx" + +#include +#include + +#define REST_NODES_FAMILY 1 +#define REST_EDGES_FAMILY -1 +#define REST_FACES_FAMILY -2 +#define REST_VOLUMES_FAMILY -3 +#define FIRST_NODE_FAMILY 2 +#define FIRST_ELEM_FAMILY -4 + +class DriverMED_Family; +typedef boost::shared_ptr DriverMED_FamilyPtr; + +class DriverMED_Family +{ + public: + + // Methods for groups storing to MED + + static std::list MakeFamilies (const std::map & theSubMeshes, + const std::list& theGroups, + const bool doGroupOfNodes, + const bool doGroupOfEdges, + const bool doGroupOfFaces, + const bool doGroupOfVolumes); + // Split each group from list and each sub-mesh from list + // on some parts (families) on the basis of the elements membership in other groups + // from and other sub-meshes from . + // Resulting families have no common elements. + + MED::PFamilyInfo GetFamilyInfo (const MED::PWrapper& theWrapper, + const MED::PMeshInfo& theMeshInfo) const; + // Create TFamilyInfo for this family + + const std::set& GetElements () const { return myElements; } + // Returns elements of this family + + int GetId () const { return myId; } + // Returns a family ID + + public: + + // Methods for groups reading from MED + + void AddElement (const SMDS_MeshElement* theElement) { myElements.insert(theElement); } + + void AddGroupName (std::string theGroupName) { myGroupNames.insert(theGroupName); } + + void SetType (const SMDSAbs_ElementType theType) { myType = theType; } + SMDSAbs_ElementType GetType () { return myType; } + + bool MemberOf (std::string theGroupName) const + { return (myGroupNames.find(theGroupName) != myGroupNames.end()); } + + const MED::TStringSet& GetGroupNames () const { return myGroupNames; } + + void SetId (const int theId) { myId = theId; } + // Sets a family ID + + private: + void Init (SMESHDS_GroupBase* group); + // Initialize the tool by SMESHDS_GroupBase + + static std::list SplitByType (SMESHDS_SubMesh* theSubMesh, + const int theId); + // Split on some parts (families) + // on the basis of the elements type. + + void Split (DriverMED_FamilyPtr by, + DriverMED_FamilyPtr common); + // Remove from elements, common with , + // Remove from elements, common with , + // Create family from common elements, with combined groups list. + + bool IsEmpty () const { return myElements.empty(); } + // Check, if this family has empty list of elements + + private: + int myId; + SMDSAbs_ElementType myType; + std::set myElements; + MED::TStringSet myGroupNames; +}; + +#endif diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.h b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.h new file mode 100644 index 000000000..cb72bccdf --- /dev/null +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.h @@ -0,0 +1,69 @@ +// SMESH DriverMED : driver to read and write 'med' files +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : DriverMED_R_SMESHDS_Mesh.h +// Module : SMESH + +#ifndef _INCLUDE_DRIVERMED_R_SMESHDS_MESH +#define _INCLUDE_DRIVERMED_R_SMESHDS_MESH + +#include "Driver_SMESHDS_Mesh.h" +#include "DriverMED_Family.h" + +#include + +class SMESHDS_Mesh; +class SMESHDS_Group; +class SMESHDS_SubMesh; + +typedef std::pair< std::string, SMDSAbs_ElementType > TNameAndType; + +class DriverMED_R_SMESHDS_Mesh: public Driver_SMESHDS_Mesh +{ + public: + virtual Status Perform(); + + std::list< TNameAndType > GetGroupNamesAndTypes(); + void GetGroup(SMESHDS_Group* theGroup); + void CreateAllSubMeshes(); + void GetSubMesh(SMESHDS_SubMesh* theSubMesh, const int theId); + + std::list GetMeshNames(Status& theStatus); + void SetMeshName(std::string theMeshName); + + private: + /*! + * \brief Ensure aFamily has required ID + * \param aFamily - a family to check + * \param anID - an ID aFamily should have + * \retval bool - true if successful + */ + bool checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const; + + private: + std::string myMeshName; + std::map myFamilies; + +}; + +#endif diff --git a/src/OBJECT/SMESH_Actor.cxx b/src/OBJECT/SMESH_Actor.cxx new file mode 100644 index 000000000..3c5e2e0d0 --- /dev/null +++ b/src/OBJECT/SMESH_Actor.cxx @@ -0,0 +1,1627 @@ +// SMESH OBJECT : interactive object for SMESH visualization +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESH_Actor.cxx +// Author : Nicolas REJNERI +// Module : SMESH +// $Header$ + + +#include "SMESH_ActorDef.h" +#include "SMESH_ActorUtils.h" +#include "SMESH_DeviceActor.h" +#include "SMESH_ControlsDef.hxx" +#include + +#include "SUIT_Session.h" +#include "SUIT_ResourceMgr.h" + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "utilities.h" + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +static int aLineWidthInc = 2; +static int aPointSizeInc = 2; + + +SMESH_ActorDef* SMESH_ActorDef::New(){ + return new SMESH_ActorDef(); +} + + +SMESH_Actor* SMESH_Actor::New(TVisualObjPtr theVisualObj, + const char* theEntry, + const char* theName, + int theIsClear) +{ + SMESH_ActorDef* anActor = SMESH_ActorDef::New(); + if(!anActor->Init(theVisualObj,theEntry,theName,theIsClear)){ + anActor->Delete(); + anActor = NULL; + } + if( anActor ) + anActor->UpdateScalarBar(); + return anActor; +} + + +SMESH_ActorDef::SMESH_ActorDef() +{ + if(MYDEBUG) MESSAGE("SMESH_ActorDef - "<resourceMgr(); + if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) ) + myControlsPrecision = (long)SMESH::GetFloat( "SMESH", "controls_precision", -1 ); + + float aPointSize = SMESH::GetFloat("SMESH:node_size",3); + float aLineWidth = SMESH::GetFloat("SMESH:element_width",1); + + vtkMatrix4x4 *aMatrix = vtkMatrix4x4::New(); + VTKViewer_ExtractUnstructuredGrid* aFilter = NULL; + + //Definition 2D and 3D divices of the actor + //----------------------------------------- + float anRGB[3] = {1,1,1}; + mySurfaceProp = vtkProperty::New(); + SMESH::GetColor( "SMESH", "fill_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) ); + mySurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] ); + + myBackSurfaceProp = vtkProperty::New(); + SMESH::GetColor( "SMESH", "backface_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 0, 255 ) ); + myBackSurfaceProp->SetColor( anRGB[0], anRGB[1], anRGB[2] ); + + my2DActor = SMESH_DeviceActor::New(); + my2DActor->SetUserMatrix(aMatrix); + my2DActor->PickableOff(); + my2DActor->SetProperty(mySurfaceProp); + my2DActor->SetBackfaceProperty(myBackSurfaceProp); + my2DActor->SetRepresentation(SMESH_DeviceActor::eSurface); + aFilter = my2DActor->GetExtractUnstructuredGrid(); + aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding); + aFilter->RegisterCellsWithType(VTK_TRIANGLE); + aFilter->RegisterCellsWithType(VTK_POLYGON); + aFilter->RegisterCellsWithType(VTK_QUAD); + + my3DActor = SMESH_DeviceActor::New(); + my3DActor->SetUserMatrix(aMatrix); + my3DActor->PickableOff(); + my3DActor->SetProperty(mySurfaceProp); + my3DActor->SetBackfaceProperty(myBackSurfaceProp); + my3DActor->SetRepresentation(SMESH_DeviceActor::eSurface); + aFilter = my3DActor->GetExtractUnstructuredGrid(); + aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding); + aFilter->RegisterCellsWithType(VTK_TETRA); + aFilter->RegisterCellsWithType(VTK_VOXEL); + aFilter->RegisterCellsWithType(VTK_HEXAHEDRON); + aFilter->RegisterCellsWithType(VTK_WEDGE); + aFilter->RegisterCellsWithType(VTK_PYRAMID); + aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET); + + //Definition 1D divice of the actor + //--------------------------------- + myEdgeProp = vtkProperty::New(); + myEdgeProp->SetAmbient(1.0); + myEdgeProp->SetDiffuse(0.0); + myEdgeProp->SetSpecular(0.0); + SMESH::GetColor( "SMESH", "outline_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 170, 255 ) ); + myEdgeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); + myEdgeProp->SetLineWidth(aLineWidth); + + my1DActor = SMESH_DeviceActor::New(); + my1DActor->SetUserMatrix(aMatrix); + my1DActor->PickableOff(); + my1DActor->SetHighlited(true); + my1DActor->SetProperty(myEdgeProp); + my1DActor->SetRepresentation(SMESH_DeviceActor::eSurface); + aFilter = my1DActor->GetExtractUnstructuredGrid(); + aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding); + aFilter->RegisterCellsWithType(VTK_LINE); + + my1DProp = vtkProperty::New(); + my1DProp->DeepCopy(myEdgeProp); + my1DProp->SetLineWidth(aLineWidth + aLineWidthInc); + my1DProp->SetPointSize(aPointSize); + + my1DExtProp = vtkProperty::New(); + my1DExtProp->DeepCopy(myEdgeProp); + anRGB[0] = 1 - anRGB[0]; + anRGB[1] = 1 - anRGB[1]; + anRGB[2] = 1 - anRGB[2]; + my1DExtProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); + my1DExtProp->SetLineWidth(aLineWidth + aLineWidthInc); + my1DExtProp->SetPointSize(aPointSize + aPointSizeInc); + + my1DExtActor = SMESH_DeviceActor::New(); + my1DExtActor->SetUserMatrix(aMatrix); + my1DExtActor->PickableOff(); + my1DExtActor->SetHighlited(true); + my1DExtActor->SetVisibility(false); + my1DExtActor->SetProperty(my1DExtProp); + my1DExtActor->SetRepresentation(SMESH_DeviceActor::eInsideframe); + aFilter = my1DExtActor->GetExtractUnstructuredGrid(); + aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding); + aFilter->RegisterCellsWithType(VTK_LINE); + + + //Definition 0D divice of the actor + //--------------------------------- + myNodeProp = vtkProperty::New(); + SMESH::GetColor( "SMESH", "node_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 0, 0 ) ); + myNodeProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); + myNodeProp->SetPointSize(aPointSize); + + myNodeActor = SMESH_DeviceActor::New(); + myNodeActor->SetUserMatrix(aMatrix); + myNodeActor->SetStoreClippingMapping(true); + myNodeActor->PickableOff(); + myNodeActor->SetVisibility(false); + myNodeActor->SetProperty(myNodeProp); + myNodeActor->SetRepresentation(SMESH_DeviceActor::ePoint); + aFilter = myNodeActor->GetExtractUnstructuredGrid(); + aFilter->SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints); + + + //Definition of Pickable and Highlitable engines + //---------------------------------------------- + + myBaseActor = SMESH_DeviceActor::New(); + myBaseActor->SetUserMatrix(aMatrix); + myBaseActor->SetStoreGemetryMapping(true); + myBaseActor->GetProperty()->SetOpacity(0.0); + + myPickableActor = myBaseActor; + + myHighlightProp = vtkProperty::New(); + myHighlightProp->SetAmbient(1.0); + myHighlightProp->SetDiffuse(0.0); + myHighlightProp->SetSpecular(0.0); + SMESH::GetColor( "SMESH", "selection_object_color", anRGB[0], anRGB[1], anRGB[2], QColor( 255, 255, 255 ) ); + myHighlightProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); + myHighlightProp->SetPointSize(aPointSize); + myHighlightProp->SetRepresentation(1); + + myPreselectProp = vtkProperty::New(); + myPreselectProp->SetAmbient(1.0); + myPreselectProp->SetDiffuse(0.0); + myPreselectProp->SetSpecular(0.0); + SMESH::GetColor( "SMESH", "highlight_color", anRGB[0], anRGB[1], anRGB[2], QColor( 0, 255, 255 ) ); + myPreselectProp->SetColor(anRGB[0],anRGB[1],anRGB[2]); + myPreselectProp->SetPointSize(aPointSize); + myPreselectProp->SetRepresentation(1); + + myHighlitableActor = SMESH_DeviceActor::New(); + myHighlitableActor->SetUserMatrix(aMatrix); + myHighlitableActor->PickableOff(); + myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe); + + SetShrinkFactor( SMESH::GetFloat( "SMESH:shrink_coeff", 0.75 ) ); + + myName = ""; + myIO = NULL; + + myControlMode = eNone; + myControlActor = my2DActor; + + //Definition of myScalarBarActor + //------------------------------ + myLookupTable = vtkLookupTable::New(); + //Fix for Bug PAL5195 - SMESH764: + //Controls - Aspect Ratio: incorrect colors of the best and worst values + myLookupTable->SetHueRange(0.667,0.0); + + myScalarBarActor = vtkScalarBarActor::New(); + myScalarBarActor->SetVisibility(false); + myScalarBarActor->SetLookupTable(myLookupTable); + + mgr = SUIT_Session::session()->resourceMgr(); + if( !mgr ) + return; + + //Definition of points numbering pipeline + //--------------------------------------- + myPointsNumDataSet = vtkUnstructuredGrid::New(); + + myPtsMaskPoints = vtkMaskPoints::New(); + myPtsMaskPoints->SetInput(myPointsNumDataSet); + myPtsMaskPoints->SetOnRatio(1); + + myPtsSelectVisiblePoints = vtkSelectVisiblePoints::New(); + myPtsSelectVisiblePoints->SetInput(myPtsMaskPoints->GetOutput()); + myPtsSelectVisiblePoints->SelectInvisibleOff(); + myPtsSelectVisiblePoints->SetTolerance(0.1); + + myPtsLabeledDataMapper = vtkLabeledDataMapper::New(); + myPtsLabeledDataMapper->SetInput(myPtsSelectVisiblePoints->GetOutput()); + myPtsLabeledDataMapper->SetLabelFormat("%g"); + myPtsLabeledDataMapper->SetLabelModeToLabelScalars(); + + vtkTextProperty* aPtsTextProp = vtkTextProperty::New(); + aPtsTextProp->SetFontFamilyToTimes(); + static int aPointsFontSize = 10; + aPtsTextProp->SetFontSize(aPointsFontSize); + aPtsTextProp->SetBold(1); + aPtsTextProp->SetItalic(0); + aPtsTextProp->SetShadow(0); + myPtsLabeledDataMapper->SetLabelTextProperty(aPtsTextProp); + aPtsTextProp->Delete(); + + myEntityMode = eAllEntity; + + myIsPointsLabeled = false; + + myPointLabels = vtkActor2D::New(); + myPointLabels->SetMapper(myPtsLabeledDataMapper); + myPointLabels->GetProperty()->SetColor(1,1,1); + myPointLabels->SetVisibility(myIsPointsLabeled); + + + //Definition of cells numbering pipeline + //--------------------------------------- + myCellsNumDataSet = vtkUnstructuredGrid::New(); + + myCellCenters = vtkCellCenters::New(); + myCellCenters->SetInput(myCellsNumDataSet); + + myClsMaskPoints = vtkMaskPoints::New(); + myClsMaskPoints->SetInput(myCellCenters->GetOutput()); + myClsMaskPoints->SetOnRatio(1); + + myClsSelectVisiblePoints = vtkSelectVisiblePoints::New(); + myClsSelectVisiblePoints->SetInput(myClsMaskPoints->GetOutput()); + myClsSelectVisiblePoints->SelectInvisibleOff(); + myClsSelectVisiblePoints->SetTolerance(0.1); + + myClsLabeledDataMapper = vtkLabeledDataMapper::New(); + myClsLabeledDataMapper->SetInput(myClsSelectVisiblePoints->GetOutput()); + myClsLabeledDataMapper->SetLabelFormat("%g"); + myClsLabeledDataMapper->SetLabelModeToLabelScalars(); + + vtkTextProperty* aClsTextProp = vtkTextProperty::New(); + aClsTextProp->SetFontFamilyToTimes(); + static int aCellsFontSize = 12; + aClsTextProp->SetFontSize(aCellsFontSize); + aClsTextProp->SetBold(1); + aClsTextProp->SetItalic(0); + aClsTextProp->SetShadow(0); + myClsLabeledDataMapper->SetLabelTextProperty(aClsTextProp); + aClsTextProp->Delete(); + + myIsCellsLabeled = false; + + myCellsLabels = vtkActor2D::New(); + myCellsLabels->SetMapper(myClsLabeledDataMapper); + myCellsLabels->GetProperty()->SetColor(0,1,0); + myCellsLabels->SetVisibility(myIsCellsLabeled); + + // Clipping planes + myImplicitBoolean = vtkImplicitBoolean::New(); + myImplicitBoolean->SetOperationTypeToIntersection(); +} + + +SMESH_ActorDef::~SMESH_ActorDef() +{ + if(MYDEBUG) MESSAGE("~SMESH_ActorDef - "<Delete(); + myLookupTable->Delete(); + + mySurfaceProp->Delete(); + myBackSurfaceProp->Delete(); + + myEdgeProp->Delete(); + myHighlightProp->Delete(); + myPreselectProp->Delete(); + + myNodeProp->Delete(); + + my1DProp->Delete(); + my1DActor->Delete(); + + my1DExtProp->Delete(); + my1DExtActor->Delete(); + + my2DActor->Delete(); + my3DActor->Delete(); + + myNodeActor->Delete(); + myBaseActor->Delete(); + + myHighlitableActor->Delete(); + + //Deleting of pints numbering pipeline + //--------------------------------------- + myPointsNumDataSet->Delete(); + + myPtsLabeledDataMapper->RemoveAllInputs(); + myPtsLabeledDataMapper->Delete(); + + myPtsSelectVisiblePoints->UnRegisterAllOutputs(); + myPtsSelectVisiblePoints->Delete(); + + myPtsMaskPoints->UnRegisterAllOutputs(); + myPtsMaskPoints->Delete(); + + myPointLabels->Delete(); + + + //Deleting of cells numbering pipeline + //--------------------------------------- + myCellsNumDataSet->Delete(); + + myClsLabeledDataMapper->RemoveAllInputs(); + myClsLabeledDataMapper->Delete(); + + myClsSelectVisiblePoints->UnRegisterAllOutputs(); + myClsSelectVisiblePoints->Delete(); + + myClsMaskPoints->UnRegisterAllOutputs(); + myClsMaskPoints->Delete(); + + myCellCenters->UnRegisterAllOutputs(); + myCellCenters->Delete(); + + myCellsLabels->Delete(); + + myImplicitBoolean->Delete(); + + myTimeStamp->Delete(); +} + + +void SMESH_ActorDef::SetPointsLabeled( bool theIsPointsLabeled ) +{ + vtkUnstructuredGrid* aGrid = GetUnstructuredGrid(); + myIsPointsLabeled = theIsPointsLabeled && aGrid->GetNumberOfPoints(); + + if ( myIsPointsLabeled ) + { + myPointsNumDataSet->ShallowCopy(aGrid); + vtkDataSet *aDataSet = myPointsNumDataSet; + + int aNbElem = aDataSet->GetNumberOfPoints(); + + vtkIntArray *anArray = vtkIntArray::New(); + anArray->SetNumberOfValues( aNbElem ); + + for ( int anId = 0; anId < aNbElem; anId++ ) + { + int aSMDSId = myVisualObj->GetNodeObjId( anId ); + anArray->SetValue( anId, aSMDSId ); + } + + aDataSet->GetPointData()->SetScalars( anArray ); + anArray->Delete(); + myPtsMaskPoints->SetInput( aDataSet ); + myPointLabels->SetVisibility( GetVisibility() ); + } + else + { + myPointLabels->SetVisibility( false ); + } + SetRepresentation(GetRepresentation()); + myTimeStamp->Modified(); +} + + +void SMESH_ActorDef::SetCellsLabeled(bool theIsCellsLabeled) +{ + vtkUnstructuredGrid* aGrid = GetUnstructuredGrid(); + myIsCellsLabeled = theIsCellsLabeled && aGrid->GetNumberOfPoints(); + if(myIsCellsLabeled){ + myCellsNumDataSet->ShallowCopy(aGrid); + vtkDataSet *aDataSet = myCellsNumDataSet; + int aNbElem = aDataSet->GetNumberOfCells(); + vtkIntArray *anArray = vtkIntArray::New(); + anArray->SetNumberOfValues(aNbElem); + for(int anId = 0; anId < aNbElem; anId++){ + int aSMDSId = myVisualObj->GetElemObjId(anId); + anArray->SetValue(anId,aSMDSId); + } + aDataSet->GetCellData()->SetScalars(anArray); + myCellCenters->SetInput(aDataSet); + myCellsLabels->SetVisibility(GetVisibility()); + }else{ + myCellsLabels->SetVisibility(false); + } + myTimeStamp->Modified(); +} + + +void +SMESH_ActorDef:: +SetControlMode(eControl theMode) +{ + SetControlMode(theMode,true); +} + + +void +SMESH_ActorDef:: +SetControlMode(eControl theMode, + bool theCheckEntityMode) +{ + SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr(); + if( !mgr ) + return; + + myControlMode = eNone; + theCheckEntityMode &= mgr->booleanValue( "SMESH", "display_entity", false ); + + my1DActor->GetMapper()->SetScalarVisibility(false); + my2DActor->GetMapper()->SetScalarVisibility(false); + my3DActor->GetMapper()->SetScalarVisibility(false); + myScalarBarActor->SetVisibility(false); + + bool anIsScalarVisible = theMode > eNone; + + if(anIsScalarVisible){ + SMESH::Controls::FunctorPtr aFunctor; + switch(theMode){ + case eLength: + { + SMESH::Controls::Length* aControl = new SMESH::Controls::Length(); + aControl->SetPrecision( myControlsPrecision ); + aFunctor.reset( aControl ); + myControlActor = my1DActor; + break; + } + case eLength2D: + { + aFunctor.reset(new SMESH::Controls::Length2D()); + myControlActor = my2DActor; + break; + } + case eFreeBorders: + aFunctor.reset(new SMESH::Controls::FreeBorders()); + myControlActor = my1DActor; + break; + case eFreeEdges: + aFunctor.reset(new SMESH::Controls::FreeEdges()); + myControlActor = my2DActor; + break; + case eMultiConnection: + aFunctor.reset(new SMESH::Controls::MultiConnection()); + myControlActor = my1DActor; + break; + case eMultiConnection2D: + aFunctor.reset(new SMESH::Controls::MultiConnection2D()); + myControlActor = my2DActor; + break; + case eArea: + { + SMESH::Controls::Area* aControl = new SMESH::Controls::Area(); + aControl->SetPrecision( myControlsPrecision ); + aFunctor.reset( aControl ); + myControlActor = my2DActor; + break; + } + case eTaper: + { + SMESH::Controls::Taper* aControl = new SMESH::Controls::Taper(); + aControl->SetPrecision( myControlsPrecision ); + aFunctor.reset( aControl ); + myControlActor = my2DActor; + break; + } + case eAspectRatio: + { + SMESH::Controls::AspectRatio* aControl = new SMESH::Controls::AspectRatio(); + aControl->SetPrecision( myControlsPrecision ); + aFunctor.reset( aControl ); + myControlActor = my2DActor; + break; + } + case eAspectRatio3D: + { + SMESH::Controls::AspectRatio3D* aControl = new SMESH::Controls::AspectRatio3D(); + aControl->SetPrecision( myControlsPrecision ); + aFunctor.reset( aControl ); + myControlActor = my3DActor; + break; + } + case eVolume3D: + { + SMESH::Controls::Volume* aControl = new SMESH::Controls::Volume(); + aControl->SetPrecision( myControlsPrecision ); + aFunctor.reset( aControl ); + myControlActor = my3DActor; + break; + } + case eMinimumAngle: + { + SMESH::Controls::MinimumAngle* aControl = new SMESH::Controls::MinimumAngle(); + aControl->SetPrecision( myControlsPrecision ); + aFunctor.reset( aControl ); + myControlActor = my2DActor; + break; + } + case eWarping: + { + SMESH::Controls::Warping* aControl = new SMESH::Controls::Warping(); + aControl->SetPrecision( myControlsPrecision ); + aFunctor.reset( aControl ); + myControlActor = my2DActor; + break; + } + case eSkew: + { + SMESH::Controls::Skew* aControl = new SMESH::Controls::Skew(); + aControl->SetPrecision( myControlsPrecision ); + aFunctor.reset( aControl ); + myControlActor = my2DActor; + break; + } + default: + return; + } + + vtkUnstructuredGrid* aGrid = myControlActor->GetUnstructuredGrid(); + vtkIdType aNbCells = aGrid->GetNumberOfCells(); + if(aNbCells){ + myControlMode = theMode; + switch(myControlMode){ + case eFreeEdges: + case eFreeBorders: + my1DExtActor->SetExtControlMode(aFunctor); + break; + case eLength2D: + case eMultiConnection2D: + my1DExtActor->SetExtControlMode(aFunctor,myScalarBarActor,myLookupTable); + break; + default: + myControlActor->SetControlMode(aFunctor,myScalarBarActor,myLookupTable); + } + } + + if(theCheckEntityMode){ + if(myControlActor == my1DActor) + SetEntityMode(eEdges); + else if(myControlActor == my2DActor){ + switch(myControlMode){ + case eLength2D: + case eFreeEdges: + case eMultiConnection2D: + //SetEntityMode(eEdges); + SetEntityMode(eFaces); + break; + default: + SetEntityMode(eFaces); + } + }else if(myControlActor == my3DActor) + SetEntityMode(eVolumes); + } + + }else if(theCheckEntityMode){ + myEntityMode = eAllEntity; + } + + SetRepresentation(GetRepresentation()); + + myTimeStamp->Modified(); + Modified(); +} + + +void SMESH_ActorDef::AddToRender(vtkRenderer* theRenderer){ + SALOME_Actor::AddToRender(theRenderer); + + theRenderer->AddActor(myNodeActor); + theRenderer->AddActor(myBaseActor); + + theRenderer->AddActor(my3DActor); + theRenderer->AddActor(my2DActor); + + theRenderer->AddActor(my1DActor); + theRenderer->AddActor(my1DExtActor); + + theRenderer->AddActor(myHighlitableActor); + + theRenderer->AddActor2D(myScalarBarActor); + + myPtsSelectVisiblePoints->SetRenderer(theRenderer); + myClsSelectVisiblePoints->SetRenderer(theRenderer); + + theRenderer->AddActor2D(myPointLabels); + theRenderer->AddActor2D(myCellsLabels); +} + +void SMESH_ActorDef::RemoveFromRender(vtkRenderer* theRenderer){ + SALOME_Actor::RemoveFromRender(theRenderer); + + theRenderer->RemoveActor(myNodeActor); + theRenderer->RemoveActor(myBaseActor); + + theRenderer->RemoveActor(myHighlitableActor); + + theRenderer->RemoveActor(my1DActor); + theRenderer->RemoveActor(my1DExtActor); + + theRenderer->RemoveActor(my2DActor); + theRenderer->RemoveActor(my3DActor); + + theRenderer->RemoveActor(myScalarBarActor); + theRenderer->RemoveActor(myPointLabels); + theRenderer->RemoveActor(myCellsLabels); +} + + +bool SMESH_ActorDef::Init(TVisualObjPtr theVisualObj, + const char* theEntry, + const char* theName, + int theIsClear) +{ + Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject(theEntry,"SMESH",theName); + setIO(anIO); + setName(theName); + + myVisualObj = theVisualObj; + myVisualObj->Update(theIsClear); + + myNodeActor->Init(myVisualObj,myImplicitBoolean); + myBaseActor->Init(myVisualObj,myImplicitBoolean); + + myHighlitableActor->Init(myVisualObj,myImplicitBoolean); + + my1DActor->Init(myVisualObj,myImplicitBoolean); + my1DExtActor->Init(myVisualObj,myImplicitBoolean); + + my2DActor->Init(myVisualObj,myImplicitBoolean); + my3DActor->Init(myVisualObj,myImplicitBoolean); + + my1DActor->GetMapper()->SetLookupTable(myLookupTable); + my1DExtActor->GetMapper()->SetLookupTable(myLookupTable); + + my2DActor->GetMapper()->SetLookupTable(myLookupTable); + my3DActor->GetMapper()->SetLookupTable(myLookupTable); + + float aFactor, aUnits; + my2DActor->GetPolygonOffsetParameters(aFactor,aUnits); + my2DActor->SetPolygonOffsetParameters(aFactor,aUnits*0.75); + + //SetIsShrunkable(theGrid->GetNumberOfCells() > 10); + SetIsShrunkable(true); + + SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr(); + if( !mgr ) + return false; + + int aMode = mgr->integerValue( "SMESH", "display_mode" ); + SetRepresentation(-1); + + if(aMode == 0){ + SetRepresentation(eEdge); + }else if(aMode == 1){ + SetRepresentation(eSurface); + }else if(aMode == 2){ + SetRepresentation(ePoint); + } + + if(aMode == 3){ + SetShrink(); + } + + myTimeStamp->Modified(); + Modified(); + return true; +} + + +float* SMESH_ActorDef::GetBounds(){ + return myNodeActor->GetBounds(); +} + + +vtkDataSet* SMESH_ActorDef::GetInput(){ + return GetUnstructuredGrid(); +} + + +void SMESH_ActorDef::SetTransform(VTKViewer_Transform* theTransform){ + myNodeActor->SetTransform(theTransform); + myBaseActor->SetTransform(theTransform); + + myHighlitableActor->SetTransform(theTransform); + + my1DActor->SetTransform(theTransform); + my1DExtActor->SetTransform(theTransform); + + my2DActor->SetTransform(theTransform); + my3DActor->SetTransform(theTransform); + + Modified(); +} + + +void SMESH_ActorDef::SetMapper(vtkMapper* theMapper){ + vtkLODActor::SetMapper(theMapper); +} + + +void SMESH_ActorDef::ShallowCopy(vtkProp *prop){ + SALOME_Actor::ShallowCopy(prop); +} + + +vtkMapper* SMESH_ActorDef::GetMapper(){ + return myPickableActor->GetMapper(); +} + + +vtkUnstructuredGrid* SMESH_ActorDef::GetUnstructuredGrid(){ + return myVisualObj->GetUnstructuredGrid(); +} + + +bool SMESH_ActorDef::IsInfinitive(){ + vtkDataSet *aDataSet = myPickableActor->GetUnstructuredGrid(); + aDataSet->Update(); + myIsInfinite = aDataSet->GetNumberOfCells() == 0 || + aDataSet->GetNumberOfCells() == 1 && + aDataSet->GetCell(0)->GetCellType() == VTK_VERTEX; + return SALOME_Actor::IsInfinitive(); +} + + +void SMESH_ActorDef::SetIsShrunkable(bool theShrunkable){ + myIsShrinkable = theShrunkable; + Modified(); +} + +float SMESH_ActorDef::GetShrinkFactor(){ + return myBaseActor->GetShrinkFactor(); +} + +void SMESH_ActorDef::SetShrinkFactor(float theValue){ + myBaseActor->SetShrinkFactor(theValue); + + my1DActor->SetShrinkFactor(theValue); + my1DExtActor->SetShrinkFactor(theValue); + + my2DActor->SetShrinkFactor(theValue); + my3DActor->SetShrinkFactor(theValue); + + Modified(); +} + +void SMESH_ActorDef::SetShrink(){ + if(!myIsShrinkable) return; + + myBaseActor->SetShrink(); + + my1DActor->SetShrink(); + my1DExtActor->SetShrink(); + + my2DActor->SetShrink(); + my3DActor->SetShrink(); + + myIsShrunk = true; + Modified(); +} + +void SMESH_ActorDef::UnShrink(){ + if(!myIsShrunk) return; + + myBaseActor->UnShrink(); + + my1DActor->UnShrink(); + my1DExtActor->UnShrink(); + + my2DActor->UnShrink(); + my3DActor->UnShrink(); + + myIsShrunk = false; + Modified(); +} + + +int SMESH_ActorDef::GetNodeObjId(int theVtkID){ + return myPickableActor->GetNodeObjId(theVtkID); +} + +float* SMESH_ActorDef::GetNodeCoord(int theObjID){ + return myPickableActor->GetNodeCoord(theObjID); +} + + +int SMESH_ActorDef::GetElemObjId(int theVtkID){ + return myPickableActor->GetElemObjId(theVtkID); +} + +vtkCell* SMESH_ActorDef::GetElemCell(int theObjID){ + return myPickableActor->GetElemCell(theObjID); +} + + +void SMESH_ActorDef::SetVisibility(int theMode){ + SetVisibility(theMode,true); +} + + +void SMESH_ActorDef::SetVisibility(int theMode, bool theIsUpdateRepersentation){ + SALOME_Actor::SetVisibility(theMode); + + myNodeActor->VisibilityOff(); + myBaseActor->VisibilityOff(); + + my1DActor->VisibilityOff(); + my1DExtActor->VisibilityOff(); + + my2DActor->VisibilityOff(); + my3DActor->VisibilityOff(); + + myScalarBarActor->VisibilityOff(); + myPointLabels->VisibilityOff(); + myCellsLabels->VisibilityOff(); + + if(GetVisibility()){ + if(theIsUpdateRepersentation) + SetRepresentation(GetRepresentation()); + + if(myControlMode != eNone){ + switch(myControlMode){ + case eFreeEdges: + case eFreeBorders: + my1DExtActor->VisibilityOn(); + break; + case eLength2D: + case eMultiConnection2D: + my1DExtActor->VisibilityOn(); + default: + if(myControlActor->GetUnstructuredGrid()->GetNumberOfCells()) + myScalarBarActor->VisibilityOn(); + } + } + + if(myRepresentation != ePoint) + myPickableActor->VisibilityOn(); + else { + myNodeActor->VisibilityOn(); + } + + if(myEntityMode & eEdges){ + my1DActor->VisibilityOn(); + } + + if(myEntityMode & eFaces){ + my2DActor->VisibilityOn(); + } + + if(myEntityMode & eVolumes){ + my3DActor->VisibilityOn(); + } + + if(myIsPointsLabeled){ + myPointLabels->VisibilityOn(); + myNodeActor->VisibilityOn(); + } + + if(myIsCellsLabeled) + myCellsLabels->VisibilityOn(); + } + + Modified(); +} + + +void SMESH_ActorDef::SetEntityMode(unsigned int theMode){ + myEntityState = eAllEntity; + + if(!myVisualObj->GetNbEntities(SMDSAbs_Edge)){ + myEntityState &= ~eEdges; + theMode &= ~eEdges; + } + + if(!myVisualObj->GetNbEntities(SMDSAbs_Face)){ + myEntityState &= ~eFaces; + theMode &= ~eFaces; + } + + if(!myVisualObj->GetNbEntities(SMDSAbs_Volume)){ + myEntityState &= ~eVolumes; + theMode &= ~eVolumes; + } + + if(!theMode){ + if(myVisualObj->GetNbEntities(SMDSAbs_Edge)) + theMode |= eEdges; + + if(myVisualObj->GetNbEntities(SMDSAbs_Face)) + theMode |= eFaces; + + if(myVisualObj->GetNbEntities(SMDSAbs_Volume)) + theMode |= eVolumes; + } + + myBaseActor->myGeomFilter->SetInside(myEntityMode != myEntityState); + + myEntityMode = theMode; + VTKViewer_ExtractUnstructuredGrid* aFilter = NULL; + aFilter = myBaseActor->GetExtractUnstructuredGrid(); + aFilter->ClearRegisteredCellsWithType(); + aFilter->SetModeOfChanging(VTKViewer_ExtractUnstructuredGrid::eAdding); + + if(myEntityMode & eEdges){ + if (MYDEBUG) MESSAGE("EDGES"); + aFilter->RegisterCellsWithType(VTK_LINE); + } + + if(myEntityMode & eFaces){ + if (MYDEBUG) MESSAGE("FACES"); + aFilter->RegisterCellsWithType(VTK_TRIANGLE); + aFilter->RegisterCellsWithType(VTK_POLYGON); + aFilter->RegisterCellsWithType(VTK_QUAD); + } + + if(myEntityMode & eVolumes){ + if (MYDEBUG) MESSAGE("VOLUMES"); + aFilter->RegisterCellsWithType(VTK_TETRA); + aFilter->RegisterCellsWithType(VTK_VOXEL); + aFilter->RegisterCellsWithType(VTK_HEXAHEDRON); + aFilter->RegisterCellsWithType(VTK_WEDGE); + aFilter->RegisterCellsWithType(VTK_PYRAMID); + aFilter->RegisterCellsWithType(VTK_CONVEX_POINT_SET); + } + aFilter->Update(); + if (MYDEBUG) MESSAGE(aFilter->GetOutput()->GetNumberOfCells()); + SetVisibility(GetVisibility(),false); +} + +void SMESH_ActorDef::SetRepresentation(int theMode){ + int aNbEdges = myVisualObj->GetNbEntities(SMDSAbs_Edge); + int aNbFaces = myVisualObj->GetNbEntities(SMDSAbs_Face); + int aNbVolumes = myVisualObj->GetNbEntities(SMDSAbs_Volume); + if(theMode < 0){ + myRepresentation = eSurface; + if(!aNbFaces && !aNbVolumes && aNbEdges){ + myRepresentation = eEdge; + }else if(!aNbFaces && !aNbVolumes && !aNbEdges){ + myRepresentation = ePoint; + } + }else{ + switch(theMode){ + case eEdge: + if(!aNbFaces && !aNbVolumes && !aNbEdges) return; + break; + case eSurface: + if(!aNbFaces && !aNbVolumes) return; + break; + } + myRepresentation = theMode; + } + + if(!GetUnstructuredGrid()->GetNumberOfCells()) + myRepresentation = ePoint; + + if(myIsShrunk){ + if(myRepresentation == ePoint){ + UnShrink(); + myIsShrunk = true; + }else{ + SetShrink(); + } + } + + myPickableActor = myBaseActor; + myNodeActor->SetVisibility(false); + vtkProperty *aProp = NULL, *aBackProp = NULL; + SMESH_DeviceActor::EReperesent aReperesent = SMESH_DeviceActor::EReperesent(-1); + switch(myRepresentation){ + case ePoint: + myPickableActor = myNodeActor; + myNodeActor->SetVisibility(true); + + aProp = aBackProp = myNodeProp; + aReperesent = SMESH_DeviceActor::ePoint; + break; + case eEdge: + aProp = aBackProp = myEdgeProp; + aReperesent = SMESH_DeviceActor::eInsideframe; + break; + case eSurface: + aProp = mySurfaceProp; + aBackProp = myBackSurfaceProp; + aReperesent = SMESH_DeviceActor::eSurface; + break; + } + + my2DActor->SetProperty(aProp); + my2DActor->SetBackfaceProperty(aBackProp); + my2DActor->SetRepresentation(aReperesent); + + my3DActor->SetProperty(aProp); + my3DActor->SetBackfaceProperty(aBackProp); + my3DActor->SetRepresentation(aReperesent); + + my1DExtActor->SetVisibility(false); + + switch(myControlMode){ + case eLength: + case eMultiConnection: + aProp = aBackProp = my1DProp; + if(myRepresentation != ePoint) + aReperesent = SMESH_DeviceActor::eInsideframe; + break; + } + + my1DActor->SetProperty(aProp); + my1DActor->SetBackfaceProperty(aBackProp); + my1DActor->SetRepresentation(aReperesent); + + my1DExtActor->SetRepresentation(aReperesent); + + if(myIsPointsVisible) + myPickableActor = myNodeActor; + if(GetPointRepresentation()) + myNodeActor->SetVisibility(true); + + SetMapper(myPickableActor->GetMapper()); + + SetVisibility(GetVisibility(),false); + + Modified(); +} + + +void SMESH_ActorDef::SetPointRepresentation(bool theIsPointsVisible){ + myIsPointsVisible = theIsPointsVisible; + SetRepresentation(GetRepresentation()); +} + +bool SMESH_ActorDef::GetPointRepresentation(){ + return myIsPointsVisible || myIsPointsLabeled; +} + + +void SMESH_ActorDef::UpdateHighlight(){ + myHighlitableActor->SetVisibility(false); + myHighlitableActor->SetHighlited(false); + + if(myIsHighlighted){ + myHighlitableActor->SetProperty(myHighlightProp); + }else if(myIsPreselected){ + myHighlitableActor->SetProperty(myPreselectProp); + } + + bool anIsVisible = GetVisibility(); + + if(myIsHighlighted || myIsPreselected){ + if(GetUnstructuredGrid()->GetNumberOfCells()){ + myHighlitableActor->SetHighlited(anIsVisible); + myHighlitableActor->SetVisibility(anIsVisible); + myHighlitableActor->GetExtractUnstructuredGrid()-> + SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::eCells); + myHighlitableActor->SetRepresentation(SMESH_DeviceActor::eWireframe); + }else if(myRepresentation == ePoint || GetPointRepresentation()){ + myHighlitableActor->SetHighlited(anIsVisible); + myHighlitableActor->SetVisibility(anIsVisible); + myHighlitableActor->GetExtractUnstructuredGrid()-> + SetModeOfExtraction(VTKViewer_ExtractUnstructuredGrid::ePoints); + myHighlitableActor->SetRepresentation(SMESH_DeviceActor::ePoint); + } + } +} + + +void SMESH_ActorDef::highlight(bool theHighlight){ + myIsHighlighted = theHighlight; + UpdateHighlight(); +} + + +void SMESH_ActorDef::SetPreSelected(bool thePreselect){ + myIsPreselected = thePreselect; + UpdateHighlight(); +} + + +// From vtkFollower +int SMESH_ActorDef::RenderOpaqueGeometry(vtkViewport *vp) +{ + if (myPickableActor->GetIsOpaque()) + { + vtkRenderer *ren = static_cast(vp); + this->Render(ren); + return 1; + } + return 0; +} + + +int SMESH_ActorDef::RenderTranslucentGeometry(vtkViewport *vp) +{ + if (!myPickableActor->GetIsOpaque()) + { + vtkRenderer *ren = static_cast(vp); + this->Render(ren); + return 1; + } + return 0; +} + + +void SMESH_ActorDef::Render(vtkRenderer *ren){ + unsigned long aTime = myTimeStamp->GetMTime(); + unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime(); + unsigned long aClippingTime = myImplicitBoolean->GetMTime(); + if(anObjTime > aTime || aClippingTime > aTime) + Update(); +} + + +void SMESH_ActorDef::Update(){ + if(MYDEBUG) MESSAGE("SMESH_ActorDef::Update"); + + if(GetControlMode() != eNone) { + unsigned long aTime = myTimeStamp->GetMTime(); + unsigned long anObjTime = myVisualObj->GetUnstructuredGrid()->GetMTime(); + if (anObjTime > aTime) + SetControlMode(GetControlMode(),false); + } + if(myIsPointsLabeled){ + SetPointsLabeled(myIsPointsLabeled); + } + if(myIsCellsLabeled){ + SetCellsLabeled(myIsCellsLabeled); + } + SetEntityMode(GetEntityMode()); + SetVisibility(GetVisibility()); + + myTimeStamp->Modified(); + Modified(); +} + + +void SMESH_ActorDef::ReleaseGraphicsResources(vtkWindow *renWin){ + SALOME_Actor::ReleaseGraphicsResources(renWin); + + myPickableActor->ReleaseGraphicsResources(renWin); +} + + +static void GetColor(vtkProperty *theProperty, float& r,float& g,float& b){ + float* aColor = theProperty->GetColor(); + r = aColor[0]; + g = aColor[1]; + b = aColor[2]; +} + + +void SMESH_ActorDef::SetOpacity(float theValue){ + mySurfaceProp->SetOpacity(theValue); + myBackSurfaceProp->SetOpacity(theValue); + myEdgeProp->SetOpacity(theValue); + myNodeProp->SetOpacity(theValue); + + my1DProp->SetOpacity(theValue); +} + + +float SMESH_ActorDef::GetOpacity(){ + return mySurfaceProp->GetOpacity(); +} + + +void SMESH_ActorDef::SetSufaceColor(float r,float g,float b){ + mySurfaceProp->SetColor(r,g,b); + Modified(); +} + +void SMESH_ActorDef::GetSufaceColor(float& r,float& g,float& b){ + ::GetColor(mySurfaceProp,r,g,b); +} + +void SMESH_ActorDef::SetBackSufaceColor(float r,float g,float b){ + myBackSurfaceProp->SetColor(r,g,b); + Modified(); +} + +void SMESH_ActorDef::GetBackSufaceColor(float& r,float& g,float& b){ + ::GetColor(myBackSurfaceProp,r,g,b); +} + +void SMESH_ActorDef::SetEdgeColor(float r,float g,float b){ + myEdgeProp->SetColor(r,g,b); + my1DProp->SetColor(r,g,b); + my1DExtProp->SetColor(1.0-r,1.0-g,1.0-b); + Modified(); +} + +void SMESH_ActorDef::GetEdgeColor(float& r,float& g,float& b){ + ::GetColor(myEdgeProp,r,g,b); +} + +void SMESH_ActorDef::SetNodeColor(float r,float g,float b){ + myNodeProp->SetColor(r,g,b); + Modified(); +} + +void SMESH_ActorDef::GetNodeColor(float& r,float& g,float& b){ + ::GetColor(myNodeProp,r,g,b); +} + +void SMESH_ActorDef::SetHighlightColor(float r,float g,float b){ + myHighlightProp->SetColor(r,g,b); + Modified(); +} + +void SMESH_ActorDef::GetHighlightColor(float& r,float& g,float& b){ + ::GetColor(myHighlightProp,r,g,b); +} + +void SMESH_ActorDef::SetPreHighlightColor(float r,float g,float b){ + myPreselectProp->SetColor(r,g,b); + Modified(); +} + +void SMESH_ActorDef::GetPreHighlightColor(float& r,float& g,float& b){ + ::GetColor(myPreselectProp,r,g,b); +} + + +float SMESH_ActorDef::GetLineWidth(){ + return myEdgeProp->GetLineWidth(); +} + + +void SMESH_ActorDef::SetLineWidth(float theVal){ + myEdgeProp->SetLineWidth(theVal); + + my1DProp->SetLineWidth(theVal + aLineWidthInc); + my1DExtProp->SetLineWidth(theVal + aLineWidthInc); + + Modified(); +} + + +void SMESH_ActorDef::SetNodeSize(float theVal){ + myNodeProp->SetPointSize(theVal); + myHighlightProp->SetPointSize(theVal); + myPreselectProp->SetPointSize(theVal); + + my1DProp->SetPointSize(theVal + aPointSizeInc); + my1DExtProp->SetPointSize(theVal + aPointSizeInc); + + Modified(); +} + +float SMESH_ActorDef::GetNodeSize(){ + return myNodeProp->GetPointSize(); +} + +int SMESH_ActorDef::GetObjDimension( const int theObjId ) +{ + return myVisualObj->GetElemDimension( theObjId ); +} + +bool +SMESH_ActorDef:: +IsImplicitFunctionUsed() const +{ + return myBaseActor->IsImplicitFunctionUsed(); +} + +void +SMESH_ActorDef:: +SetImplicitFunctionUsed(bool theIsImplicitFunctionUsed) +{ + myNodeActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed); + myBaseActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed); + + myHighlitableActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed); + + my1DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed); + my1DExtActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed); + + my2DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed); + my3DActor->SetImplicitFunctionUsed(theIsImplicitFunctionUsed); +} + +vtkIdType +SMESH_ActorDef:: +AddClippingPlane(vtkPlane* thePlane) +{ + if(thePlane){ + myImplicitBoolean->GetFunction()->AddItem(thePlane); + myCippingPlaneCont.push_back(thePlane); + if(!IsImplicitFunctionUsed()) + SetImplicitFunctionUsed(true); + } + return myCippingPlaneCont.size(); +} + +void +SMESH_ActorDef:: +RemoveAllClippingPlanes() +{ + myImplicitBoolean->GetFunction()->RemoveAllItems(); + myImplicitBoolean->GetFunction()->Modified(); // VTK bug + myCippingPlaneCont.clear(); + SetImplicitFunctionUsed(false); +} + +vtkIdType +SMESH_ActorDef:: +GetNumberOfClippingPlanes() +{ + return myCippingPlaneCont.size(); +} + +vtkPlane* +SMESH_ActorDef:: +GetClippingPlane(vtkIdType theID) +{ + if(theID >= myCippingPlaneCont.size()) + return NULL; + return myCippingPlaneCont[theID].Get(); +} + + +static void ComputeBoundsParam(vtkDataSet* theDataSet, + float theDirection[3], float theMinPnt[3], + float& theMaxBoundPrj, float& theMinBoundPrj) +{ + float aBounds[6]; + theDataSet->GetBounds(aBounds); + + //Enlarge bounds in order to avoid conflicts of precision + for(int i = 0; i < 6; i += 2){ + static double EPS = 1.0E-3; + float aDelta = (aBounds[i+1] - aBounds[i])*EPS; + aBounds[i] -= aDelta; + aBounds[i+1] += aDelta; + } + + float aBoundPoints[8][3] = { {aBounds[0],aBounds[2],aBounds[4]}, + {aBounds[1],aBounds[2],aBounds[4]}, + {aBounds[0],aBounds[3],aBounds[4]}, + {aBounds[1],aBounds[3],aBounds[4]}, + {aBounds[0],aBounds[2],aBounds[5]}, + {aBounds[1],aBounds[2],aBounds[5]}, + {aBounds[0],aBounds[3],aBounds[5]}, + {aBounds[1],aBounds[3],aBounds[5]}}; + + int aMaxId = 0, aMinId = aMaxId; + theMaxBoundPrj = vtkMath::Dot(theDirection,aBoundPoints[aMaxId]); + theMinBoundPrj = theMaxBoundPrj; + for(int i = 1; i < 8; i++){ + float aTmp = vtkMath::Dot(theDirection,aBoundPoints[i]); + if(theMaxBoundPrj < aTmp){ + theMaxBoundPrj = aTmp; + aMaxId = i; + } + if(theMinBoundPrj > aTmp){ + theMinBoundPrj = aTmp; + aMinId = i; + } + } + float *aMinPnt = aBoundPoints[aMaxId]; + theMinPnt[0] = aMinPnt[0]; + theMinPnt[1] = aMinPnt[1]; + theMinPnt[2] = aMinPnt[2]; +} + + +static void DistanceToPosition(vtkDataSet* theDataSet, + float theDirection[3], float theDist, float thePos[3]) +{ + float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3]; + ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj); + float aLength = (aMaxBoundPrj-aMinBoundPrj)*theDist; + thePos[0] = aMinPnt[0]-theDirection[0]*aLength; + thePos[1] = aMinPnt[1]-theDirection[1]*aLength; + thePos[2] = aMinPnt[2]-theDirection[2]*aLength; +} + + +static void PositionToDistance(vtkDataSet* theDataSet, + float theDirection[3], float thePos[3], float& theDist) +{ + float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3]; + ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj); + float aPrj = vtkMath::Dot(theDirection,thePos); + theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj); +} + + +void SMESH_ActorDef::SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane) +{ + thePlane->SetNormal(theDir); + float anOrigin[3]; + ::DistanceToPosition(GetUnstructuredGrid(),theDir,theDist,anOrigin); + thePlane->SetOrigin(anOrigin); +} + + +void SMESH_ActorDef::GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane) +{ + thePlane->GetNormal(theDir); + + float anOrigin[3]; + thePlane->GetOrigin(anOrigin); + ::PositionToDistance(GetUnstructuredGrid(),theDir,anOrigin,theDist); +} + +void SMESH_ActorDef::UpdateScalarBar() +{ + SUIT_ResourceMgr* mgr = SUIT_Session::session()->resourceMgr(); + if( !mgr ) + return; + + vtkTextProperty* aScalarBarTitleProp = vtkTextProperty::New(); + + QColor aTColor = mgr->colorValue( "SMESH", "scalar_bar_title_color", QColor( 255, 255, 255 ) ); + aScalarBarTitleProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. ); + + aScalarBarTitleProp->SetFontFamilyToArial(); + + if ( mgr->hasValue( "SMESH", "scalar_bar_title_font" ) ) + { + QFont f = mgr->fontValue( "SMESH", "scalar_bar_title_font" ); + if ( f.family() == "Arial" ) + aScalarBarTitleProp->SetFontFamilyToArial(); + else if ( f.family() == "Courier" ) + aScalarBarTitleProp->SetFontFamilyToCourier(); + else if ( f.family() == "Times" ) + aScalarBarTitleProp->SetFontFamilyToTimes(); + + if ( f.bold() ) + aScalarBarTitleProp->BoldOn(); + else + aScalarBarTitleProp->BoldOff(); + + if ( f.italic() ) + aScalarBarTitleProp->ItalicOn(); + else + aScalarBarTitleProp->ItalicOff(); + + if ( f.underline() ) + aScalarBarTitleProp->ShadowOn(); + else + aScalarBarTitleProp->ShadowOff(); + } + + myScalarBarActor->SetTitleTextProperty( aScalarBarTitleProp ); + aScalarBarTitleProp->Delete(); + + vtkTextProperty* aScalarBarLabelProp = vtkTextProperty::New(); + + aTColor = mgr->colorValue( "SMESH", "scalar_bar_label_color", QColor( 255, 255, 255 ) ); + aScalarBarLabelProp->SetColor( aTColor.red()/255., aTColor.green()/255., aTColor.blue()/255. ); + + aScalarBarLabelProp->SetFontFamilyToArial(); + if( mgr->hasValue( "SMESH", "scalar_bar_label_font" ) ) + { + QFont f = mgr->stringValue( "SMESH", "scalar_bar_label_font" ); + if( f.family() == "Arial" ) + aScalarBarLabelProp->SetFontFamilyToArial(); + else if( f.family() == "Courier" ) + aScalarBarLabelProp->SetFontFamilyToCourier(); + else if( f.family() == "Times" ) + aScalarBarLabelProp->SetFontFamilyToTimes(); + + if ( f.bold() ) + aScalarBarLabelProp->BoldOn(); + else + aScalarBarLabelProp->BoldOff(); + + if ( f.italic() ) + aScalarBarLabelProp->ItalicOn(); + else + aScalarBarLabelProp->ItalicOff(); + + if( f.underline() ) + aScalarBarLabelProp->ShadowOn(); + else + aScalarBarLabelProp->ShadowOff(); + } + + myScalarBarActor->SetLabelTextProperty( aScalarBarLabelProp ); + aScalarBarLabelProp->Delete(); + + bool horiz = ( mgr->integerValue( "SMESH", "scalar_bar_orientation" ) == 1 ); + QString name = QString( "scalar_bar_%1_" ).arg( horiz ? "horizontal" : "vertical" ); + if( horiz ) + myScalarBarActor->SetOrientationToHorizontal(); + else + myScalarBarActor->SetOrientationToVertical(); + + + float aXVal = horiz ? 0.20 : 0.01; + if( mgr->hasValue( "SMESH", name + "x" ) ) + aXVal = mgr->doubleValue( "SMESH", name + "x", aXVal ); + + float aYVal = horiz ? 0.01 : 0.1; + if( mgr->hasValue( "SMESH", name + "y" ) ) + aYVal = mgr->doubleValue( "SMESH", name + "y", aYVal ); + myScalarBarActor->SetPosition( aXVal, aYVal ); + + float aWVal = horiz ? 0.60 : 0.10; + if( mgr->hasValue( "SMESH", name + "width" ) ) + aWVal = mgr->doubleValue( "SMESH", name + "width", aWVal ); + myScalarBarActor->SetWidth( aWVal ); + + float aHVal = horiz ? 0.12 : 0.80; + if( mgr->hasValue( "SMESH", name + "height" ) ) + aHVal = mgr->doubleValue( "SMESH", name + "height", aHVal ); + myScalarBarActor->SetHeight( aHVal ); + + int anIntVal = 5; + if( mgr->hasValue( "SMESH", "scalar_bar_num_labels" ) ) + anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_labels", anIntVal ); + myScalarBarActor->SetNumberOfLabels( anIntVal == 0 ? 5: anIntVal ); + + anIntVal = 64; + if( mgr->hasValue( "SMESH", "scalar_bar_num_colors" ) ) + anIntVal = mgr->integerValue( "SMESH", "scalar_bar_num_colors", anIntVal ); + myScalarBarActor->SetMaximumNumberOfColors( anIntVal == 0 ? 64 : anIntVal ); + +} diff --git a/src/OBJECT/SMESH_Actor.h b/src/OBJECT/SMESH_Actor.h new file mode 100644 index 000000000..7319914d7 --- /dev/null +++ b/src/OBJECT/SMESH_Actor.h @@ -0,0 +1,121 @@ +// SMESH OBJECT : interactive object for SMESH visualization +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESH_Actor.h +// Author : Nicolas REJNERI +// Module : SMESH +// $Header$ + +#ifndef SMESH_ACTOR_H +#define SMESH_ACTOR_H + +#include +#include "SMESH_Object.h" + +class vtkUnstructuredGrid; + +class vtkScalarBarActor; + +class vtkPlane; +class vtkImplicitBoolean; + +class SMESH_Actor: public SALOME_Actor +{ + static SMESH_Actor* New() { return NULL;} + + public: + vtkTypeMacro(SMESH_Actor,SALOME_Actor); + static SMESH_Actor* New(TVisualObjPtr theVisualObj, + const char* theEntry, + const char* theName, + int theIsClear); + + virtual void SetSufaceColor(float r,float g,float b) = 0; + virtual void GetSufaceColor(float& r,float& g,float& b) = 0; + + virtual void SetBackSufaceColor(float r,float g,float b) = 0; + virtual void GetBackSufaceColor(float& r,float& g,float& b) = 0; + + virtual void SetEdgeColor(float r,float g,float b) = 0; + virtual void GetEdgeColor(float& r,float& g,float& b) = 0; + + virtual void SetNodeColor(float r,float g,float b) = 0; + virtual void GetNodeColor(float& r,float& g,float& b) = 0; + + virtual void SetHighlightColor(float r,float g,float b) = 0; + virtual void GetHighlightColor(float& r,float& g,float& b) = 0; + + virtual void SetPreHighlightColor(float r,float g,float b) = 0; + virtual void GetPreHighlightColor(float& r,float& g,float& b) = 0; + + virtual float GetLineWidth() = 0; + virtual void SetLineWidth(float theVal) = 0; + + virtual void SetNodeSize(float size) = 0; + virtual float GetNodeSize() = 0; + + enum EReperesent { ePoint, eEdge, eSurface}; + + enum EEntityMode { eEdges = 0x01, eFaces = 0x02, eVolumes = 0x04, eAllEntity = 0x07}; + virtual void SetEntityMode(unsigned int theMode) = 0; + virtual unsigned int GetEntityMode() const = 0; + + virtual void SetPointRepresentation(bool theIsPointsVisible) = 0; + virtual bool GetPointRepresentation() = 0; + + virtual vtkUnstructuredGrid* GetUnstructuredGrid() = 0; + + virtual void SetShrinkFactor(float theValue) = 0; + + virtual void SetPointsLabeled(bool theIsPointsLabeled) = 0; + virtual bool GetPointsLabeled() = 0; + + virtual void SetCellsLabeled(bool theIsCellsLabeled) = 0; + virtual bool GetCellsLabeled() = 0; + + enum eControl{eNone, eLength, eLength2D, eFreeBorders, eFreeEdges, eMultiConnection, + eArea, eTaper, eAspectRatio, eMinimumAngle, eWarping, eSkew, + eAspectRatio3D, eMultiConnection2D, eVolume3D}; + virtual void SetControlMode(eControl theMode) = 0; + virtual eControl GetControlMode() = 0; + + virtual vtkScalarBarActor* GetScalarBarActor() = 0; + + virtual void SetPlaneParam(float theDir[3], float theDist, vtkPlane* thePlane) = 0; + virtual void GetPlaneParam(float theDir[3], float& theDist, vtkPlane* thePlane) = 0; + + virtual void RemoveAllClippingPlanes() = 0; + virtual vtkIdType GetNumberOfClippingPlanes() = 0; + virtual vtkPlane* GetClippingPlane(vtkIdType theID) = 0; + virtual vtkIdType AddClippingPlane(vtkPlane* thePlane) = 0; + + virtual TVisualObjPtr GetObject() = 0; + + virtual void SetControlsPrecision( const long ) = 0; + virtual long GetControlsPrecision() const = 0; + + virtual void UpdateScalarBar() = 0; +}; + + +#endif //SMESH_ACTOR_H diff --git a/src/SMDS/SMDS_VolumeTool.hxx b/src/SMDS/SMDS_VolumeTool.hxx new file mode 100644 index 000000000..beec061b7 --- /dev/null +++ b/src/SMDS/SMDS_VolumeTool.hxx @@ -0,0 +1,265 @@ +// SMESH SMDS : implementaion of Salome mesh data structure +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMDS_VolumeTool.hxx +// Module : SMESH +// Created : Tue Jul 13 11:27:17 2004 +// Author : Edward AGAPOV (eap) + + +#ifndef SMDS_VolumeTool_HeaderFile +#define SMDS_VolumeTool_HeaderFile + +class SMDS_MeshElement; +class SMDS_MeshNode; +class SMDS_PolyhedralVolumeOfNodes; + +#include +#include + +//#ifdef WNT +//#include +//#else +//#define SALOME_WNT_EXPORT +//#endif + +#if defined WNT && defined WIN32 && defined SMDS_EXPORTS +#define SMDS_WNT_EXPORT __declspec( dllexport ) +#else +#define SMDS_WNT_EXPORT +#endif + +// ========================================================================= +// +// Class providing topological and other information about SMDS_MeshVolume: +// allows iteration on faces or, to be precise, on nodes of volume sides; +// provides info on nodes connection etc. +// +// ========================================================================= + +class SMDS_WNT_EXPORT SMDS_VolumeTool +{ + public: + + enum VolumeType { UNKNOWN = -1, TETRA = 0, PYRAM, PENTA, HEXA, POLYHEDA }; + + SMDS_VolumeTool (); + ~SMDS_VolumeTool (); + SMDS_VolumeTool (const SMDS_MeshElement* theVolume); + + bool Set (const SMDS_MeshElement* theVolume); + // Set volume. + // Return false if theVolume is not of type SMDSAbs_Volume + + // ----------------------- + // general info + // ----------------------- + + VolumeType GetVolumeType() const; + + bool IsForward() const { return myVolForward; } + // Check volume orientation. can be changed by Inverse(). + // See node order of forward volumes at the file bottom + + void Inverse(); + // Change nodes order as if the volume changes its orientation: + // top and bottom faces are reversed. + // Result of IsForward() and methods returning nodes change + + const SMDS_MeshNode** GetNodes() { return myVolumeNodes; } + // Return array of volume nodes + + int NbNodes() { return myVolumeNbNodes; } + // Return array of volume nodes + + double GetSize() const; + // Return element volume + + bool GetBaryCenter (double & X, double & Y, double & Z) const; + + + // ----------------------- + // info on node connection + // ----------------------- + + bool IsLinked (const SMDS_MeshNode* theNode1, + const SMDS_MeshNode* theNode2) const; + // Return true if theNode1 is linked with theNode2. + + bool IsLinked (const int theNode1Index, + const int theNode2Index) const; + // Return true if the node with theNode1Index is linked + // with the node with theNode2Index + + int GetNodeIndex(const SMDS_MeshNode* theNode) const; + // Return an index of theNode + + // ------------- + // info on faces + // ------------- + + void SetExternalNormal (); + // Node order in faces will be so that faces normals are external. + + int NbFaces() const { return myNbFaces; } + // Return number of faces of the volume. In the following + // methods 0 <= faceIndex < NbFaces() + + int NbFaceNodes( int faceIndex ); + // Return number of nodes in the array of face nodes + + const int* GetFaceNodesIndices( int faceIndex ); + // Return the array of face nodes indices + // To comfort link iteration, the array + // length == NbFaceNodes( faceIndex ) + 1 and + // the last node index == the first one. + + const SMDS_MeshNode** GetFaceNodes( int faceIndex ); + // Return the array of face nodes. + // To comfort link iteration, the array + // length == NbFaceNodes( faceIndex ) + 1 and + // the last node == the first one. + // WARNING: do not modify the array, some methods + // work basing on its contents + + bool GetFaceNodes (int faceIndex, + std::set& theFaceNodes ); + // Return a set of face nodes. + + bool IsFaceExternal( int faceIndex ); + // Check normal orientation of a face. + // SetExternalNormal() is taken into account. + + bool IsFreeFace( int faceIndex ); + // Check that all volumes built on the face nodes lays on one side + + bool GetFaceNormal (int faceIndex, double & X, double & Y, double & Z); + // Return a normal to a face + + double GetFaceArea( int faceIndex ); + // Return face area + + int GetOppFaceIndex( int faceIndex ) const; + // Return index of the opposite face if it exists, else -1. + + int GetFaceIndex( const std::set& theFaceNodes ); + // Return index of a face formed by theFaceNodes. + // Return -1 if a face not found + + //int GetFaceIndex( const std::set& theFaceNodesIndices ); + // Return index of a face formed by theFaceNodesIndices + // Return -1 if a face not found + + // ------------------------ + // static methods for faces + // ------------------------ + + static VolumeType GetType(int nbNodes); + // return VolumeType by nb of nodes in a volume + + static int NbFaces( VolumeType type ); + // return nb of faces by volume type + + static const int* GetFaceNodesIndices(VolumeType type, + int faceIndex, + bool external); + // Return the array of face nodes indices + // To comfort link iteration, the array + // length == NbFaceNodes( faceIndex ) + 1 and + // the last node index == the first one. + + static int NbFaceNodes(VolumeType type, + int faceIndex ); + // Return number of nodes in the array of face nodes + + private: + + bool setFace( int faceIndex ); + + const SMDS_MeshElement* myVolume; + const SMDS_PolyhedralVolumeOfNodes* myPolyedre; + + bool myVolForward; + int myNbFaces; + int myVolumeNbNodes; + const SMDS_MeshNode** myVolumeNodes; + + bool myExternalFaces; + + int myCurFace; + int myFaceNbNodes; + int* myFaceNodeIndices; + const SMDS_MeshNode** myFaceNodes; + +}; +#endif + + +/////////////////////////////////////////////////////////////////////////// +// +// ORDER OF NODES OF FORWARD ELEMENT +// +/////////////////////////////////////////////////////////////////////////// +/* +// N3 +// + +// /|\ +// / | \ +// / | \ +// N0 +---|---+ N1 TETRAHEDRON +// \ | / +// \ | / +// \ | / +// \|/ +// + +// N2 + +// + N4 +// /|\ +// / | \ +// / | \ +// / | \ +// N3 +---------+ N5 +// | | | +// | + N1 | +// | / \ | PENTAHEDRON +// | / \ | +// | / \ | +// |/ \| +// N0 +---------+ N2 + +// N5+----------+N6 +// /| /| +// / | / | +// / | / | +// N4+----------+N7 | +// | | | | HEXAHEDRON +// | | | | +// | | | | +// | N1+------|---+N2 +// | / | / +// | / | / +// |/ |/ +// N0+----------+N3 +// +*/ diff --git a/src/SMESH/SMESH_Mesh.cxx b/src/SMESH/SMESH_Mesh.cxx new file mode 100644 index 000000000..ffd77cd55 --- /dev/null +++ b/src/SMESH/SMESH_Mesh.cxx @@ -0,0 +1,1430 @@ +// SMESH SMESH : implementaion of SMESH idl descriptions +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESH_Mesh.cxx +// Author : Paul RASCLE, EDF +// Module : SMESH +// $Header$ + +#include "SMESH_Mesh.hxx" +#include "SMESH_subMesh.hxx" +#include "SMESH_Gen.hxx" +#include "SMESH_Hypothesis.hxx" +#include "SMESH_Group.hxx" +#include "SMESH_HypoFilter.hxx" +#include "SMESHDS_Group.hxx" +#include "SMESHDS_Script.hxx" +#include "SMESHDS_GroupOnGeom.hxx" +#include "SMDS_MeshVolume.hxx" + +#include "utilities.h" + +#include "DriverMED_W_SMESHDS_Mesh.h" +#include "DriverDAT_W_SMDS_Mesh.h" +#include "DriverUNV_W_SMDS_Mesh.h" +#include "DriverSTL_W_SMDS_Mesh.h" + +#include "DriverMED_R_SMESHDS_Mesh.h" +#include "DriverUNV_R_SMDS_Mesh.h" +#include "DriverSTL_R_SMDS_Mesh.h" + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include "Utils_ExceptHandlers.hxx" + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESH_Mesh::SMESH_Mesh(int localId, int studyId, SMESH_Gen * gen, SMESHDS_Document * myDocument) +: _groupId( 0 ) +{ + INFOS("SMESH_Mesh::SMESH_Mesh(int localId)"); + _id = localId; + _studyId = studyId; + _gen = gen; + _myDocument = myDocument; + _idDoc = _myDocument->NewMesh(); + _myMeshDS = _myDocument->GetMesh(_idDoc); + _isShapeToMesh = false; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESH_Mesh::~SMESH_Mesh() +{ + INFOS("SMESH_Mesh::~SMESH_Mesh"); + + // delete groups + map < int, SMESH_Group * >::iterator itg; + for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) { + SMESH_Group *aGroup = (*itg).second; + delete aGroup; + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape) +{ + if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh"); + + if ( !_myMeshDS->ShapeToMesh().IsNull() && aShape.IsNull() ) + { + // removal of a shape to mesh, delete objects referring to sub-shapes: + // - sub-meshes + map ::iterator i_sm = _mapSubMesh.begin(); + for ( ; i_sm != _mapSubMesh.end(); ++i_sm ) + delete i_sm->second; + _mapSubMesh.clear(); + // - groups on geometry + map ::iterator i_gr = _mapGroup.begin(); + while ( i_gr != _mapGroup.end() ) { + if ( dynamic_cast( i_gr->second->GetGroupDS() )) { + _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() ); + delete i_gr->second; + _mapGroup.erase( i_gr++ ); + } + else + i_gr++; + } + _mapPropagationChains.Clear(); + } + else + { + if (_isShapeToMesh) + throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined")); + } + _isShapeToMesh = true; + _myMeshDS->ShapeToMesh(aShape); + + // fill _mapAncestors + _mapAncestors.Clear(); + int desType, ancType; + for ( desType = TopAbs_EDGE; desType > TopAbs_COMPOUND; desType-- ) + for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- ) + TopExp::MapShapesAndAncestors ( aShape, + (TopAbs_ShapeEnum) desType, + (TopAbs_ShapeEnum) ancType, + _mapAncestors ); + + // NRI : 24/02/03 + //EAP: 1/9/04 TopExp::MapShapes(aShape, _subShapes); USE the same map of _myMeshDS +} + +//======================================================================= +//function : UNVToMesh +//purpose : +//======================================================================= + +int SMESH_Mesh::UNVToMesh(const char* theFileName) +{ + if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<NbNodes() = "<<_myMeshDS->NbNodes()); + MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges()); + MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces()); + MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes()); + } + return 1; +} + +//======================================================================= +//function : MEDToMesh +//purpose : +//======================================================================= + +int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName) +{ + if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<NbNodes() = "<<_myMeshDS->NbNodes()); + MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges()); + MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces()); + MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes()); + } + + // Reading groups (sub-meshes are out of scope of MED import functionality) + list aGroupNames = myReader.GetGroupNamesAndTypes(); + if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<::iterator name_type = aGroupNames.begin(); + for ( ; name_type != aGroupNames.end(); name_type++ ) { + SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId ); + if ( aGroup ) { + if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<first.c_str()); + SMESHDS_Group* aGroupDS = dynamic_cast( aGroup->GetGroupDS() ); + if ( aGroupDS ) { + aGroupDS->SetStoreName( name_type->first.c_str() ); + myReader.GetGroup( aGroupDS ); + } + } + } + return (int) status; +} + +//======================================================================= +//function : STLToMesh +//purpose : +//======================================================================= + +int SMESH_Mesh::STLToMesh(const char* theFileName) +{ + if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<NbNodes() = "<<_myMeshDS->NbNodes()); + MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges()); + MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces()); + MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes()); + } + return 1; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESH_Hypothesis::Hypothesis_Status + SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape, + int anHypId ) throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis"); + + SMESH_subMesh *subMesh = GetSubMesh(aSubShape); + SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS(); + if ( subMeshDS && subMeshDS->IsComplexSubmesh() ) // group of sub-shapes and maybe of not sub- + { + MESSAGE("AddHypothesis() to complex submesh"); + // return the worst but not fatal state of all group memebers + SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret; + aBestRet = SMESH_Hypothesis::HYP_BAD_DIM; + aWorstNotFatal = SMESH_Hypothesis::HYP_OK; + for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next()) + { + if ( !GetMeshDS()->ShapeToIndex( itS.Value() )) + continue; // not sub-shape + ret = AddHypothesis( itS.Value(), anHypId ); + if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal ) + aWorstNotFatal = ret; + if ( ret < aBestRet ) + aBestRet = ret; + } + if ( SMESH_Hypothesis::IsStatusFatal( aBestRet )) + return aBestRet; + return aWorstNotFatal; + } + + StudyContextStruct *sc = _gen->GetStudyContext(_studyId); + if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end()) + { + if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis"); + if(MYDEBUG) { + SCRUTE(_studyId); + SCRUTE(anHypId); + } + throw SALOME_Exception(LOCALIZED("hypothesis does not exist")); + } + + SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId]; + MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() ); + + bool isGlobalHyp = IsMainShape( aSubShape ); + + // NotConformAllowed can be only global + if ( !isGlobalHyp ) + { + string hypName = anHyp->GetName(); + if ( hypName == "NotConformAllowed" ) + { + if(MYDEBUG) MESSAGE( "Hypotesis can be only global" ); + return SMESH_Hypothesis::HYP_INCOMPATIBLE; + } + } + + // shape + + int event; + if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO) + event = SMESH_subMesh::ADD_HYP; + else + event = SMESH_subMesh::ADD_ALGO; + SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp); + + // subShapes + if (!SMESH_Hypothesis::IsStatusFatal(ret) && + !subMesh->IsApplicableHypotesis( anHyp )) // is added on father + { + if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO) + event = SMESH_subMesh::ADD_FATHER_HYP; + else + event = SMESH_subMesh::ADD_FATHER_ALGO; + SMESH_Hypothesis::Hypothesis_Status ret2 = + subMesh->SubMeshesAlgoStateEngine(event, anHyp); + if (ret2 > ret) + ret = ret2; + + // check concurent hypotheses on ansestors + if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp ) + { + const map < int, SMESH_subMesh * >& smMap = subMesh->DependsOn(); + map < int, SMESH_subMesh * >::const_iterator smIt = smMap.begin(); + for ( ; smIt != smMap.end(); smIt++ ) { + if ( smIt->second->IsApplicableHypotesis( anHyp )) { + ret2 = smIt->second->CheckConcurentHypothesis( anHyp->GetType() ); + if (ret2 > ret) { + ret = ret2; + break; + } + } + } + } + } + + if(MYDEBUG) subMesh->DumpAlgoState(true); + SCRUTE(ret); + return ret; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESH_Hypothesis::Hypothesis_Status + SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape, + int anHypId)throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis"); + + SMESH_subMesh *subMesh = GetSubMesh(aSubShape); + SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS(); + if ( subMeshDS && subMeshDS->IsComplexSubmesh() ) + { + // return the worst but not fatal state of all group memebers + SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret; + aBestRet = SMESH_Hypothesis::HYP_BAD_DIM; + aWorstNotFatal = SMESH_Hypothesis::HYP_OK; + for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next()) + { + if ( !GetMeshDS()->ShapeToIndex( itS.Value() )) + continue; // not sub-shape + ret = RemoveHypothesis( itS.Value(), anHypId ); + if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal ) + aWorstNotFatal = ret; + if ( ret < aBestRet ) + aBestRet = ret; + } + if ( SMESH_Hypothesis::IsStatusFatal( aBestRet )) + return aBestRet; + return aWorstNotFatal; + } + + StudyContextStruct *sc = _gen->GetStudyContext(_studyId); + if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end()) + throw SALOME_Exception(LOCALIZED("hypothesis does not exist")); + + SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId]; + int hypType = anHyp->GetType(); + if(MYDEBUG) SCRUTE(hypType); + int event; + + // shape + + if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO) + event = SMESH_subMesh::REMOVE_HYP; + else + event = SMESH_subMesh::REMOVE_ALGO; + SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp); + + // there may appear concurrent hyps that were covered by the removed hyp + if (ret < SMESH_Hypothesis::HYP_CONCURENT && + subMesh->IsApplicableHypotesis( anHyp ) && + subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK) + ret = SMESH_Hypothesis::HYP_CONCURENT; + + // subShapes + if (!SMESH_Hypothesis::IsStatusFatal(ret) && + !subMesh->IsApplicableHypotesis( anHyp )) // is removed from father + { + if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO) + event = SMESH_subMesh::REMOVE_FATHER_HYP; + else + event = SMESH_subMesh::REMOVE_FATHER_ALGO; + SMESH_Hypothesis::Hypothesis_Status ret2 = + subMesh->SubMeshesAlgoStateEngine(event, anHyp); + if (ret2 > ret) // more severe + ret = ret2; + + // check concurent hypotheses on ansestors + if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) ) + { + const map < int, SMESH_subMesh * >& smMap = subMesh->DependsOn(); + map < int, SMESH_subMesh * >::const_iterator smIt = smMap.begin(); + for ( ; smIt != smMap.end(); smIt++ ) { + if ( smIt->second->IsApplicableHypotesis( anHyp )) { + ret2 = smIt->second->CheckConcurentHypothesis( anHyp->GetType() ); + if (ret2 > ret) { + ret = ret2; + break; + } + } + } + } + } + + if(MYDEBUG) subMesh->DumpAlgoState(true); + if(MYDEBUG) SCRUTE(ret); + return ret; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESHDS_Mesh * SMESH_Mesh::GetMeshDS() +{ + return _myMeshDS; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +const list& +SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const + throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + return _myMeshDS->GetHypothesis(aSubShape); +} + +//======================================================================= +//function : GetHypothesis +//purpose : +//======================================================================= + +const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape, + const SMESH_HypoFilter& aFilter, + const bool andAncestors) const +{ + { + const list& hypList = _myMeshDS->GetHypothesis(aSubShape); + list::const_iterator hyp = hypList.begin(); + for ( ; hyp != hypList.end(); hyp++ ) { + const SMESH_Hypothesis * h = static_cast( *hyp ); + if ( aFilter.IsOk( h, aSubShape)) + return h; + } + } + if ( andAncestors ) + { + TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape )); + for (; it.More(); it.Next() ) + { + const list& hypList = _myMeshDS->GetHypothesis(it.Value()); + list::const_iterator hyp = hypList.begin(); + for ( ; hyp != hypList.end(); hyp++ ) { + const SMESH_Hypothesis * h = static_cast( *hyp ); + if (aFilter.IsOk( h, it.Value() )) + return h; + } + } + } + return 0; +} + +//======================================================================= +//function : GetHypotheses +//purpose : +//======================================================================= + +bool SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape, + const SMESH_HypoFilter& aFilter, + list & aHypList, + const bool andAncestors) const +{ + int nbHyp = 0; + { + const list& hypList = _myMeshDS->GetHypothesis(aSubShape); + list::const_iterator hyp = hypList.begin(); + for ( ; hyp != hypList.end(); hyp++ ) + if ( aFilter.IsOk (static_cast( *hyp ), aSubShape)) { + aHypList.push_back( *hyp ); + nbHyp++; + } + } + // get hypos from shape of one type only: if any hypo is found on edge, do + // not look up on faces + if ( !nbHyp && andAncestors ) + { + TopTools_MapOfShape map; + TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape )); + int shapeType = it.More() ? it.Value().ShapeType() : TopAbs_SHAPE; + for (; it.More(); it.Next() ) + { + if ( nbHyp && shapeType != it.Value().ShapeType() ) + break; + shapeType = it.Value().ShapeType(); + if ( !map.Add( it.Value() )) + continue; + const list& hypList = _myMeshDS->GetHypothesis(it.Value()); + list::const_iterator hyp = hypList.begin(); + for ( ; hyp != hypList.end(); hyp++ ) + if (aFilter.IsOk( static_cast( *hyp ), it.Value() )) { + aHypList.push_back( *hyp ); + nbHyp++; + } + } + } + return nbHyp; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +const list & SMESH_Mesh::GetLog() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog"); + return _myMeshDS->GetScript()->GetCommands(); +} + +//============================================================================= +/*! + * + */ +//============================================================================= +void SMESH_Mesh::ClearLog() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog"); + _myMeshDS->GetScript()->Clear(); +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +int SMESH_Mesh::GetId() +{ + if(MYDEBUG) MESSAGE("SMESH_Mesh::GetId"); + return _id; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESH_Gen *SMESH_Mesh::GetGen() +{ + return _gen; +} + +//============================================================================= +/*! + * Get or Create the SMESH_subMesh object implementation + */ +//============================================================================= + +SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape) +throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + SMESH_subMesh *aSubMesh; + int index = _myMeshDS->ShapeToIndex(aSubShape); + + // for submeshes on GEOM Group + if ( !index && aSubShape.ShapeType() == TopAbs_COMPOUND ) { + TopoDS_Iterator it( aSubShape ); + if ( it.More() ) + index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() ); + } + + if (_mapSubMesh.find(index) != _mapSubMesh.end()) + { + aSubMesh = _mapSubMesh[index]; + } + else + { + aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape); + _mapSubMesh[index] = aSubMesh; + } + return aSubMesh; +} + +//============================================================================= +/*! + * Get the SMESH_subMesh object implementation. Dont create it, return null + * if it does not exist. + */ +//============================================================================= + +SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) +throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + bool isFound = false; + SMESH_subMesh *aSubMesh = NULL; + + int index = _myMeshDS->ShapeToIndex(aSubShape); + if (_mapSubMesh.find(index) != _mapSubMesh.end()) + { + aSubMesh = _mapSubMesh[index]; + isFound = true; + } + if (!isFound) + aSubMesh = NULL; + return aSubMesh; +} + +//============================================================================= +/*! + * Get the SMESH_subMesh object implementation. Dont create it, return null + * if it does not exist. + */ +//============================================================================= + +SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) +throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + + map ::iterator i_sm = _mapSubMesh.find(aShapeID); + if (i_sm == _mapSubMesh.end()) + return NULL; + return i_sm->second; +} + +//======================================================================= +//function : IsUsedHypothesis +//purpose : Return True if anHyp is used to mesh aSubShape +//======================================================================= + +bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp, + const TopoDS_Shape & aSubShape) +{ + SMESH_Hypothesis* hyp = static_cast(anHyp); + // check if anHyp is applicable to aSubShape + SMESH_subMesh * subMesh = GetSubMeshContaining( aSubShape ); + if ( !subMesh || !subMesh->IsApplicableHypotesis( hyp )) + return false; + + SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape); + + // algorithm + if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO) + return ( anHyp == algo ); + + // algorithm parameter + if (algo) + { + // look trough hypotheses used by algo + const list &usedHyps = + algo->GetUsedHypothesis(*this, aSubShape); + return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() ); + } + + // look through all assigned hypotheses + SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp )); + return GetHypothesis( aSubShape, filter, true ); +} + + +//============================================================================= +/*! + * + */ +//============================================================================= + +const list < SMESH_subMesh * >& + SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp) +throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis"); + map < int, SMESH_subMesh * >::iterator itsm; + _subMeshesUsingHypothesisList.clear(); + for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++) + { + SMESH_subMesh *aSubMesh = (*itsm).second; + if ( IsUsedHypothesis ( anHyp, aSubMesh->GetSubShape() )) + _subMeshesUsingHypothesisList.push_back(aSubMesh); + } + return _subMeshesUsingHypothesisList; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +void SMESH_Mesh::ExportMED(const char *file, + const char* theMeshName, + bool theAutoGroups, + int theVersion) + throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + DriverMED_W_SMESHDS_Mesh myWriter; + myWriter.SetFile ( file, MED::EVersion(theVersion) ); + myWriter.SetMesh ( _myMeshDS ); + if ( !theMeshName ) + myWriter.SetMeshId ( _idDoc ); + else { + myWriter.SetMeshId ( -1 ); + myWriter.SetMeshName( theMeshName ); + } + + if ( theAutoGroups ) { + myWriter.AddGroupOfNodes(); + myWriter.AddGroupOfEdges(); + myWriter.AddGroupOfFaces(); + myWriter.AddGroupOfVolumes(); + } + + for ( map::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) { + SMESH_Group* aGroup = it->second; + SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS(); + if ( aGroupDS ) { + aGroupDS->SetStoreName( aGroup->GetName() ); + myWriter.AddGroup( aGroupDS ); + } + } + + myWriter.Perform(); +} + +void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + DriverDAT_W_SMDS_Mesh myWriter; + myWriter.SetFile(string(file)); + myWriter.SetMesh(_myMeshDS); + myWriter.SetMeshId(_idDoc); + myWriter.Perform(); +} + +void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + DriverUNV_W_SMDS_Mesh myWriter; + myWriter.SetFile(string(file)); + myWriter.SetMesh(_myMeshDS); + myWriter.SetMeshId(_idDoc); + myWriter.Perform(); +} + +void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + DriverSTL_W_SMDS_Mesh myWriter; + myWriter.SetFile(string(file)); + myWriter.SetIsAscii( isascii ); + myWriter.SetMesh(_myMeshDS); + myWriter.SetMeshId(_idDoc); + myWriter.Perform(); +} + +//============================================================================= +/*! + * + */ +//============================================================================= +int SMESH_Mesh::NbNodes() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + return _myMeshDS->NbNodes(); +} + +//============================================================================= +/*! + * + */ +//============================================================================= +int SMESH_Mesh::NbEdges() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + return _myMeshDS->NbEdges(); +} + +//============================================================================= +/*! + * + */ +//============================================================================= +int SMESH_Mesh::NbFaces() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + return _myMeshDS->NbFaces(); +} + +/////////////////////////////////////////////////////////////////////////////// +/// Return the number of 3 nodes faces in the mesh. This method run in O(n) +/////////////////////////////////////////////////////////////////////////////// +int SMESH_Mesh::NbTriangles() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + int Nb = 0; + + SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator(); + //while(itFaces->more()) if(itFaces->next()->NbNodes()==3) Nb++; + const SMDS_MeshFace * curFace; + while (itFaces->more()) { + curFace = itFaces->next(); + if (!curFace->IsPoly() && curFace->NbNodes() == 3) Nb++; + } + return Nb; +} + +/////////////////////////////////////////////////////////////////////////////// +/// Return the number of 4 nodes faces in the mesh. This method run in O(n) +/////////////////////////////////////////////////////////////////////////////// +int SMESH_Mesh::NbQuadrangles() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + int Nb = 0; + + SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator(); + //while(itFaces->more()) if(itFaces->next()->NbNodes()==4) Nb++; + const SMDS_MeshFace * curFace; + while (itFaces->more()) { + curFace = itFaces->next(); + if (!curFace->IsPoly() && curFace->NbNodes() == 4) Nb++; + } + return Nb; +} + +/////////////////////////////////////////////////////////////////////////////// +/// Return the number of polygonal faces in the mesh. This method run in O(n) +/////////////////////////////////////////////////////////////////////////////// +int SMESH_Mesh::NbPolygons() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + int Nb = 0; + SMDS_FaceIteratorPtr itFaces = _myMeshDS->facesIterator(); + while (itFaces->more()) + if (itFaces->next()->IsPoly()) Nb++; + return Nb; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +int SMESH_Mesh::NbVolumes() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + return _myMeshDS->NbVolumes(); +} + +int SMESH_Mesh::NbTetras() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + int Nb = 0; + SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator(); + //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==4) Nb++; + const SMDS_MeshVolume * curVolume; + while (itVolumes->more()) { + curVolume = itVolumes->next(); + if (!curVolume->IsPoly() && curVolume->NbNodes() == 4) Nb++; + } + return Nb; +} + +int SMESH_Mesh::NbHexas() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + int Nb = 0; + SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator(); + //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==8) Nb++; + const SMDS_MeshVolume * curVolume; + while (itVolumes->more()) { + curVolume = itVolumes->next(); + if (!curVolume->IsPoly() && curVolume->NbNodes() == 8) Nb++; + } + return Nb; +} + +int SMESH_Mesh::NbPyramids() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + int Nb = 0; + SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator(); + //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==5) Nb++; + const SMDS_MeshVolume * curVolume; + while (itVolumes->more()) { + curVolume = itVolumes->next(); + if (!curVolume->IsPoly() && curVolume->NbNodes() == 5) Nb++; + } + return Nb; +} + +int SMESH_Mesh::NbPrisms() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + int Nb = 0; + SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator(); + //while(itVolumes->more()) if(itVolumes->next()->NbNodes()==6) Nb++; + const SMDS_MeshVolume * curVolume; + while (itVolumes->more()) { + curVolume = itVolumes->next(); + if (!curVolume->IsPoly() && curVolume->NbNodes() == 6) Nb++; + } + return Nb; +} + +int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + int Nb = 0; + SMDS_VolumeIteratorPtr itVolumes = _myMeshDS->volumesIterator(); + while (itVolumes->more()) + if (itVolumes->next()->IsPoly()) Nb++; + return Nb; +} + +//============================================================================= +/*! + * + */ +//============================================================================= +int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception) +{ + Unexpect aCatch(SalomeException); + return _myMeshDS->NbSubMesh(); +} + +//======================================================================= +//function : IsNotConformAllowed +//purpose : check if a hypothesis alowing notconform mesh is present +//======================================================================= + +bool SMESH_Mesh::IsNotConformAllowed() const +{ + if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed"); + + SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" )); + return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false ); +} + +//======================================================================= +//function : IsMainShape +//purpose : +//======================================================================= + +bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const +{ + return theShape.IsSame(_myMeshDS->ShapeToMesh() ); +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType, + const char* theName, + int& theId, + const TopoDS_Shape& theShape) +{ + if (_mapGroup.find(_groupId) != _mapGroup.end()) + return NULL; + theId = _groupId; + SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape); + GetMeshDS()->AddGroup( aGroup->GetGroupDS() ); + _mapGroup[_groupId++] = aGroup; + return aGroup; +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID) +{ + if (_mapGroup.find(theGroupID) == _mapGroup.end()) + return NULL; + return _mapGroup[theGroupID]; +} + + +//============================================================================= +/*! + * + */ +//============================================================================= + +list SMESH_Mesh::GetGroupIds() +{ + list anIds; + for ( map::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) + anIds.push_back( it->first ); + + return anIds; +} + + +//============================================================================= +/*! + * + */ +//============================================================================= + +void SMESH_Mesh::RemoveGroup (const int theGroupID) +{ + if (_mapGroup.find(theGroupID) == _mapGroup.end()) + return; + GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() ); + _mapGroup.erase (theGroupID); + delete _mapGroup[theGroupID]; +} + +//============================================================================= +/*! + * IsLocal1DHypothesis + * Returns a local 1D hypothesis used for theEdge + */ +//============================================================================= +const SMESH_Hypothesis* SMESH_Mesh::IsLocal1DHypothesis (const TopoDS_Shape& theEdge) +{ + SMESH_HypoFilter hypo ( SMESH_HypoFilter::HasDim( 1 )); + hypo.AndNot( hypo.IsAlgo() ).AndNot( hypo.IsAssignedTo( GetMeshDS()->ShapeToMesh() )); + + return GetHypothesis( theEdge, hypo, true ); +} + +//============================================================================= +/*! + * IsPropagationHypothesis + */ +//============================================================================= +bool SMESH_Mesh::IsPropagationHypothesis (const TopoDS_Shape& theEdge) +{ + return _mapPropagationChains.Contains(theEdge); +} + +//============================================================================= +/*! + * IsPropagatedHypothesis + */ +//============================================================================= +bool SMESH_Mesh::IsPropagatedHypothesis (const TopoDS_Shape& theEdge, + TopoDS_Shape& theMainEdge) +{ + int nbChains = _mapPropagationChains.Extent(); + for (int i = 1; i <= nbChains; i++) { + //const TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i); + const SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i); + if (aChain.Contains(theEdge)) { + theMainEdge = _mapPropagationChains.FindKey(i); + return true; + } + } + + return false; +} +//============================================================================= +/*! + * IsReversedInChain + */ +//============================================================================= + +bool SMESH_Mesh::IsReversedInChain (const TopoDS_Shape& theEdge, + const TopoDS_Shape& theMainEdge) +{ + if ( !theMainEdge.IsNull() && !theEdge.IsNull() && + _mapPropagationChains.Contains( theMainEdge )) + { + const SMESH_IndexedMapOfShape& aChain = + _mapPropagationChains.FindFromKey( theMainEdge ); + int index = aChain.FindIndex( theEdge ); + if ( index ) + return aChain(index).Orientation() == TopAbs_REVERSED; + } + return false; +} + +//============================================================================= +/*! + * CleanMeshOnPropagationChain + */ +//============================================================================= +void SMESH_Mesh::CleanMeshOnPropagationChain (const TopoDS_Shape& theMainEdge) +{ + const SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromKey(theMainEdge); + int i, nbEdges = aChain.Extent(); + for (i = 1; i <= nbEdges; i++) { + TopoDS_Shape anEdge = aChain.FindKey(i); + SMESH_subMesh *subMesh = GetSubMesh(anEdge); + SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS(); + if (subMeshDS && subMeshDS->NbElements() > 0) { + subMesh->ComputeStateEngine(SMESH_subMesh::CLEANDEP); + } + } +} + +//============================================================================= +/*! + * RebuildPropagationChains + * Rebuild all existing propagation chains. + * Have to be used, if 1D hypothesis have been assigned/removed to/from any edge + */ +//============================================================================= +bool SMESH_Mesh::RebuildPropagationChains() +{ + bool ret = true; + + // Clean all chains, because they can be not up-to-date + int i, nbChains = _mapPropagationChains.Extent(); + for (i = 1; i <= nbChains; i++) { + TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i); + CleanMeshOnPropagationChain(aMainEdge); + _mapPropagationChains.ChangeFromIndex(i).Clear(); + } + + // Build all chains + for (i = 1; i <= nbChains; i++) { + TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i); + if (!BuildPropagationChain(aMainEdge)) + ret = false; + CleanMeshOnPropagationChain(aMainEdge); + } + + return ret; +} + +//============================================================================= +/*! + * RemovePropagationChain + * Have to be used, if Propagation hypothesis is removed from + */ +//============================================================================= +bool SMESH_Mesh::RemovePropagationChain (const TopoDS_Shape& theMainEdge) +{ + if (!_mapPropagationChains.Contains(theMainEdge)) + return false; + + // Clean mesh elements and nodes, built on the chain + CleanMeshOnPropagationChain(theMainEdge); + + // Clean the chain + _mapPropagationChains.ChangeFromKey(theMainEdge).Clear(); + + // Remove the chain from the map + int i = _mapPropagationChains.FindIndex(theMainEdge); + if ( i == _mapPropagationChains.Extent() ) + _mapPropagationChains.RemoveLast(); + else { + TopoDS_Vertex anEmptyShape; + BRep_Builder BB; + BB.MakeVertex(anEmptyShape, gp_Pnt(0,0,0), 0.1); + SMESH_IndexedMapOfShape anEmptyMap; + _mapPropagationChains.Substitute(i, anEmptyShape, anEmptyMap); + } + + return true; +} + +//============================================================================= +/*! + * BuildPropagationChain + */ +//============================================================================= +bool SMESH_Mesh::BuildPropagationChain (const TopoDS_Shape& theMainEdge) +{ + if (theMainEdge.ShapeType() != TopAbs_EDGE) return true; + + // Add new chain, if there is no + if (!_mapPropagationChains.Contains(theMainEdge)) { + SMESH_IndexedMapOfShape aNewChain; + _mapPropagationChains.Add(theMainEdge, aNewChain); + } + + // Check presence of 1D hypothesis to be propagated + const SMESH_Hypothesis* aMainHyp = IsLocal1DHypothesis(theMainEdge); + if (!aMainHyp) { + MESSAGE("Warning: There is no 1D hypothesis to propagate. Please, assign."); + return true; + } + + // Edges, on which the 1D hypothesis will be propagated from + SMESH_IndexedMapOfShape& aChain = _mapPropagationChains.ChangeFromKey(theMainEdge); + if (aChain.Extent() > 0) { + CleanMeshOnPropagationChain(theMainEdge); + aChain.Clear(); + } + + // At first put in the chain + aChain.Add(theMainEdge); + + // List of edges, added to chain on the previous cycle pass + TopTools_ListOfShape listPrevEdges; + listPrevEdges.Append(theMainEdge.Oriented( TopAbs_FORWARD )); + +// 5____4____3____4____5____6 +// | | | | | | +// | | | | | | +// 4____3____2____3____4____5 +// | | | | | | Number in the each knot of +// | | | | | | grid indicates cycle pass, +// 3____2____1____2____3____4 on which corresponding edge +// | | | | | | (perpendicular to the plane +// | | | | | | of view) will be found. +// 2____1____0____1____2____3 +// | | | | | | +// | | | | | | +// 3____2____1____2____3____4 + + // Collect all edges pass by pass + while (listPrevEdges.Extent() > 0) { + // List of edges, added to chain on this cycle pass + TopTools_ListOfShape listCurEdges; + + // Find the next portion of edges + TopTools_ListIteratorOfListOfShape itE (listPrevEdges); + for (; itE.More(); itE.Next()) { + TopoDS_Shape anE = itE.Value(); + + // Iterate on faces, having edge + TopTools_ListIteratorOfListOfShape itA (GetAncestors(anE)); + for (; itA.More(); itA.Next()) { + TopoDS_Shape aW = itA.Value(); + + // There are objects of different type among the ancestors of edge + if (aW.ShapeType() == TopAbs_WIRE) { + TopoDS_Shape anOppE; + + BRepTools_WireExplorer aWE (TopoDS::Wire(aW)); + Standard_Integer nb = 1, found = 0; + TopTools_Array1OfShape anEdges (1,4); + for (; aWE.More(); aWE.Next(), nb++) { + if (nb > 4) { + found = 0; + break; + } + anEdges(nb) = aWE.Current(); + if (!_mapAncestors.Contains(anEdges(nb))) { + MESSAGE("WIRE EXPLORER HAVE GIVEN AN INVALID EDGE !!!"); + break; + } + if (anEdges(nb).IsSame(anE)) found = nb; + } + + if (nb == 5 && found > 0) { + // Quadrangle face found, get an opposite edge + Standard_Integer opp = found + 2; + if (opp > 4) opp -= 4; + anOppE = anEdges(opp); + + // add anOppE to aChain if ... + if (!aChain.Contains(anOppE)) { // ... anOppE is not in aChain + if (!IsLocal1DHypothesis(anOppE)) { // ... no other 1d hyp on anOppE + TopoDS_Shape aMainEdgeForOppEdge; // ... no other hyp is propagated to anOppE + if (!IsPropagatedHypothesis(anOppE, aMainEdgeForOppEdge)) + { + // Add found edge to the chain oriented so that to + // have it co-directed with a forward MainEdge + TopAbs_Orientation ori = anE.Orientation(); + if ( anEdges(opp).Orientation() == anEdges(found).Orientation() ) + ori = TopAbs::Reverse( ori ); + anOppE.Orientation( ori ); + aChain.Add(anOppE); + listCurEdges.Append(anOppE); + } + else { + // Collision! + MESSAGE("Error: Collision between propagated hypotheses"); + CleanMeshOnPropagationChain(theMainEdge); + aChain.Clear(); + return ( aMainHyp == IsLocal1DHypothesis(aMainEdgeForOppEdge) ); + } + } + } + } // if (nb == 5 && found > 0) + } // if (aF.ShapeType() == TopAbs_WIRE) + } // for (; itF.More(); itF.Next()) + } // for (; itE.More(); itE.Next()) + + listPrevEdges = listCurEdges; + } // while (listPrevEdges.Extent() > 0) + + CleanMeshOnPropagationChain(theMainEdge); + return true; +} + +//======================================================================= +//function : GetAncestors +//purpose : return list of ancestors of theSubShape in the order +// that lower dimention shapes come first. +//======================================================================= + +const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const +{ + if ( _mapAncestors.Contains( theS ) ) + return _mapAncestors.FindFromKey( theS ); + + static TopTools_ListOfShape emptyList; + return emptyList; +} + +//======================================================================= +//function : Dump +//purpose : dumps contents of mesh to stream [ debug purposes ] +//======================================================================= +ostream& SMESH_Mesh::Dump(ostream& save) +{ + save << "========================== Dump contents of mesh ==========================" << endl; + save << "1) Total number of nodes: " << NbNodes() << endl; + save << "2) Total number of edges: " << NbEdges() << endl; + save << "3) Total number of faces: " << NbFaces() << endl; + if ( NbFaces() > 0 ) { + int nb3 = NbTriangles(); + int nb4 = NbQuadrangles(); + save << "3.1.) Number of triangles: " << nb3 << endl; + save << "3.2.) Number of quadrangles: " << nb4 << endl; + if ( nb3 + nb4 != NbFaces() ) { + map myFaceMap; + SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator(); + while( itFaces->more( ) ) { + int nbNodes = itFaces->next()->NbNodes(); + if ( myFaceMap.find( nbNodes ) == myFaceMap.end() ) + myFaceMap[ nbNodes ] = 0; + myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1; + } + save << "3.3.) Faces in detail: " << endl; + map ::iterator itF; + for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++) + save << "--> nb nodes: " << itF->first << " - nb elemens: " << itF->second << endl; + } + } + save << "4) Total number of volumes: " << NbVolumes() << endl; + if ( NbVolumes() > 0 ) { + int nb8 = NbHexas(); + int nb4 = NbTetras(); + int nb5 = NbPyramids(); + int nb6 = NbPrisms(); + save << "4.1.) Number of hexahedrons: " << nb8 << endl; + save << "4.2.) Number of tetrahedrons: " << nb4 << endl; + save << "4.3.) Number of prisms: " << nb6 << endl; + save << "4.4.) Number of pyramides: " << nb5 << endl; + if ( nb8 + nb4 + nb5 + nb6 != NbVolumes() ) { + map myVolumesMap; + SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator(); + while( itVolumes->more( ) ) { + int nbNodes = itVolumes->next()->NbNodes(); + if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() ) + myVolumesMap[ nbNodes ] = 0; + myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1; + } + save << "4.5.) Volumes in detail: " << endl; + map ::iterator itV; + for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++) + save << "--> nb nodes: " << itV->first << " - nb elemens: " << itV->second << endl; + } + } + save << "===========================================================================" << endl; + return save; +} + +//======================================================================= +//function : GetElementType +//purpose : Returns type of mesh element with certain id +//======================================================================= +SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem ) +{ + return _myMeshDS->GetElementType( id, iselem ); +} diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx new file mode 100644 index 000000000..5054e0038 --- /dev/null +++ b/src/SMESH/SMESH_Mesh.hxx @@ -0,0 +1,256 @@ +// SMESH SMESH : implementaion of SMESH idl descriptions +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESH_Mesh.hxx +// Author : Paul RASCLE, EDF +// Module : SMESH +// $Header$ + +#ifndef _SMESH_MESH_HXX_ +#define _SMESH_MESH_HXX_ + +#include "SMESH_Hypothesis.hxx" +//#include "SMESH_subMesh.hxx" + +#include "SMESHDS_Document.hxx" +#include "SMESHDS_Mesh.hxx" +#include "SMESHDS_Command.hxx" +#include "SMDSAbs_ElementType.hxx" + +//#include "NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx" +#include "SMESH_IndexedDataMapOfShapeIndexedMapOfShape.hxx" + +#include "Utils_SALOME_Exception.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +class SMESH_Gen; +class SMESH_Group; +class TopTools_ListOfShape; +class SMESH_subMesh; +class SMESH_HypoFilter; + +//typedef NMTTools_IndexedDataMapOfShapeIndexedMapOfShape IndexedMapOfChain; +typedef SMESH_IndexedDataMapOfShapeIndexedMapOfShape IndexedMapOfChain; + +class SMESH_Mesh +{ + SMESH_Mesh(); + SMESH_Mesh(const SMESH_Mesh&); +public: + SMESH_Mesh(int localId, int studyId, SMESH_Gen * gen, + SMESHDS_Document * myDocument); + + virtual ~SMESH_Mesh(); + + void ShapeToMesh(const TopoDS_Shape & aShape); + + int UNVToMesh(const char* theFileName); + /*! + * consult DriverMED_R_SMESHDS_Mesh::ReadStatus for returned value + */ + int MEDToMesh(const char* theFileName, const char* theMeshName); + + int STLToMesh(const char* theFileName); + + SMESH_Hypothesis::Hypothesis_Status + AddHypothesis(const TopoDS_Shape & aSubShape, int anHypId) + throw(SALOME_Exception); + + SMESH_Hypothesis::Hypothesis_Status + RemoveHypothesis(const TopoDS_Shape & aSubShape, int anHypId) + throw(SALOME_Exception); + + const list & + GetHypothesisList(const TopoDS_Shape & aSubShape) const + throw(SALOME_Exception); + + const SMESH_Hypothesis * GetHypothesis(const TopoDS_Shape & aSubShape, + const SMESH_HypoFilter& aFilter, + const bool andAncestors) const; + + bool GetHypotheses(const TopoDS_Shape & aSubShape, + const SMESH_HypoFilter& aFilter, + list & aHypList, + const bool andAncestors) const; + + const list & GetLog() throw(SALOME_Exception); + + void ClearLog() throw(SALOME_Exception); + + int GetId(); + + SMESHDS_Mesh * GetMeshDS(); + + SMESH_Gen *GetGen(); + + SMESH_subMesh *GetSubMesh(const TopoDS_Shape & aSubShape) + throw(SALOME_Exception); + + SMESH_subMesh *GetSubMeshContaining(const TopoDS_Shape & aSubShape) + throw(SALOME_Exception); + + SMESH_subMesh *GetSubMeshContaining(const int aShapeID) + throw(SALOME_Exception); + + const list < SMESH_subMesh * >& + GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp) + throw(SALOME_Exception); + + bool IsUsedHypothesis(SMESHDS_Hypothesis * anHyp, + const TopoDS_Shape & aSubShape); + // Return True if anHyp is used to mesh aSubShape + + bool IsNotConformAllowed() const; + // check if a hypothesis alowing notconform mesh is present + + bool IsMainShape(const TopoDS_Shape& theShape) const; + + const TopTools_ListOfShape& GetAncestors(const TopoDS_Shape& theSubShape) const; + // return list of ancestors of theSubShape in the order + // that lower dimention shapes come first. + + void ExportMED(const char *file, + const char* theMeshName = NULL, + bool theAutoGroups = true, + int theVersion = 0) + throw(SALOME_Exception); + + void ExportDAT(const char *file) throw(SALOME_Exception); + void ExportUNV(const char *file) throw(SALOME_Exception); + void ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception); + + int NbNodes() throw(SALOME_Exception); + + int NbEdges() throw(SALOME_Exception); + + int NbFaces() throw(SALOME_Exception); + + int NbTriangles() throw(SALOME_Exception); + + int NbQuadrangles() throw(SALOME_Exception); + + int NbPolygons() throw(SALOME_Exception); + + int NbVolumes() throw(SALOME_Exception); + + int NbTetras() throw(SALOME_Exception); + + int NbHexas() throw(SALOME_Exception); + + int NbPyramids() throw(SALOME_Exception); + + int NbPrisms() throw(SALOME_Exception); + + int NbPolyhedrons() throw(SALOME_Exception); + + int NbSubMesh() throw(SALOME_Exception); + + int NbGroup() const { return _mapGroup.size(); } + + SMESH_Group* AddGroup (const SMDSAbs_ElementType theType, + const char* theName, + int& theId, + const TopoDS_Shape& theShape=TopoDS_Shape()); + + SMESH_Group* GetGroup (const int theGroupID); + + list GetGroupIds(); + + void RemoveGroup (const int theGroupID); + + // Propagation hypothesis management + + const SMESH_Hypothesis* IsLocal1DHypothesis (const TopoDS_Shape& theEdge); + // Returns a local 1D hypothesis used for theEdge. + + bool IsPropagationHypothesis (const TopoDS_Shape& theEdge); + // Returns true, if a local Propagation hypothesis is set directly on + + bool IsPropagatedHypothesis (const TopoDS_Shape& theEdge, + TopoDS_Shape& theMainEdge); + // Returns true, if a local 1D hypothesis is + // propagated on from some other edge. + // Returns through the edge, from + // which the 1D hypothesis is propagated on + + bool IsReversedInChain (const TopoDS_Shape& theEdge, + const TopoDS_Shape& theMainEdge); + // Returns true if theEdge should be reversed to be + // co-directed with theMainEdge + + bool RebuildPropagationChains(); + bool RemovePropagationChain (const TopoDS_Shape& theMainEdge); + bool BuildPropagationChain (const TopoDS_Shape& theMainEdge); + + SMDSAbs_ElementType GetElementType( const int id, const bool iselem ); + + // + + ostream& Dump(ostream & save); + +private: + // Propagation hypothesis management + void CleanMeshOnPropagationChain(const TopoDS_Shape& theMainEdge); + // + +private: + int _id; // id given by creator (unique within the creator instance) + int _studyId; + int _idDoc; // id given by SMESHDS_Document + int _groupId; // id generator for group objects + bool _isShapeToMesh;// set to true when a shape is given (only once) + list _subMeshesUsingHypothesisList; + SMESHDS_Document * _myDocument; + SMESHDS_Mesh * _myMeshDS; + map _mapSubMesh; + map _mapGroup; + SMESH_Gen * _gen; + + TopTools_IndexedDataMapOfShapeListOfShape _mapAncestors; + + IndexedMapOfChain _mapPropagationChains; // Propagation hypothesis management +}; + +#endif diff --git a/src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx b/src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx new file mode 100644 index 000000000..a6e560ffa --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_FilterLibraryDlg.cxx @@ -0,0 +1,1133 @@ +// SMESH SMESHGUI : GUI for SMESH component +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESHGUI_FilterLibraryDlg.cxx +// Author : Sergey LITONIN +// Module : SMESH + +#include "SMESHGUI_FilterLibraryDlg.h" + +#include "SMESHGUI.h" +#include "SMESHGUI_Utils.h" +#include "SMESHGUI_FilterUtils.h" + +#include "SUIT_Session.h" +#include "SUIT_Desktop.h" +#include "SUIT_FileDlg.h" + +// QT Includes +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SPACING 5 +#define MARGIN 10 + +/*! + * Class : SMESHGUI_FilterLibraryDlg::Dialog + * Description : Dialog for opening filter library + */ + +class SMESHGUI_FilterLibraryDlg::Dialog : public SUIT_FileDlg +{ + public: + Dialog(QWidget* theParent, const bool theToOpen); + virtual ~Dialog(); + + protected: + virtual bool acceptData(); +}; + +SMESHGUI_FilterLibraryDlg::Dialog::Dialog (QWidget* theParent, + const bool theToOpen) + : SUIT_FileDlg(theParent, theToOpen) +{ +} + +SMESHGUI_FilterLibraryDlg::Dialog::~Dialog() +{ +} + +bool SMESHGUI_FilterLibraryDlg::Dialog::acceptData() +{ +// if (mode() != QFileDialogP::AnyFile) +// return SUIT_FileDlg::acceptData(); + + return true; +} + +/*! + * Class : SMESHGUI_FilterLibraryDlg + * Description : Dialog to specify filters for VTK viewer + */ + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::SMESHGUI_FilterLibraryDlg +// Purpose : Constructor +//======================================================================= +SMESHGUI_FilterLibraryDlg::SMESHGUI_FilterLibraryDlg (SMESHGUI* theModule, + QWidget* parent, + const QValueList& theTypes, + const int theMode, + const char* theName) + : QDialog( parent, theName, true, WStyle_Customize | + WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ), + mySMESHGUI( theModule ) +{ + construct(theTypes, theMode); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::SMESHGUI_FilterLibraryDlg +// Purpose : Constructor +//======================================================================= +SMESHGUI_FilterLibraryDlg::SMESHGUI_FilterLibraryDlg (SMESHGUI* theModule, + QWidget* parent, + const int theType, + const int theMode, + const char* theName) + : QDialog( parent, theName, true, WStyle_Customize | + WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ), + mySMESHGUI( theModule ) +{ + QValueList aTypes; + aTypes.append(theType); + construct(aTypes, theMode); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::construct +// Purpose : Construct dialog (called by constructor) +//======================================================================= +void SMESHGUI_FilterLibraryDlg::construct (const QValueList& theTypes, + const int theMode) +{ + myTypes = theTypes; + myMode = theMode; + + QVBoxLayout* aDlgLay = new QVBoxLayout(this, MARGIN, SPACING); + + myMainFrame = createMainFrame (this); + QFrame* aBtnFrame = createButtonFrame(this); + + aDlgLay->addWidget(myMainFrame); + aDlgLay->addWidget(aBtnFrame); + + aDlgLay->setStretchFactor(myMainFrame, 1); + + Init(myTypes, myMode); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::createMainFrame +// Purpose : Create frame containing dialog's input fields +//======================================================================= +QFrame* SMESHGUI_FilterLibraryDlg::createMainFrame (QWidget* theParent) +{ + QGroupBox* aMainFrame = new QGroupBox(1, Qt::Horizontal, theParent); + aMainFrame->setFrameStyle(QFrame::NoFrame); + aMainFrame->setInsideMargin(0); + + // library name + + QGroupBox* aGrp = new QGroupBox(1, Qt::Vertical, aMainFrame); + aGrp->setFrameStyle(QFrame::NoFrame); + aGrp->setInsideMargin(0); + + new QLabel(tr("LIBRARY_FILE"), aGrp); + myFileName = new QLineEdit(aGrp); + myOpenBtn = new QPushButton(aGrp); + myOpenBtn->setPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap( + "SUIT", tr("ICON_FILE_OPEN"))); + + // filters list box + + aGrp = new QGroupBox(1, Qt::Vertical, tr("FILTER_NAMES"), aMainFrame); + QFrame* aFrame = new QFrame(aGrp); + myListBox = new QListBox(aFrame); + myAddBtn = new QPushButton(tr("ADD"), aFrame); + myDeleteBtn = new QPushButton(tr("DELETE"), aFrame); + + QGridLayout* aLay = new QGridLayout(aFrame, 3, 2, 0, 5); + aLay->addMultiCellWidget(myListBox, 0, 2, 0, 0); + aLay->addWidget(myAddBtn, 0, 1); + aLay->addWidget(myDeleteBtn, 1, 1); + QSpacerItem* aVSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + aLay->addItem(aVSpacer, 2, 1); + + // filter name + + myNameGrp = new QGroupBox(1, Qt::Vertical, aMainFrame); + myNameGrp->setFrameStyle(QFrame::NoFrame); + myNameGrp->setInsideMargin(0); + new QLabel(tr("FILTER_NAME"), myNameGrp); + myName = new QLineEdit(myNameGrp); + + // table + + myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes); + myTable->SetEditable(myMode == EDIT); + myTable->SetLibsEnabled(false); + + myListBox->setMinimumHeight((int)(myTable->sizeHint().height() * 0.5)); + myListBox->setRowMode(QListBox::FitToWidth); + myListBox->setSelectionMode(QListBox::Single); + + myOpenBtn->setAutoDefault(false); + myAddBtn->setAutoDefault(false); + myDeleteBtn->setAutoDefault(false); + + // connect signals and slots + + connect(myFileName, SIGNAL(returnPressed()), this, SLOT(onReturnPressed())); + connect(myOpenBtn , SIGNAL(clicked()), this, SLOT(onBrowse())); + + connect(myListBox, SIGNAL(highlighted(const QString&)), + this, SLOT(onFilterChanged(const QString&))); + + connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtnPressed())); + connect(myDeleteBtn, SIGNAL(clicked()), this, SLOT(onDeleteBtnPressed())); + + connect(myName, SIGNAL(textChanged(const QString&)), + this, SLOT(onFilterNameChanged(const QString&))); + + connect(myTable, SIGNAL(EntityTypeChanged(const int)), + this, SLOT(onEntityTypeChanged(const int))); + + connect(myTable, SIGNAL(NeedValidation()), this, SLOT(onNeedValidation())); + + return aMainFrame; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::createButtonFrame +// Purpose : Create frame containing buttons +//======================================================================= +QFrame* SMESHGUI_FilterLibraryDlg::createButtonFrame (QWidget* theParent) +{ + QGroupBox* aGrp = new QGroupBox(1, Qt::Vertical, theParent); + + myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_OK" ), aGrp); + myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp); + + QLabel* aLbl = new QLabel(aGrp); + aLbl->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); + + myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp); + myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp); + + connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk())); + connect(myButtons[ BTN_Cancel ], SIGNAL(clicked()), SLOT(onClose())); + connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose())); + connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply())); + + QMap::iterator anIter; + for (anIter = myButtons.begin(); anIter != myButtons.end(); ++anIter) + anIter.data()->setAutoDefault(false); + + updateMainButtons(); + + return aGrp; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::updateMainButtons +// Purpose : Update visibility of main buttons (OK, Cancel, Close ...) +//======================================================================= +void SMESHGUI_FilterLibraryDlg::updateMainButtons() +{ + if (myTypes.count() == 1) { + myButtons[ BTN_Cancel ]->show(); + myButtons[ BTN_Apply ]->hide(); + myButtons[ BTN_Close ]->hide(); + } else { + myButtons[ BTN_Cancel ]->hide(); + myButtons[ BTN_Apply ]->show(); + myButtons[ BTN_Close ]->show(); + } +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::~SMESHGUI_FilterLibraryDlg +// Purpose : Destructor +//======================================================================= +SMESHGUI_FilterLibraryDlg::~SMESHGUI_FilterLibraryDlg() +{ +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::Init +// Purpose : Init dialog fields, connect signals and slots, show dialog +//======================================================================= +void SMESHGUI_FilterLibraryDlg::Init (const int type, const int theMode) +{ + QValueList aTypes; + aTypes.append(type); + Init(aTypes, theMode); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::Init +// Purpose : Init dialog fields, connect signals and slots, show dialog +//======================================================================= +void SMESHGUI_FilterLibraryDlg::Init (const QValueList& theTypes, + const int theMode) +{ + myMode = theMode; + myTypes = theTypes; + myTable->Init(theTypes); + myCurrFilterName = ""; + myCurrFilter = -1; + myListBox->clear(); + myName->clear(); + myTable->Clear(); + + updateControlsVisibility(); + setEnabled(true); + + connect( mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate())); + connect( mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose())); + + if (myMode == ADD_TO) + { + setCaption(tr("ADD_TO_TLT")); + if (myFileName->text().isEmpty()) + myFileName->setText(getDefaultLibraryName()); + processNewLibrary(); + } + else if (myMode == COPY_FROM) + { + setCaption(tr("COPY_FROM_TLT")); + if (myFileName->text().isEmpty()) + myFileName->setText(getDefaultLibraryName()); + processNewLibrary(); + if (myListBox->count() > 0) + myListBox->setCurrentItem(0); + } + else + { + setCaption(tr("EDIT_LIB_TLT")); + if (myFileName->text().isEmpty()) + myFileName->setText(getDefaultLibraryName()); + processNewLibrary(); + if (myListBox->count() > 0) + myListBox->setCurrentItem(0); + } + + int x, y; + mySMESHGUI->DefineDlgPosition(this, x, y); + this->move(x, y); + + this->show(); + + updateMainButtons(); + isPermissionValid(false); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::updateControlsVisibility +// Purpose : Update visibility of controls in accordance with myMode +//======================================================================= +void SMESHGUI_FilterLibraryDlg::updateControlsVisibility() +{ + if (myMode == ADD_TO) + { + myNameGrp->show(); + myNameGrp->setEnabled(true); + myAddBtn->hide(); + myDeleteBtn->hide(); + myTable->SetEditable(false); + } + else if (myMode == COPY_FROM) + { + myNameGrp->hide(); + myNameGrp->setEnabled(false); + myAddBtn->hide(); + myDeleteBtn->hide(); + myTable->SetEditable(false); + } + else if (myMode == EDIT) + { + myNameGrp->show(); + myNameGrp->setEnabled(true); + myAddBtn->show(); + myDeleteBtn->show(); + myTable->SetEditable(true); + } + + qApp->processEvents(); + updateGeometry(); + adjustSize(); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onApply +// Purpose : SLOT called when "Apply" button pressed. +//======================================================================= +bool SMESHGUI_FilterLibraryDlg::onApply() +{ + if (!isValid(true) || !isPermissionValid(false)) + return false; + + if (myLibrary->_is_nil()) { + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"), + tr("LIBRARY_IS_NOT_LOADED"), QMessageBox::Ok); + return false; + } + + const char* aName = myFileName->text().latin1(); + if (strcmp(myLibrary->GetFileName(), aName) != 0) + myLibrary->SetFileName(aName); + + bool aResult = false; + + if (myMode == COPY_FROM || myListBox->count() == 0) { + aResult = true; + } else if (myMode == EDIT || myMode == ADD_TO) { + SMESH::Filter_var aFilter = createFilter(); + if (!myLibrary->Replace(myCurrFilterName, myName->text(), aFilter.in())) { + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), + tr("ERROR_OF_EDITING"), QMessageBox::Ok); + aResult = false; + } + else + aResult = true; + } + + if (aResult && myMode != COPY_FROM) + aResult = myLibrary->Save(); + + if (aResult) { + char* aFileName = myLibrary->GetFileName(); + getDefaultLibraryName() = QString(aFileName); + delete aFileName; + } else if (myMode != COPY_FROM) { + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), + tr("ERROR_OF_SAVING"), QMessageBox::Ok); + } else { + } + + return aResult; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onOk +// Purpose : SLOT called when "Ok" button pressed. +// Assign filters VTK viewer and close dialog +//======================================================================= +void SMESHGUI_FilterLibraryDlg::onOk() +{ + if (onApply()) + { + disconnect( mySMESHGUI, 0, this, 0); + mySMESHGUI->ResetState(); + accept(); + } +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onClose +// Purpose : SLOT called when "Close" button pressed. Close dialog +//======================================================================= +void SMESHGUI_FilterLibraryDlg::onClose() +{ + disconnect( mySMESHGUI, 0, this, 0); + mySMESHGUI->ResetState(); + reject(); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onDeactivate +// Purpose : SLOT called when dialog must be deativated +//======================================================================= +void SMESHGUI_FilterLibraryDlg::onDeactivate() +{ + setEnabled(false); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::enterEvent +// Purpose : Event filter +//======================================================================= +void SMESHGUI_FilterLibraryDlg::enterEvent(QEvent*) +{ + setEnabled(true); +} + +//================================================================================= +// function : closeEvent() +// purpose : Close dialog +//================================================================================= +void SMESHGUI_FilterLibraryDlg::closeEvent(QCloseEvent* e) +{ + onClose(); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::getFileName +// Purpose : Get file name +//======================================================================= +QString SMESHGUI_FilterLibraryDlg::getFileName() const +{ + return myFileName != 0 ? myFileName->text() : QString(""); +} + +//================================================================ +// Function : setFileName +// Purpose : Set file name to line edit +//================================================================ +void SMESHGUI_FilterLibraryDlg::setFileName(const QString& txt, const bool autoExt) +{ + if (myFileName == 0) + return; + myFileName->setText(autoExt ? autoExtension(txt) : txt); +} + +//================================================================ +// Function : autoExtension +// Purpose : Append extension to the file name +//================================================================ +QString SMESHGUI_FilterLibraryDlg::autoExtension(const QString& theFileName) const +{ + QString anExt = theFileName.section('.', -1); + return anExt != "xml" && anExt != "XML" ? theFileName + ".xml" : theFileName; +} + +//================================================================ +// Function : filterWildCards +// Purpose : +//================================================================ +QStringList SMESHGUI_FilterLibraryDlg::filterWildCards(const QString& theFilter) const +{ + QStringList res; + + int b = theFilter.findRev("("); + int e = theFilter.findRev(")"); + if (b != -1 && e != -1) + { + QString content = theFilter.mid(b + 1, e - b - 1).stripWhiteSpace(); + QStringList lst = QStringList::split(" ", content); + for (QStringList::const_iterator it = lst.begin(); it != lst.end(); ++it) + if ((*it).find(".") != -1) + res.append((*it).stripWhiteSpace()); + } + return res; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::prepareFilters +// Purpose : Prepare filters for dialog +//======================================================================= +QStringList SMESHGUI_FilterLibraryDlg::prepareFilters() const +{ + static QStringList aList; + if (aList.isEmpty()) + { + aList.append(tr("XML_FILT")); + //aList.append(tr("ALL_FILES_FILTER")); + } + + return aList; +} + +//================================================================ +// Function : onBrowse +// Purpose : SLOT. Display "Open file" dialog for chosing library name +//================================================================ +void SMESHGUI_FilterLibraryDlg::onBrowse() +{ + Dialog* aDlg = new Dialog(this, true); + aDlg->setCaption(tr("OPEN_LIBRARY")); + + //aDlg->setMode(myMode == COPY_FROM ? QFileDialogP::ExistingFile : QFileDialogP::AnyFile); + aDlg->setMode(myMode == COPY_FROM ? QFileDialog::ExistingFile : QFileDialog::AnyFile); + aDlg->setFilters(prepareFilters()); + aDlg->setSelection(getFileName()); + + QPushButton* anOkBtn = (QPushButton*)aDlg->child("OK", "QPushButton"); + if (anOkBtn != 0) + anOkBtn->setText(tr("SMESH_BUT_OK")); + + if (aDlg->exec() != Accepted) + return; + + QString fName = aDlg->selectedFile(); + + if (fName.isEmpty()) + return; + + if (QFileInfo(fName).extension().isEmpty()) + fName = autoExtension(fName); + + fName = QDir::convertSeparators(fName); + QString prev = QDir::convertSeparators(getFileName()); + + if (prev == fName) + return; + + setFileName(fName); + + QString aName = myListBox->text(myListBox->count() - 1); + processNewLibrary(); + + if (myMode == ADD_TO) + { + myTable->Copy((SMESHGUI_FilterTable*)parentWidget()); + myCurrFilterName = ""; + myCurrFilter = -1; + addFilterToLib(aName); + } + + isPermissionValid(false); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::processNewLibrary +// Purpose : SLOT. Calleds when file name changed +//======================================================================= +void SMESHGUI_FilterLibraryDlg::processNewLibrary() +{ + SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager(); + if (aFilterMgr->_is_nil()) + return; + + myLibrary = aFilterMgr->LoadLibrary(autoExtension(getFileName())); + if (myLibrary->_is_nil()) { + if (myMode == COPY_FROM) { + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), + tr("ERROR_LOAD"), QMessageBox::Ok); + return; + } else { + myLibrary = aFilterMgr->CreateLibrary(); + myLibrary->SetFileName(getFileName().latin1()); + } + } + + updateList(); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::updateList +// Purpose : Fill list box with filter names +//======================================================================= +void SMESHGUI_FilterLibraryDlg::updateList() +{ + QStringList aList; + SMESH::string_array_var aNames = myLibrary->GetNames((SMESH::ElementType)myTable->GetType()); + for (int i = 0, n = aNames->length(); i < n; i++) + aList.append(QString(aNames[ i ])); + myListBox->clear(); + myListBox->insertStringList(aList); + if (myListBox->count() == 0) + { + myTable->Clear(myTable->GetType()); + myName->clear(); + myName->setEnabled(false); + myTable->SetEnabled(false); + } + else + { + myName->setEnabled(true); + myTable->SetEnabled(true); + if (myListBox->count()) + { + myCurrFilterName = ""; + myListBox->setCurrentItem(0); + } + } +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::isNameValid +// Purpose : Verify validity if entered data +//======================================================================= +bool SMESHGUI_FilterLibraryDlg::isNameValid(const bool theMess) const +{ + // verify validity of filter name + if (myName->isEnabled() && !myCurrFilterName.isEmpty()) { + QString aCurrName = myName->text(); + if (aCurrName.isEmpty()) { + if (theMess) + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), + tr("EMPTY_FILTER_NAME"), QMessageBox::Ok); + return false; + } + + SMESH::string_array_var aNames = myLibrary->GetAllNames(); + for (int f = 0, n = aNames->length(); f < n; f++) { + if (aNames[ f ] == aCurrName && aNames[ f ] != myCurrFilterName) { + if (theMess) + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), + tr("ERROR_FILTER_NAME"), QMessageBox::Ok); + return false; + } + } + } + + return true; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::isPermissionValid +// Purpose : Verify write permission on file +//======================================================================= +bool SMESHGUI_FilterLibraryDlg::isPermissionValid(const bool theIsExistingOnly) +{ + if (myMode == COPY_FROM) + return true; + + // Verify write permission + bool isWritable = false; + + QString fName(myFileName->text()); + if (QFileInfo(fName).extension().isEmpty()) + fName = autoExtension(fName); + + fName = QDir::convertSeparators(fName); + + if (QFileInfo(fName).exists()) { + isWritable = QFileInfo(fName).isWritable(); + } else if (!theIsExistingOnly) { + QFileInfo aDirInfo(QFileInfo(fName).dirPath(true)); + isWritable = aDirInfo.isWritable(); + /*if (QDir(QFileInfo(fName).dirPath(true)).exists() || + QDir().mkdir(QFileInfo(fName).dirPath(true))) + { + QFile aFile(fName); + if (aFile.open(IO_WriteOnly)) + isWritable = true; + else + aFile.close(); + } + */ + } else { + isWritable = true; + } + + if (!isWritable) { + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"), + tr("NO_PERMISSION"), QMessageBox::Ok); + return false; + } + + return true; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::isValid +// Purpose : Verify validity if entered data +//======================================================================= +bool SMESHGUI_FilterLibraryDlg::isValid(const bool theMess) const +{ + // verify validity of table + if (!myTable->IsValid(theMess) || !isNameValid(theMess)) + return false; + else + return true; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onFilterChanged +// Purpose : SLOT. Called when selected filter of library changed +//======================================================================= +void SMESHGUI_FilterLibraryDlg::onFilterChanged(const QString& theName) +{ + if (myLibrary->_is_nil()) + return; + + // Save parameters of filter if it was changed + + if (!myCurrFilterName.isEmpty() && myTable->IsEditable()) + { + if (!isValid(true)) + { + myListBox->blockSignals(true); + myListBox->setCurrentItem(myCurrFilter); + myListBox->blockSignals(false); + return; + } + + SMESH::Filter_var aFilter = createFilter(); + myLibrary->Replace(myCurrFilterName.latin1(), myName->text().latin1(), aFilter); + } + + // Fill table with filter parameters + + SMESH::Filter_var aFilter = myLibrary->Copy(theName); + myCurrFilterName = theName; + myCurrFilter = myListBox->currentItem(); + myName->setText(theName); + + + SMESH::Filter::Criteria_var aCriteria; + + myTable->Clear(myTable->GetType()); + + if (!aFilter->GetCriteria(aCriteria)) + return; + + for (int i = 0, n = aCriteria->length(); i < n; i++) + myTable->AddCriterion(aCriteria[ i ], myTable->GetType()); + + myTable->Update(); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onReturnPressed +// Purpose : SLOT. Called when enter button is pressed in library name field +// Reload library +//======================================================================= +void SMESHGUI_FilterLibraryDlg::onReturnPressed() +{ + QString aName = myListBox->text(myListBox->count() - 1); + + processNewLibrary(); + + if (myMode == ADD_TO) + { + myTable->Copy((SMESHGUI_FilterTable*)parentWidget()); + myCurrFilterName = ""; + myCurrFilter = -1; + addFilterToLib(aName); + } + + isPermissionValid(false); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::enableMainButtons +// Purpose : Update state of "OK", "Cancel" buttons +//======================================================================= +void SMESHGUI_FilterLibraryDlg::enableMainButtons() +{ + /*bool isEnabled = isValid(false); + if (myButtons.contains(BTN_OK)) + myButtons[ BTN_OK ]->setEnabled(isEnabled); + else if (myButtons.contains(BTN_Apply)) + myButtons[ BTN_OK ]->setEnabled(isEnabled); + if (myButtons.contains(BTN_Cancel)) + myButtons[ BTN_Cancel ]->setEnabled(isEnabled); + else if (myButtons.contains(BTN_Close)) + myButtons[ BTN_Cancel ]->setEnabled(isEnabled); + */ +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::createFilter +// Purpose : Cerate filter in accordance with library +//======================================================================= +SMESH::Filter_ptr SMESHGUI_FilterLibraryDlg::createFilter(const int theType) +{ + int n = myTable->NumRows(theType); + + SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria; + aCriteria->length(n); + + for (int i = 0; i < n; i++) + { + SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion(); + myTable->GetCriterion(i, aCriterion); + aCriteria[ i ] = aCriterion; + } + + SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager(); + SMESH::Filter_var aFilter = aFilterMgr->CreateFilter(); + aFilter->SetCriteria(aCriteria.in()); + + return aFilter._retn(); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onAddBtnPressed +// Purpose : SLOT. Called when "Add" button pressed +// Add new filter to the end of library +//======================================================================= +void SMESHGUI_FilterLibraryDlg::onAddBtnPressed() +{ + // Save parameters of filter if it was changed + if (!myCurrFilterName.isEmpty() && myTable->IsEditable()) + { + if (!isValid(true)) + return; + + SMESH::Filter_var aFilter = createFilter(); + myLibrary->Replace(myCurrFilterName.latin1(), myName->text().latin1(), aFilter); + } + + addFilterToLib(getDefaultFilterName()); +} + +//======================================================================= +// name : onAddBtnPressed() +// Purpose : SLOT. Called when "Add" button pressed +// Add new filter to the end of library +//======================================================================= +void SMESHGUI_FilterLibraryDlg::addFilterToLib (const QString& theName) +{ + if (myLibrary->_is_nil()) { + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"), + tr("LIBRARY_IS_NOT_LOADED"), QMessageBox::Ok); + return; + } + + // create filter + SMESH::Filter_var aFilter = createFilter(); + + // if name of filter already exist in the library assign default name for the filter + QString aName(theName); + SMESH::string_array_var aNames = myLibrary->GetAllNames(); + for (int i = 0, n = aNames->length(); i < n; i++) + if (aName == QString(aNames[ i ])) + { + aName = getDefaultFilterName(); + break; + } + + // add new filter in library + bool aResult = !aFilter->GetPredicate()->_is_nil() + ? myLibrary->Add(aName.latin1(), aFilter) + : myLibrary->AddEmpty(aName.latin1(), (SMESH::ElementType)myTable->GetType()); + + if (!aResult) { + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), + tr("ERROR_OF_ADDING"), QMessageBox::Ok); + } + + updateList(); + myCurrFilterName = ""; + myCurrFilter = -1; + setSelected(aName); + + if (theName != aName) + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WARNING"), + tr("ASSIGN_NEW_NAME").arg(theName).arg(aName), QMessageBox::Ok); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::getDefaultLibraryName +// Purpose : Get default library name +//======================================================================= +QString& SMESHGUI_FilterLibraryDlg::getDefaultLibraryName() const +{ + static QString aName; + if (aName.isEmpty()) + { + QString aHomeDir = QDir(QDir::home()).absPath(); + aName = aHomeDir + "/" + tr ("LIB_NAME"); + } + return aName; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::getDefaultFilterName +// Purpose : Create default filter name +//======================================================================= +QString SMESHGUI_FilterLibraryDlg::getDefaultFilterName() const +{ + QString aName; + + if (myTable->GetType() == SMESH::NODE) + aName = tr("NODE"); + else if (myTable->GetType() == SMESH::EDGE) + aName = tr("EDGE"); + else if (myTable->GetType() == SMESH::FACE) + aName = tr("FACE"); + else if (myTable->GetType() == SMESH::VOLUME) + aName = tr("VOLUME"); + else if (myTable->GetType() == SMESH::ALL) + aName = tr("ELEMENT"); + else + aName = tr("SELECTION"); + + aName += tr("FILTER"); + + + QMap< QString, int > anAllNames; + SMESH::string_array_var aNames = myLibrary->GetAllNames(); + for(int i = 0, n = aNames->length(); i < n; i++) + anAllNames[ QString(aNames[ i ]) ] = -1; + + bool isNotValid = true; + int k = 1; + QString aNewName; + while (isNotValid) + { + isNotValid = false; + aNewName = aName + "_" + QString("%1").arg(k); + if (anAllNames.contains(aNewName)) + { + isNotValid = true; + k++; + } + } + + return aNewName; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::setSelected +// Purpose : set selected item in list box containing filters +//======================================================================= +bool SMESHGUI_FilterLibraryDlg::setSelected(const QString& theName) +{ + int anIndex = getIndex(theName); + if (anIndex != -1) + { + myListBox->setCurrentItem(anIndex); + myCurrFilterName = theName; + myCurrFilter = anIndex; + } + return anIndex != -1; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::getIndex +// Purpose : Get index of the filter in list box +//======================================================================= +int SMESHGUI_FilterLibraryDlg::getIndex(const QString& theName) const +{ + for (int i = 0, n = myListBox->count(); i < n; i++) + if (myListBox->text(i) == theName) + return i; + return -1; +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onDeleteBtnPressed +// Purpose : SLOT. Called when "Delete" button pressed +//======================================================================= +void SMESHGUI_FilterLibraryDlg::onDeleteBtnPressed() +{ + if (myLibrary->_is_nil()) { + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"), + tr("LIBRARY_IS_NOT_LOADED"), QMessageBox::Ok); + return; + } + + int anIndex = getIndex(myCurrFilterName); + + if (anIndex == -1 || !myLibrary->Delete(myCurrFilterName.latin1())) { + QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_ERROR"), + tr("ERROR_OF_DELETING"), QMessageBox::Ok); + } else { + myCurrFilterName = ""; + myCurrFilter = -1; + myListBox->removeItem(anIndex); + + if (anIndex >= 1) + myListBox->setSelected(anIndex - 1, true); + else if (anIndex == 0 && myListBox->count() > 0) + myListBox->setSelected(0, true); + else + myTable->Clear(); + } + + myTable->SetEnabled(myListBox->count() > 0); + if (myListBox->count() == 0) { + myName->setText(""); + myName->setEnabled(false); + } +} + +//======================================================================= +// name : onFilterNameChanged() +// Purpose : SLOT. Called when name of filter changed +// Change filter name in list box +//======================================================================= +void SMESHGUI_FilterLibraryDlg::onFilterNameChanged (const QString& theName) +{ + int aCurrItem = myListBox->currentItem(); + if (aCurrItem == -1) + return; + + myListBox->blockSignals(true); + myListBox->changeItem(theName, aCurrItem); + myListBox->blockSignals(false); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::SetTable +// Purpose : Set table +//======================================================================= +void SMESHGUI_FilterLibraryDlg::SetTable(const SMESHGUI_FilterTable* theTable) +{ + myTable->Copy(theTable); + myName->setText(getDefaultFilterName()); + addFilterToLib(myName->text()); + myTable->Update(); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::GetTable +// Purpose : Get table +//======================================================================= +const SMESHGUI_FilterTable* SMESHGUI_FilterLibraryDlg::GetTable() const +{ + return myTable; +} + + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onEntityTypeChanged +// Purpose : SLOT. Called when entiyt type changed +//======================================================================= +void SMESHGUI_FilterLibraryDlg::onEntityTypeChanged(const int theType) +{ + if (myLibrary->_is_nil()) + return; + + myName->clear(); + myCurrFilterName = ""; + myCurrFilter = -1; + updateList(); + if (myListBox->count()) + myListBox->setCurrentItem(0); +} + +//======================================================================= +// name : SMESHGUI_FilterLibraryDlg::onNeedValidation +// Purpose : +//======================================================================= +void SMESHGUI_FilterLibraryDlg::onNeedValidation() +{ + if (!myCurrFilterName.isEmpty()) + { + bool valid = isValid(true); + myTable->SetValidity(valid); + + if (valid) + { + SMESH::Filter_var aFilter = createFilter(myTable->GetType()); + myLibrary->Replace(myCurrFilterName.latin1(), myName->text().latin1(), aFilter); + } + } +} diff --git a/src/SMESHGUI/SMESHGUI_FilterUtils.cxx b/src/SMESHGUI/SMESHGUI_FilterUtils.cxx new file mode 100644 index 000000000..e5c529f16 --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_FilterUtils.cxx @@ -0,0 +1,37 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org + + +#include "SMESHGUI_FilterUtils.h" + +#include "SMESHGUI.h" + +#include "utilities.h" + +namespace SMESH +{ + SMESH::FilterManager_var& GetFilterManager() + { + static SMESH::FilterManager_var aFilterManager; + if (CORBA::is_nil(aFilterManager)) { + aFilterManager = SMESHGUI::GetSMESHGen()->CreateFilterManager(); + } + return aFilterManager; + } +} diff --git a/src/SMESHGUI/SMESHGUI_FilterUtils.h b/src/SMESHGUI/SMESHGUI_FilterUtils.h new file mode 100644 index 000000000..6b8c75862 --- /dev/null +++ b/src/SMESHGUI/SMESHGUI_FilterUtils.h @@ -0,0 +1,34 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org + +#ifndef SMESHGUI_FilterUtils_HeaderFile +#define SMESHGUI_FilterUtils_HeaderFile + +#include "SALOMEconfig.h" +#include CORBA_SERVER_HEADER(SMESH_Filter) + + +namespace SMESH{ + + SMESH::FilterManager_var& GetFilterManager(); + +} + + +#endif diff --git a/src/SMESH_I/SMESH_MEDFamily_i.hxx b/src/SMESH_I/SMESH_MEDFamily_i.hxx new file mode 100644 index 000000000..eeeef51ee --- /dev/null +++ b/src/SMESH_I/SMESH_MEDFamily_i.hxx @@ -0,0 +1,90 @@ +// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESH_MEDFamily_i.hxx +// Module : SMESH + +#ifndef SMESH_MED_FAMILY_I_HXX_ +#define SMESH_MED_FAMILY_I_HXX_ + +#include "SMESH_MEDSupport_i.hxx" + +#include + +class SMESH_MEDFamily_i: + public virtual POA_SALOME_MED::FAMILY, + public virtual SMESH_MEDSupport_i +{ +protected : + SMESH_MEDFamily_i(); + ~SMESH_MEDFamily_i(); + + ::SMESH_subMesh_i* _subMesh_i; + + // Values + int _identifier; + int _numberOfAttribute; + int * _attributeIdentifier; + int * _attributeValue; + string * _attributeDescription; + int _numberOfGroup ; + string * _groupName ; + + +public : + + // Constructors and associated internal methods + SMESH_MEDFamily_i(int identifier, SMESH_subMesh_i* sm, + string name, string description, SALOME_MED::medEntityMesh entity ); + SMESH_MEDFamily_i(const SMESH_MEDFamily_i & f); + + // IDL Methods + void setProtocol(SALOME::TypeOfCommunication typ) {} + void release() {} + SALOME::SenderInt_ptr getSenderForNumber(long int) {return SALOME::SenderInt::_nil();} + SALOME::SenderInt_ptr getSenderForNumberIndex() {return SALOME::SenderInt::_nil();} + + CORBA::Long getIdentifier() + throw (SALOME::SALOME_Exception); + CORBA::Long getNumberOfAttributes() + throw (SALOME::SALOME_Exception); + SALOME_MED::long_array* getAttributesIdentifiers() + throw (SALOME::SALOME_Exception); + CORBA::Long getAttributeIdentifier(CORBA::Long i) + throw (SALOME::SALOME_Exception); + SALOME_MED::long_array* getAttributesValues() + throw (SALOME::SALOME_Exception); + CORBA::Long getAttributeValue(CORBA::Long i) + throw (SALOME::SALOME_Exception); + SALOME_MED::string_array* getAttributesDescriptions() + throw (SALOME::SALOME_Exception); + char* getAttributeDescription( CORBA::Long i) + throw (SALOME::SALOME_Exception); + CORBA::Long getNumberOfGroups() + throw (SALOME::SALOME_Exception); + char * getGroupName( CORBA::Long i) + throw (SALOME::SALOME_Exception); + SALOME_MED::string_array* getGroupsNames() + throw (SALOME::SALOME_Exception); +}; +#endif /* MED_FAMILY_I_HXX_ */ diff --git a/src/SMESH_I/SMESH_MEDSupport_i.hxx b/src/SMESH_I/SMESH_MEDSupport_i.hxx new file mode 100644 index 000000000..c888661b6 --- /dev/null +++ b/src/SMESH_I/SMESH_MEDSupport_i.hxx @@ -0,0 +1,111 @@ +// SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : SMESH_MEDSupport_i.hxx +// Module : SMESH + +#ifndef _MED_SMESH_MEDSUPPORT_I_HXX_ +#define _MED_SMESH_MEDSUPPORT_I_HXX_ + +#include +#include CORBA_SERVER_HEADER(MED) +#include + +#include "SMESHDS_Mesh.hxx" +#include "SMESHDS_SubMesh.hxx" +#include "SMDS_MeshElement.hxx" +#include "SMDS_MeshNode.hxx" + +#include "SMESH_MEDSupport_i.hxx" +#include "SALOME_GenericObj_i.hh" +class SMESH_subMesh_i; + +class SMESH_MEDSupport_i: + public virtual POA_SALOME_MED::SUPPORT, public virtual SALOME::GenericObj_i +{ + public: + +// Constructors and associated internal methods + SMESH_MEDSupport_i(SMESH_subMesh_i * sm, + string name, string description, SALOME_MED::medEntityMesh entity); + SMESH_MEDSupport_i(const SMESH_MEDSupport_i & s); + +// IDL Methods + char *getName() throw(SALOME::SALOME_Exception); + char *getDescription() throw(SALOME::SALOME_Exception); + SALOME_MED::MESH_ptr getMesh() throw(SALOME::SALOME_Exception); + CORBA::Boolean isOnAllElements() throw(SALOME::SALOME_Exception); + SALOME_MED::medEntityMesh getEntity() throw(SALOME::SALOME_Exception); + CORBA::Long + getNumberOfElements(SALOME_MED::medGeometryElement geomElement) + throw(SALOME::SALOME_Exception); + + CORBA::Long getNumberOfTypes() throw (SALOME::SALOME_Exception); + + SALOME_MED::long_array * + getNumber(SALOME_MED::medGeometryElement geomElement) + throw(SALOME::SALOME_Exception); + + SALOME_MED::long_array * getNumberIndex() + throw(SALOME::SALOME_Exception); + + CORBA::Long + getNumberOfGaussPoint(SALOME_MED::medGeometryElement geomElement) + throw(SALOME::SALOME_Exception); + + SALOME_MED::long_array* getNumbersOfGaussPoint() + throw (SALOME::SALOME_Exception); + + SALOME_MED::medGeometryElement_array *getTypes() + throw(SALOME::SALOME_Exception); + + void getBoundaryElements() throw (SALOME::SALOME_Exception); + + CORBA::Long getCorbaIndex() throw(SALOME::SALOME_Exception); + + SALOME_MED::SUPPORT::supportInfos * getSupportGlobal() + throw (SALOME::SALOME_Exception); + + void createSeq() throw(SALOME::SALOME_Exception); + + public: //public field + const SMESHDS_SubMesh * _subMeshDS; + ::SMESH_subMesh_i * _subMesh_i; + + SMESHDS_Mesh * _meshDS; + string _name; + string _description; + bool _isOnAllElements; + bool _seqNumber; + int _seqLength; + + SALOME_MED::medEntityMesh _entity; + SALOME_MED::medGeometryElement * _geometricType; + int _numberOfGeometricType; + + protected: + SMESH_MEDSupport_i(); + ~SMESH_MEDSupport_i(); +}; + +#endif /* _MED_MEDSUPPORT_I_HXX_ */ -- 2.30.2