From: rnv Date: Fri, 29 Dec 2017 13:20:32 +0000 (+0300) Subject: Merge changes from 'master' branch. X-Git-Tag: V9_0_0~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=10191484fe88a27e962b8e4b57e09d390d8705c7;p=modules%2Fsmesh.git Merge changes from 'master' branch. --- 10191484fe88a27e962b8e4b57e09d390d8705c7 diff --cc doc/salome/examples/create_penta_biquad.py index 000000000,60b1b617c..9e7ec271a mode 000000,100644..100644 --- a/doc/salome/examples/create_penta_biquad.py +++ b/doc/salome/examples/create_penta_biquad.py @@@ -1,0 -1,43 +1,42 @@@ + # -*- coding: utf-8 -*- + + import sys + import salome + + salome.salome_init() -theStudy = salome.myStudy + + import SMESH, SALOMEDS + from salome.smesh import smeshBuilder + -smesh = smeshBuilder.New(theStudy) ++smesh = smeshBuilder.New() + unPentaBiQuad = smesh.Mesh() + nodeID = unPentaBiQuad.AddNode( 0, 0, 0 ) + nodeID = unPentaBiQuad.AddNode( 10, 0, 0 ) + nodeID = unPentaBiQuad.AddNode( 0, 10, 0 ) + nodeID = unPentaBiQuad.AddNode( 0, 0, 10 ) + nodeID = unPentaBiQuad.AddNode( 10, 0, 10 ) + nodeID = unPentaBiQuad.AddNode( 0, 10, 10 ) + nodeID = unPentaBiQuad.AddNode( 5, 0, 0 ) + nodeID = unPentaBiQuad.AddNode( 7, 7, 0 ) + nodeID = unPentaBiQuad.AddNode( 0, 5, 0 ) + nodeID = unPentaBiQuad.AddNode( 5, 0, 10 ) + nodeID = unPentaBiQuad.AddNode( 7, 7, 10 ) + nodeID = unPentaBiQuad.AddNode( 0, 5, 10 ) + nodeID = unPentaBiQuad.AddNode( 0, 0, 5 ) + nodeID = unPentaBiQuad.AddNode( 10, 0, 5 ) + nodeID = unPentaBiQuad.AddNode( 0, 10, 5 ) + nodeID = unPentaBiQuad.AddNode( 5, -1, 5 ) + nodeID = unPentaBiQuad.AddNode( 8, 8, 5 ) + nodeID = unPentaBiQuad.AddNode( -1, 5, 5 ) + volID = unPentaBiQuad.AddVolume( [ 4, 5, 6, 1, 2, 3, 10, 11, 12, 7, 8, 9, 13, 14, 15, 16, 17, 18 ] ) + + infos = unPentaBiQuad.GetMeshInfo() -print "Number of biquadratic pentahedrons:", infos[SMESH.Entity_BiQuad_Penta] ++print("Number of biquadratic pentahedrons:", infos[SMESH.Entity_BiQuad_Penta]) + if (infos[SMESH.Entity_BiQuad_Penta] != 1): + raise RuntimeError("Bad number of biquadratic pentahedrons: should be 1") + + ## Set names of Mesh objects + smesh.SetName(unPentaBiQuad.GetMesh(), 'unPentaBiQuad') + + if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) ++ salome.sg.updateObjBrowser() diff --cc doc/salome/examples/ex_MakePolyLine.py index 000000000,530d39cd7..0a9c67b1b mode 000000,100644..100644 --- a/doc/salome/examples/ex_MakePolyLine.py +++ b/doc/salome/examples/ex_MakePolyLine.py @@@ -1,0 -1,37 +1,37 @@@ + import salome + salome.salome_init() + + ### create geometry + + from salome.geom import geomBuilder + geompy = geomBuilder.New(salome.myStudy) + + Box_1 = geompy.MakeBoxDXDYDZ(200, 200, 200) + geompy.addToStudy( Box_1, 'Box_1' ) + + ### create a mesh + + import SMESH + from salome.smesh import smeshBuilder + smesh = smeshBuilder.New(salome.myStudy) + + Mesh_1 = smesh.Mesh( Box_1 ) + Mesh_1.Segment().NumberOfSegments(15) + Mesh_1.Triangle() + Mesh_1.Compute() + + # define arguments for MakePolyLine + + segments = [] + # between nodes 20 and 1, default plane + segments.append( SMESH.PolySegment( 20, 0, 1, 0, smesh.MakeDirStruct(0,0,0) )) + # between nodes 1 and 100, default plane + segments.append( SMESH.PolySegment( 1, 0, 200, 0, smesh.MakeDirStruct(0,0,0) )) + # between nodes 200 and edge (578, 577), plane includes vector (1,1,1) + segments.append( SMESH.PolySegment( 200, 0, 578, 577, smesh.MakeDirStruct(1,1,1) )) + + Mesh_1.MakePolyLine( segments, "1D group") + + + if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) ++ salome.sg.updateObjBrowser() diff --cc doc/salome/examples/extrusion_penta_biquad.py index 000000000,90cc2087e..b98f8cd4b mode 000000,100644..100644 --- a/doc/salome/examples/extrusion_penta_biquad.py +++ b/doc/salome/examples/extrusion_penta_biquad.py @@@ -1,0 -1,55 +1,54 @@@ + # -*- coding: utf-8 -*- + + import sys + import salome + + salome.salome_init() -theStudy = salome.myStudy + + import GEOM + from salome.geom import geomBuilder + import math + import SALOMEDS + -geompy = geomBuilder.New(theStudy) ++geompy = geomBuilder.New() + + O = geompy.MakeVertex(0, 0, 0) + OX = geompy.MakeVectorDXDYDZ(1, 0, 0) + OY = geompy.MakeVectorDXDYDZ(0, 1, 0) + OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) + Divided_Disk_1 = geompy.MakeDividedDisk(100, 1, GEOM.SQUARE) + geompy.addToStudy( O, 'O' ) + geompy.addToStudy( OX, 'OX' ) + geompy.addToStudy( OY, 'OY' ) + geompy.addToStudy( OZ, 'OZ' ) + geompy.addToStudy( Divided_Disk_1, 'Divided Disk_1' ) + + import SMESH, SALOMEDS + from salome.smesh import smeshBuilder + -smesh = smeshBuilder.New(theStudy) ++smesh = smeshBuilder.New() + aFilterManager = smesh.CreateFilterManager() + Mesh_1 = smesh.Mesh(Divided_Disk_1) + Regular_1D = Mesh_1.Segment() + Number_of_Segments_1 = Regular_1D.NumberOfSegments(6) + Quadrangle_2D = Mesh_1.Quadrangle(algo=smeshBuilder.QUADRANGLE) + isDone = Mesh_1.Compute() + aMaxElementLength2D0x5d7fdf0 = aFilterManager.CreateMaxElementLength2D() + isDone = Mesh_1.QuadToTriObject( Mesh_1, ) + Mesh_1.ExtrusionSweepObjects( [ Mesh_1 ], [ Mesh_1 ], [ Mesh_1 ], [ 0, 0, 50 ], 3, 1 ) + Mesh_1.ConvertToQuadratic(0, Mesh_1,True) + + infos = Mesh_1.GetMeshInfo() -print "Number of biquadratic pentahedrons:", infos[SMESH.Entity_BiQuad_Penta] ++print("Number of biquadratic pentahedrons:", infos[SMESH.Entity_BiQuad_Penta]) + if (infos[SMESH.Entity_BiQuad_Penta] != 1080): + raise RuntimeError("Bad number of biquadratic pentahedrons: should be 1080") + + ## Set names of Mesh objects + smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D') + smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D') + smesh.SetName(Number_of_Segments_1, 'Number of Segments_1') + smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1') + + + if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) ++ salome.sg.updateObjBrowser() diff --cc doc/salome/examples/grouping_elements_ex03.py index 19ce71311,abe275c64..97e1de945 --- a/doc/salome/examples/grouping_elements_ex03.py +++ b/doc/salome/examples/grouping_elements_ex03.py @@@ -28,22 -28,22 +28,22 @@@ critaria = [ ] filt = smesh.GetFilterFromCriteria( critaria ) filtGroup = mesh.GroupOnFilter( SMESH.FACE, "group on filter", filt ) - print("Group on filter contains %s elemens" % filtGroup.Size()) -print "Group on filter contains %s elements" % filtGroup.Size() ++print("Group on filter contains %s elements" % filtGroup.Size()) # group on filter is updated if the mesh is modified hyp1D.SetStartLength( 2.5 ) hyp1D.SetEndLength( 2.5 ) mesh.Compute() - print("After mesh change, group on filter contains %s elemens" % filtGroup.Size()) -print "After mesh change, group on filter contains %s elements" % filtGroup.Size() ++print("After mesh change, group on filter contains %s elements" % filtGroup.Size()) # set a new filter defining the group filt2 = smesh.GetFilter( SMESH.FACE, SMESH.FT_RangeOfIds, "1-50" ) filtGroup.SetFilter( filt2 ) - print("With a new filter, group on filter contains %s elemens" % filtGroup.Size()) -print "With a new filter, group on filter contains %s elements" % filtGroup.Size() ++print("With a new filter, group on filter contains %s elements" % filtGroup.Size()) # group is updated at modification of the filter filt2.SetCriteria( [ smesh.GetCriterion( SMESH.FACE, SMESH.FT_RangeOfIds, "1-70" )]) filtIDs3 = filtGroup.GetIDs() - print("After filter modification, group on filter contains %s elemens" % filtGroup.Size()) -print "After filter modification, group on filter contains %s elements" % filtGroup.Size() ++print("After filter modification, group on filter contains %s elements" % filtGroup.Size()) -salome.sg.updateObjBrowser(True) +salome.sg.updateObjBrowser() diff --cc doc/salome/examples/quality_controls_defl.py index 000000000,9105fee6a..9c018e8de mode 000000,100644..100644 --- a/doc/salome/examples/quality_controls_defl.py +++ b/doc/salome/examples/quality_controls_defl.py @@@ -1,0 -1,45 +1,45 @@@ + # Deflection 2D + + + import salome + salome.salome_init() + from salome.geom import geomBuilder -geompy = geomBuilder.New(salome.myStudy) ++geompy = geomBuilder.New() + + import SMESH + from salome.smesh import smeshBuilder -smesh = smeshBuilder.New(salome.myStudy) ++smesh = smeshBuilder.New() + + # fuse a box and a sphere + Sphere_1 = geompy.MakeSphereR(100) + Box_1 = geompy.MakeBoxDXDYDZ(200, 200, 200) + Fuse = geompy.MakeFuse( Sphere_1, Box_1, theName="box + sphere" ) + + # create a mesh + mesh = smesh.Mesh( Fuse, "Deflection_2D") + algo = mesh.Segment() + algo.LocalLength(35) + algo = mesh.Triangle() + mesh.Compute() + + # get min and max deflection + minMax = mesh.GetMinMax( SMESH.FT_Deflection2D ) -print "min and max deflection: ", minMax ++print("min and max deflection: ", minMax) + + # get deflection of a certain face + faceID = mesh.NbEdges() + mesh.NbFaces() + defl = mesh.FunctorValue( SMESH.FT_Deflection2D, faceID ) -print "deflection of face %s = %s" % ( faceID, defl ) ++print("deflection of face %s = %s" % ( faceID, defl )) + + margin = minMax[1] / 2 + + # get all faces with deflection LESS than the margin + aFilter = smesh.GetFilter(SMESH.FACE, SMESH.FT_Deflection2D, '<', margin, mesh=mesh) + anIds = aFilter.GetIDs() -print "%s faces have deflection less than %s" %( len(anIds), margin ) ++print("%s faces have deflection less than %s" %( len(anIds), margin )) + + # create a group of faces with deflection MORE than the margin -aGroup = mesh.MakeGroup("Deflection > " + `margin`, SMESH.FACE, SMESH.FT_Deflection2D,'>',margin) -print "%s faces have deflection more than %s: %s ..." %( aGroup.Size(), margin, aGroup.GetIDs()[:10] ) ++aGroup = mesh.MakeGroup("Deflection > " + repr(margin), SMESH.FACE, SMESH.FT_Deflection2D,'>',margin) ++print("%s faces have deflection more than %s: %s ..." %( aGroup.Size(), margin, aGroup.GetIDs()[:10] )) + -salome.sg.updateObjBrowser(True) ++salome.sg.updateObjBrowser() diff --cc idl/SMESH_Gen.idl index 4e29fa63b,03ae8e0f8..878c3d6a7 --- a/idl/SMESH_Gen.idl +++ b/idl/SMESH_Gen.idl @@@ -139,22 -139,17 +139,22 @@@ module SMES boolean IsEmbeddedMode(); /*! - Set the current study + Update the study */ - void SetCurrentStudy( in SALOMEDS::Study theStudy ); - + void UpdateStudy(); + + /*! + Set enable publishing in the study + */ + void SetEnablePublish( in boolean theIsEnablePublish ); + /*! - Get the current study + Get enable publishing in the study */ - SALOMEDS::Study GetCurrentStudy(); + boolean IsEnablePublish(); /*! - * Create a hypothesis that can be shared by differents parts of the mesh. + * Create a hypothesis that can be shared by different parts of the mesh. * An hypothesis is either: * - a method used to generate or modify a part of the mesh (algorithm). * - a parameter or a law used by an algorithm. diff --cc src/MEDWrapper/MED_Common.hxx index 798585d8e,000000000..6a861eb5c mode 100644,000000..100644 --- a/src/MEDWrapper/MED_Common.hxx +++ b/src/MEDWrapper/MED_Common.hxx @@@ -1,174 -1,0 +1,174 @@@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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, or (at your option) any later version. +// +// 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.com +// + +#ifndef MED_Common_HeaderFile +#define MED_Common_HeaderFile + +#include "MED_WrapperDef.hxx" +#include "MED_Vector.hxx" +#include "MED_SharedPtr.hxx" + +#include +#include +#include + +#include + +#ifdef WIN32 +#pragma warning(disable:4099) +#endif + +namespace MED +{ + typedef enum {eFAUX, eVRAI} EBooleen; + typedef double TFloat; +#if defined(HAVE_F77INT64) + typedef long TInt; +#else + typedef int TInt; +#endif + typedef hid_t TIdt; + typedef herr_t TErr; + + typedef enum {eFULL_INTERLACE, eNO_INTERLACE} EModeSwitch; + + typedef enum {eFLOAT64=6, eINT=24, eLONG=26} ETypeChamp; + + typedef enum {eNON_STRUCTURE, eSTRUCTURE} EMaillage; + + typedef enum {eCART, eCYL, eSPHER} ERepere; + + typedef enum {eNOD, eDESC} EConnectivite; + + typedef enum {ePOINT1=1, eSEG2=102, eSEG3=103, eTRIA3=203, + eQUAD4=204, eTRIA6=206, eTRIA7=207, eQUAD8=208, eQUAD9=209, eTETRA4=304, + ePYRA5=305, ePENTA6=306, eHEXA8=308, eOCTA12=312, eTETRA10=310, - ePYRA13=313, ePENTA15=315, eHEXA20=320, eHEXA27=327, ++ ePYRA13=313, ePENTA15=315, ePENTA18=318, eHEXA20=320, eHEXA27=327, + ePOLYGONE=400, ePOLYGON2=420, ePOLYEDRE=500, eNONE=0, + eBALL=1101, // no such a type in med.h, it's just a trick + eAllGeoType=-1} EGeometrieElement; + + typedef enum {eMAILLE, eFACE, eARETE, eNOEUD, eNOEUD_ELEMENT, eSTRUCT_ELEMENT} EEntiteMaillage; + + typedef enum {eNO_PFLMOD, eGLOBAL, eCOMPACT} EModeProfil; + + typedef enum {eGRILLE_CARTESIENNE, eGRILLE_POLAIRE, eGRILLE_STANDARD} EGrilleType; + + typedef enum {eCOOR, eCONN, eNOM, eNUM, eFAM, eCOOR_IND1, eCOOR_IND2, eCOOR_IND3} ETable; + + typedef TVector TIntVector; + typedef TVector TFloatVector; + typedef TVector TStringVector; + typedef std::set TStringSet; + + typedef std::map TGeom2Size; + typedef std::map TEntityInfo; + + typedef std::set TGeomSet; + typedef std::map TEntity2GeomSet; + + struct TNameInfo; + typedef SharedPtr PNameInfo; + + struct TMeshInfo; + typedef SharedPtr PMeshInfo; + + struct TFamilyInfo; + typedef SharedPtr PFamilyInfo; + + struct TElemInfo; + typedef SharedPtr PElemInfo; + + struct TNodeInfo; + typedef SharedPtr PNodeInfo; + + struct TPolygoneInfo; + typedef SharedPtr PPolygoneInfo; + + struct TPolyedreInfo; + typedef SharedPtr PPolyedreInfo; + + struct TCellInfo; + typedef SharedPtr PCellInfo; + + struct TBallInfo; + typedef SharedPtr PBallInfo; + + struct TFieldInfo; + typedef SharedPtr PFieldInfo; + + struct TTimeStampInfo; + typedef SharedPtr PTimeStampInfo; + + struct TProfileInfo; + typedef SharedPtr PProfileInfo; + + struct TGaussInfo; + typedef SharedPtr PGaussInfo; + + class TGrilleInfo; + typedef SharedPtr PGrilleInfo; + + struct TTimeStampValueBase; + typedef SharedPtr PTimeStampValueBase; + + struct TWrapper; + typedef SharedPtr PWrapper; + + MEDWRAPPER_EXPORT + TInt + GetDESCLength(); + + MEDWRAPPER_EXPORT + TInt + GetIDENTLength(); + + MEDWRAPPER_EXPORT + TInt + GetNOMLength(); + + MEDWRAPPER_EXPORT + TInt + GetLNOMLength(); + + MEDWRAPPER_EXPORT + TInt + GetPNOMLength(); + + MEDWRAPPER_EXPORT + void + GetVersionRelease(TInt&, TInt&, TInt&); + + MEDWRAPPER_EXPORT + TInt + GetNbConn(EGeometrieElement, EEntiteMaillage, TInt); + + MEDWRAPPER_EXPORT + TInt + GetNbNodes(EGeometrieElement typmai); + + MEDWRAPPER_EXPORT + const TEntity2GeomSet& + GetEntity2GeomSet(); +} + +#endif // MED_Common_HeaderFile diff --cc src/MEDWrapper/MED_Structures.hxx index 8e9beae88,000000000..91387eb90 mode 100644,000000..100644 --- a/src/MEDWrapper/MED_Structures.hxx +++ b/src/MEDWrapper/MED_Structures.hxx @@@ -1,1072 -1,0 +1,1072 @@@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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, or (at your option) any later version. +// +// 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.com +// + +#ifndef MED_Structures_HeaderFile +#define MED_Structures_HeaderFile + +#include "MED_WrapperDef.hxx" +#include "MED_Common.hxx" +#include "MED_Utilities.hxx" +#include "MED_SliceArray.hxx" + +#include + +#ifdef WIN32 +#pragma warning(disable:4251) +#endif + +namespace MED +{ + //--------------------------------------------------------------- + //! Defines a type for managing sequence of strings + typedef TVector TString; + typedef SharedPtr PString; + + //--------------------------------------------------------------- + //! Extract a substring from the sequence of the strings + MEDWRAPPER_EXPORT + std::string + GetString(TInt theId, + TInt theStep, + const TString& theString); + + //--------------------------------------------------------------- + //! Set a substring in the sequence of the strings + MEDWRAPPER_EXPORT + void + SetString(TInt theId, + TInt theStep, + TString& theString, + const std::string& theValue); + + //--------------------------------------------------------------- + //! Set a substring in the sequence of the strings + MEDWRAPPER_EXPORT + void + SetString(TInt theId, + TInt theStep, + TString& theString, + const TString& theValue); + + //--------------------------------------------------------------- + //! Define a parent class for all MEDWrapper classes + struct MEDWRAPPER_EXPORT TBase + { + virtual ~TBase() {} + }; + + //--------------------------------------------------------------- + //! Define a parent class for all named MED entities + struct MEDWRAPPER_EXPORT TNameInfo: virtual TBase + { + TString myName; //!< Keeps its name + virtual std::string GetName() const = 0; //!< Gets its name + virtual void SetName(const std::string& theValue) = 0; //!< Set a new name + virtual void SetName(const TString& theValue) = 0; //!< Set a new name + }; + + //--------------------------------------------------------------- + //! Define a parent class for all MED entities that contains a sequence of numbers + /*! + It defines through corresponding enumeration (EModeSwitch) how the sequence + should be interpreted in C or Fortran mode (eFULL_INTERLACE or eNON_INTERLACE). + */ + struct MEDWRAPPER_EXPORT TModeSwitchInfo: virtual TBase + { + //! To construct instance of the class by default + TModeSwitchInfo(): + myModeSwitch(eFULL_INTERLACE) + {} + + //! To construct instance of the class + TModeSwitchInfo(EModeSwitch theModeSwitch): + myModeSwitch(theModeSwitch) + {} + + EModeSwitch myModeSwitch; //!< Keeps the interlace mode + EModeSwitch GetModeSwitch() const { return myModeSwitch; } + }; + + //--------------------------------------------------------------- + //! Define a base class which represents MED Mesh entity + struct MEDWRAPPER_EXPORT TMeshInfo: virtual TNameInfo + { + TInt myDim; //!< Dimension of the mesh (0, 1, 2 or 3) + TInt GetDim() const { return myDim; } //!< Gets dimension of the mesh + + TInt mySpaceDim; + TInt GetSpaceDim() const { return mySpaceDim; } + + EMaillage myType; //!< Type of the mesh + EMaillage GetType() const { return myType; } //!< Gets type of the mesh + + TString myDesc; //!< Description of the mesh + virtual std::string GetDesc() const = 0; //!< Get description for the mesh + virtual void SetDesc(const std::string& theValue) = 0; //!< Sets description for the mesh + }; + + //--------------------------------------------------------------- + typedef TSlice TIntVecSlice; + typedef TCSlice TCIntVecSlice; + typedef TIntVector TFamAttr; + + //--------------------------------------------------------------- + //! Define a base class which represents MED Family entity + struct MEDWRAPPER_EXPORT TFamilyInfo: virtual TNameInfo + { + PMeshInfo myMeshInfo; //!< A reference to correspondig MED Mesh + //! Get a reference to corresponding MED Mesh + const PMeshInfo& GetMeshInfo() const { return myMeshInfo; } + + TInt myId; //!< An unique index of the MED FAMILY + TInt GetId() const { return myId; } //!< Gets number of the MED FAMILY + void SetId(TInt theId) { myId = theId; } //! Define number of the MED FAMILY + + TInt myNbGroup; //!< Defines number MED Groups connected to + //! Gets number of MED GROUPS the MED FAMILY is bound to + TInt GetNbGroup() const { return myNbGroup; } + + //! Contains sequence of the names for the MED Groups connected to + TString myGroupNames; + //! Gets name of a bound MED GROUP by its number + virtual std::string GetGroupName(TInt theId) const = 0; + //! Sets name of the defined MED GROUP by its number + virtual void SetGroupName(TInt theId, const std::string& theValue) = 0; + + TInt myNbAttr; //!< Defines number of the MED Family attributes + //! Gets number of attached attributes for the MED FAMILY + TInt GetNbAttr() const { return myNbAttr; } + + //! Defines sequence of the indexes of the MED Family attributes + TFamAttr myAttrId; + //! Get MED FAMILY attribute by its number + TInt GetAttrId(TInt theId) const; + //! Set MED FAMILY attribute by its number + void SetAttrId(TInt theId, TInt theVal); + + //! Defines sequence of the values of the MED Family attributes + TFamAttr myAttrVal; + //! Get MED FAMILY attribute by its number + TInt GetAttrVal(TInt theId) const; + //! Set MED FAMILY attribute by its number + void SetAttrVal(TInt theId, TInt theVal); + + //! Defines sequence of the names of the MED Family attributes + TString myAttrDesc; + //! Get value of the MED FAMILY attribute by its number + virtual std::string GetAttrDesc(TInt theId) const = 0; + //! Set value of the MED FAMILY attribute by its number + virtual void SetAttrDesc(TInt theId, const std::string& theValue) = 0; + }; + + //--------------------------------------------------------------- + typedef TIntVector TElemNum; + typedef SharedPtr PElemNum; + + //--------------------------------------------------------------- - //! Define a parent class for all MED entities that describes mesh entites such as nodes and cells. ++ //! Define a parent class for all MED entities that describes mesh entities such as nodes and cells. + struct MEDWRAPPER_EXPORT TElemInfo: virtual TBase + { + PMeshInfo myMeshInfo; //!< A reference to correspondig MED Mesh + //! Get a reference to corresponding MED Mesh + const PMeshInfo& GetMeshInfo() const { return myMeshInfo; } + + TInt myNbElem; // TFloatVecSlice; + typedef TCSlice TCFloatVecSlice; + typedef TFloatVector TNodeCoord; + typedef SharedPtr PNodeCoord; + typedef TFloatVecSlice TCoordSlice; + typedef TCFloatVecSlice TCCoordSlice; + + //--------------------------------------------------------------- + //! Define a base class which represents MED Nodes entity + struct MEDWRAPPER_EXPORT TNodeInfo: + virtual TElemInfo, + virtual TModeSwitchInfo + { + PNodeCoord myCoord; //!< Contains all nodal coordinates + + //! Gives coordinates for mesh node by its number (const version) + TCCoordSlice GetCoordSlice(TInt theId) const; + //! Gives coordinates for mesh node by its number + TCoordSlice GetCoordSlice(TInt theId); + + ERepere mySystem; //!< Defines, which coordinate system is used + //! Get which coordinate system is used for the node describing + ERepere GetSystem() const { return mySystem; } + //! Set coordinate system to be used for the node describing + void SetSystem(ERepere theSystem) { mySystem = theSystem; } + + TString myCoordNames; //!< Contains names for the coordinate dimensions + //! Get name of the coordinate dimension by its order number + virtual std::string GetCoordName(TInt theId) const = 0; + //! Set name of the coordinate dimension by its order number + virtual void SetCoordName(TInt theId, const std::string& theValue) = 0; + + TString myCoordUnits; //!< Contains units for the coordinate dimensions + //! Get name of unit for the coordinate dimension by its order number + virtual std::string GetCoordUnit(TInt theId) const = 0; + //! Set name of unit for the coordinate dimension by its order number + virtual void SetCoordUnit(TInt theId, const std::string& theValue) = 0; + }; + + //--------------------------------------------------------------- + typedef TIntVecSlice TConnSlice; + typedef TCIntVecSlice TCConnSlice; + + //--------------------------------------------------------------- + //! Define a base class which represents MED Cells entity + struct MEDWRAPPER_EXPORT TCellInfo: + virtual TElemInfo, + virtual TModeSwitchInfo + { + EEntiteMaillage myEntity; //!< Defines the MED Entity where the mesh cells belongs to + //! Find out what MED ENTITY the cells belong to + EEntiteMaillage GetEntity() const { return myEntity; } + + EGeometrieElement myGeom; //!< Defines the MED Geometric type of the instance + //! Find out what MED geometrical type the cells belong to + EGeometrieElement GetGeom() const { return myGeom; } + + EConnectivite myConnMode; //!< Defines connectivity mode + //! Find out in what connectivity the cells are writen + EConnectivite GetConnMode() const { return myConnMode; } + + virtual TInt GetConnDim() const = 0; //!< Gives step in the connectivity sequence + + PElemNum myConn; //!< Defines sequence which describe connectivity for each of mesh cell + + //! Gives connectivities for mesh cell by its number (const version) + TCConnSlice GetConnSlice(TInt theElemId) const; + //! Gives connectivities for mesh cell by its number + TConnSlice GetConnSlice(TInt theElemId); + }; + + //--------------------------------------------------------------- + //! Define a base class which represents MED Polygon entity + struct MEDWRAPPER_EXPORT TPolygoneInfo: + virtual TElemInfo + { + //! Defines the MED Entity where the polygons belongs to + EEntiteMaillage myEntity; // MED_FACE|MED_MAILLE + //! Find out what MED ENTITY the MED Polygons belong to + EEntiteMaillage GetEntity() const { return myEntity; } + + //! Defines the MED Geometric type of the instance + EGeometrieElement myGeom; // ePOLYGONE + //! Find out what MED geometrical type the MED Polygons belong to + EGeometrieElement GetGeom() const { return ePOLYGONE; } + + //! Defines connectivity mode + EConnectivite myConnMode; // eNOD|eDESC(eDESC not used) + //! Find out in what connectivity the cells are writen + EConnectivite GetConnMode() const { return myConnMode; } + + PElemNum myConn; //!< Table de connectivities + PElemNum myIndex; //!< Table de indexes + + //! Gives number of the connectivities for the defined polygon + TInt GetNbConn(TInt theElemId) const; + + //! Gives connectivities for polygon by its number (const version) + TCConnSlice GetConnSlice(TInt theElemId) const; + //! Gives connectivities for polygon by its number + TConnSlice GetConnSlice(TInt theElemId); + }; + + //--------------------------------------------------------------- + //! Define a class representing MED_BALL structure element. + /*! + This could be a generic class for any structure element + holding any number of contant and variable attributes + but it's too hard to implement + */ + struct MEDWRAPPER_EXPORT TBallInfo: + virtual TCellInfo + { + TFloatVector myDiameters; + }; + + //--------------------------------------------------------------- + typedef TVector TCConnSliceArr; + typedef TVector TConnSliceArr; + + //--------------------------------------------------------------- + //! Define a base class which represents MED Polyedre entity + struct MEDWRAPPER_EXPORT TPolyedreInfo: + virtual TElemInfo + { + //! Defines the MED Entity where the polyedres belongs to + EEntiteMaillage myEntity; // MED_FACE|MED_MAILLE + //! Find out what MED ENTITY the MED Polyedres belong to + EEntiteMaillage GetEntity() const { return myEntity; } + + //! Defines the MED Geometric type of the instance + EGeometrieElement myGeom; // ePOLYEDRE + //! Find out what MED geometrical type the MED Polyedres belong to + EGeometrieElement GetGeom() const { return ePOLYEDRE; } + + //! Defines connectivity mode + EConnectivite myConnMode; // eNOD|eDESC(eDESC not used) + //! Find out in what connectivity the cells are writen + EConnectivite GetConnMode() const { return myConnMode; } + + PElemNum myConn; //!< Table de connectivities + PElemNum myFaces; //!< Table de faces indexes + PElemNum myIndex; //!< Table de indexes + + //! Gives number of the faces for the defined polyedre (const version) + TInt GetNbFaces(TInt theElemId) const; + //! Gives number of the nodes for the defined polyedre + TInt GetNbNodes(TInt theElemId) const; + + //! Gives sequence of the face connectivities for polyedre by its number (const version) + TCConnSliceArr GetConnSliceArr(TInt theElemId) const; + //! Gives sequence of the face connectivities for polyedre by its number + TConnSliceArr GetConnSliceArr(TInt theElemId); + }; + + //--------------------------------------------------------------- + //! Define a base class which represents MED Field entity + struct MEDWRAPPER_EXPORT TFieldInfo: + virtual TNameInfo + { + PMeshInfo myMeshInfo; //!< A reference to corresponding MED Mesh + //! Get a reference to corresponding MED Mesh + const PMeshInfo& GetMeshInfo() const { return myMeshInfo; } + + ETypeChamp myType; //!< Defines type of MED Field + //! Find out what type of MED FIELD is used + ETypeChamp GetType() const { return myType; } + + TInt myNbComp; //!< Defines number of components stored in the field + //! Get number of components for MED FIELD + TInt GetNbComp() const { return myNbComp; } + + EBooleen myIsLocal; //!< Defines if the MED Field is local + //! Find out if MED FIELD is local or not + EBooleen GetIsLocal() const { return myIsLocal; } + + TInt myNbRef; //!< Defines number of references of the field + //! Find out number of references for the MED FIELD + TInt GetNbRef() const { return myNbRef; } + + TString myCompNames; //!< Contains names for each of MED Field components + //! Get name of the component by its order number + virtual std::string GetCompName(TInt theId) const = 0; + //! Set name for the component by its order number + virtual void SetCompName(TInt theId, const std::string& theValue) = 0; + + TString myUnitNames; //!< Contains units for each of MED Field components + //! Get unit of the component by its order number + virtual std::string GetUnitName(TInt theId) const = 0; + //! Set unit for the component by its order number + virtual void SetUnitName(TInt theId, const std::string& theValue) = 0; + }; + + //--------------------------------------------------------------- + //! Get dimension of the Gauss coordinates for the defined type of mesh cell + MEDWRAPPER_EXPORT + TInt + GetDimGaussCoord(EGeometrieElement theGeom); + + //--------------------------------------------------------------- + //! Get number of referenced nodes for the defined type of mesh cell + MEDWRAPPER_EXPORT + TInt + GetNbRefCoord(EGeometrieElement theGeom); + + //--------------------------------------------------------------- + typedef TFloatVector TWeight; + + //--------------------------------------------------------------- + //! The class represents MED Gauss entity + struct MEDWRAPPER_EXPORT TGaussInfo: + virtual TNameInfo, + virtual TModeSwitchInfo + { + typedef boost::tuple TKey; + typedef boost::tuple TInfo; + struct MEDWRAPPER_EXPORT TLess + { + bool + operator()(const TKey& theLeft, const TKey& theRight) const; + + bool + operator()(const TGaussInfo& theLeft, const TGaussInfo& theRight) const; + }; + + //! Defines, which geometrical type the MED Gauss entity belongs to + EGeometrieElement myGeom; + //! Find out what MED geometrical type the MED GAUSS entity belong to + EGeometrieElement GetGeom() const { return myGeom; } + + //! Contains coordinates for the refereced nodes + TNodeCoord myRefCoord; + + //! Gives coordinates for the referenced node by its number + TCCoordSlice GetRefCoordSlice(TInt theId) const; + //! Gives coordinates for the referenced node by its number + TCoordSlice GetRefCoordSlice(TInt theId); + + //! Contains coordinates for the Gauss points + TNodeCoord myGaussCoord; + + //! Gives coordinates for the Gauss points by its number + TCCoordSlice GetGaussCoordSlice(TInt theId) const; + //! Gives coordinates for the Gauss points by its number + TCoordSlice GetGaussCoordSlice(TInt theId); + + //! Contains wheights for the Gauss points + TWeight myWeight; + + //! Gives number of the referenced nodes + TInt GetNbRef() const { return GetNbRefCoord(GetGeom()); } + + //! Gives dimension of the referenced nodes + TInt GetDim() const { return GetDimGaussCoord(GetGeom()); } + + //! Gives number of the Gauss Points + TInt GetNbGauss() const { return (TInt)(myGaussCoord.size() / GetDim()); } + }; + + //--------------------------------------------------------------- + typedef std::map TGeom2Gauss; + typedef std::map TGeom2NbGauss; + + //--------------------------------------------------------------- + //! Define a base class which represents MED TimeStamp + struct MEDWRAPPER_EXPORT TTimeStampInfo: + virtual TBase + { + PFieldInfo myFieldInfo; //!< A reference to correspondig MED Field + //! Get a reference to corresponding MED Field + const PFieldInfo& GetFieldInfo() const { return myFieldInfo; } + + //! Defines the MED Entity where the MED TimeStamp belongs to + EEntiteMaillage myEntity; + //! Find out to what MED Entity the MED TimeStamp belong to + EEntiteMaillage GetEntity() const { return myEntity; } + + //! Keeps map of number of cells per geometric type where the MED TimeStamp belongs to + TGeom2Size myGeom2Size; + //! Get map of number of cells per geometric type where the MED TimeStamp belongs to + const TGeom2Size& GetGeom2Size() const { return myGeom2Size; } + + TGeom2NbGauss myGeom2NbGauss; //!< Keeps number of the Gauss Points for the MED TimeStamp + TInt GetNbGauss(EGeometrieElement theGeom) const; //!< Gives number of the Gauss Points for the MED TimeStamp + + TInt myNumDt; //!< Keeps number in time for the MED TimeStamp + TInt GetNumDt() const { return myNumDt; } //!< Defines number in time for the MED TimeStamp + + TInt myNumOrd; //!< Keeps number for the MED TimeStamp + TInt GetNumOrd() const { return myNumOrd; } //!< Defines number for the MED TimeStamp + + TFloat myDt; //!< Keeps time for the MED TimeStamp + TFloat GetDt() const { return myDt; } //!< Defines time for the MED TimeStamp + + //! Keeps map of MED Gauss entityes per geometric type + TGeom2Gauss myGeom2Gauss; + //! Gets a map of MED Gauss entityes per geometric type + const TGeom2Gauss& GetGeom2Gauss() const { return myGeom2Gauss; } + + TString myUnitDt; //!< Defines unit for the time for the MED TimeStamp + //! Get unit of time for the MED TimeStamp + virtual std::string GetUnitDt() const = 0; + //! Set unit of time for the MED TimeStamp + virtual void SetUnitDt(const std::string& theValue) = 0; + }; + + //--------------------------------------------------------------- + //! The class represents MED Profile entity + struct MEDWRAPPER_EXPORT TProfileInfo: + virtual TNameInfo + { + typedef std::string TKey; + typedef boost::tuple TInfo; + + EModeProfil myMode; //!< Keeps mode for the MED Profile + //! Find out what mode of MED Profile is used + EModeProfil GetMode() const { return myMode; } + //! Set mode for the MED Profile + void SetMode(EModeProfil theMode) { myMode = theMode; } + + PElemNum myElemNum; //!< Keeps sequence of cell by its number which belong to the profile + //! Get number of mesh elelemts by its order number + TInt GetElemNum(TInt theId) const; + //! Set number of mesh elelemts by its order number + void SetElemNum(TInt theId, TInt theVal); + + //! Find out if the MED Profile defined + bool IsPresent() const { return GetName() != ""; } + + //! Find out size of the MED Profile + TInt GetSize() const { return (TInt)myElemNum->size(); } + }; + + //--------------------------------------------------------------- + //! The class is a helper one. It provide safe and flexible way to get access to values for a MED TimeStamp + struct MEDWRAPPER_EXPORT TMeshValueBase: + virtual TModeSwitchInfo + { + TInt myNbElem; + TInt myNbComp; + TInt myNbGauss; + TInt myStep; + + TMeshValueBase(); + + //! Initialize the class + void + Allocate(TInt theNbElem, + TInt theNbGauss, + TInt theNbComp, + EModeSwitch theMode = eFULL_INTERLACE); + + //! Returns size of the value container + size_t + GetSize() const; + + //! Returns MED interpetation of the value size + size_t + GetNbVal() const; + + //! Returns number of Gauss Points bounded with the value + size_t + GetNbGauss() const; + + //! Returns step inside of the data array + size_t + GetStep() const; + + //! Returns bare pointer on the internal value representation + virtual + unsigned char* + GetValuePtr() = 0; + }; + + //--------------------------------------------------------------- + //! The class is a helper one. It provide safe and flexible way to get access to values for a MED TimeStamp + template + struct TTMeshValue: + virtual TMeshValueBase + { + typedef TValueType TValue; + typedef typename TValueType::value_type TElement; + + typedef TSlice TValueSlice; + typedef TCSlice TCValueSlice; + + typedef TVector TCValueSliceArr; + typedef TVector TValueSliceArr; + + TValue myValue; + + //! Initialize the class + void + Allocate(TInt theNbElem, + TInt theNbGauss, + TInt theNbComp, + EModeSwitch theMode = eFULL_INTERLACE) + { + TMeshValueBase::Allocate(theNbElem, theNbGauss, theNbComp, theMode); + myValue.resize(theNbElem * this->GetStep()); + } + + //! Returns bare pointer on the internal value representation + virtual + unsigned char* + GetValuePtr() + { + return (unsigned char*)&myValue[0]; + } + + //! Returns bare pointer on the internal value representation + virtual + TElement* + GetPointer() + { + return &myValue[0]; + } + + //! Returns bare pointer on the internal value representation + virtual + const TElement* + GetPointer() const + { + return &myValue[0]; + } + + //! Iteration through Gauss Points by their components + TCValueSliceArr + GetGaussValueSliceArr(TInt theElemId) const + { + TCValueSliceArr aValueSliceArr(myNbGauss); + if(GetModeSwitch() == eFULL_INTERLACE){ + TInt anId = theElemId * myStep; + for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TCValueSlice(myValue, std::slice(anId, myNbComp, 1)); + anId += myNbComp; + } + } + else{ + for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TCValueSlice(myValue, std::slice(theElemId, myNbComp, myStep)); + } + } + return aValueSliceArr; + } + + //! Iteration through Gauss Points by their components + TValueSliceArr + GetGaussValueSliceArr(TInt theElemId) + { + TValueSliceArr aValueSliceArr(myNbGauss); + if(GetModeSwitch() == eFULL_INTERLACE){ + TInt anId = theElemId*myStep; + for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TValueSlice(myValue, std::slice(anId, myNbComp, 1)); + anId += myNbComp; + } + } + else{ + for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TValueSlice(myValue, std::slice(theElemId, myNbComp, myStep)); + } + } + return aValueSliceArr; + } + + //! Iteration through components by corresponding Gauss Points + TCValueSliceArr + GetCompValueSliceArr(TInt theElemId) const + { + TCValueSliceArr aValueSliceArr(myNbComp); + if(GetModeSwitch() == eFULL_INTERLACE){ + TInt anId = theElemId*myStep; + for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){ + aValueSliceArr[aCompId] = + TCValueSlice(myValue, std::slice(anId, myNbGauss, myNbComp)); + anId += 1; + } + } + else{ + for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){ + aValueSliceArr[aCompId] = + TCValueSlice(myValue, std::slice(theElemId, myNbGauss, myStep)); + } + } + return aValueSliceArr; + } + + //! Iteration through components by corresponding Gauss Points + TValueSliceArr + GetCompValueSliceArr(TInt theElemId) + { + if(GetModeSwitch() == eFULL_INTERLACE){ + TValueSliceArr aValueSliceArr(myNbComp); + TInt anId = theElemId*myStep; + for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){ + aValueSliceArr[aCompId] = + TValueSlice(myValue, std::slice(anId, myNbGauss, myNbComp)); + anId += 1; + } + return aValueSliceArr; + } + else{ + TValueSliceArr aValueSliceArr(myNbGauss); + for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){ + aValueSliceArr[aGaussId] = + TValueSlice(myValue,std::slice(theElemId, myNbComp, myStep)); + } + return aValueSliceArr; + } + } + }; + + //--------------------------------------------------------------- + typedef TTMeshValue TFloatMeshValue; + typedef TTMeshValue TIntMeshValue; + + //--------------------------------------------------------------- + // Backward compatibility declarations + typedef TFloatVector TValue; + typedef TSlice TValueSlice; + typedef TCSlice TCValueSlice; + + typedef TVector TCValueSliceArr; + typedef TVector TValueSliceArr; + + typedef TFloatMeshValue TMeshValue; + typedef std::map TGeom2Value; + + //--------------------------------------------------------------- + typedef std::map TGeom2Profile; + typedef std::set TGeom; + + //--------------------------------------------------------------- + //! The class is a base class for MED TimeStamp values holder + struct MEDWRAPPER_EXPORT TTimeStampValueBase: + virtual TModeSwitchInfo + { + //! A reference to correspondig MED TimeStamp + PTimeStampInfo myTimeStampInfo; + //!< Get a reference to correspondig MED TimeStamp + const PTimeStampInfo& GetTimeStampInfo() const { return myTimeStampInfo; } + + //! Keeps set of MED EGeometrieElement which contains values for the timestamp + TGeomSet myGeomSet; + const TGeomSet& GetGeomSet() const { return myGeomSet; } + + //! Keeps map of MED Profiles per geometric type + TGeom2Profile myGeom2Profile; + //! Gets a map of MED Profiles per geometric type + const TGeom2Profile& GetGeom2Profile() const { return myGeom2Profile; } + + //! Gets type of the champ + virtual + ETypeChamp + GetTypeChamp() const = 0; + + //! Allocates values for the given geometry + virtual + void + AllocateValue(EGeometrieElement theGeom, + TInt theNbElem, + TInt theNbGauss, + TInt theNbComp, + EModeSwitch theMode = eFULL_INTERLACE) = 0; + + virtual + size_t + GetValueSize(EGeometrieElement theGeom) const = 0; + + virtual + size_t + GetNbVal(EGeometrieElement theGeom) const = 0; + + virtual + size_t + GetNbGauss(EGeometrieElement theGeom) const = 0; + + virtual + unsigned char* + GetValuePtr(EGeometrieElement theGeom) = 0; + }; + + //--------------------------------------------------------------- + //! The class implements a container for MED TimeStamp values + template + struct TTimeStampValue: + virtual TTimeStampValueBase + { + typedef TMeshValueType TTMeshValue; + typedef SharedPtr PTMeshValue; + typedef typename TMeshValueType::TElement TElement; + typedef std::map TTGeom2Value; + + ETypeChamp myTypeChamp; //second; + } + + //! Gets MED TimeStamp values for the given geometric type + PTMeshValue& + GetMeshValuePtr(EGeometrieElement theGeom) + { + myGeomSet.insert(theGeom); + if(myGeom2Value.find(theGeom) == myGeom2Value.end()){ + myGeom2Value[theGeom] = PTMeshValue(new TTMeshValue()); + return myGeom2Value[theGeom]; + } + return myGeom2Value[theGeom]; + } + + //! Gets MED TimeStamp values for the given geometric type (const version) + const TTMeshValue& + GetMeshValue(EGeometrieElement theGeom) const + { + return *(this->GetMeshValuePtr(theGeom)); + } + + //! Gets MED TimeStamp values for the given geometric type + TTMeshValue& + GetMeshValue(EGeometrieElement theGeom) + { + return *(this->GetMeshValuePtr(theGeom)); + } + }; + + //--------------------------------------------------------------- + typedef TTimeStampValue TFloatTimeStampValue; + typedef SharedPtr PFloatTimeStampValue; + + PFloatTimeStampValue MEDWRAPPER_EXPORT + CastToFloatTimeStampValue(const PTimeStampValueBase& theTimeStampValue); + + typedef TTimeStampValue TIntTimeStampValue; + typedef SharedPtr PIntTimeStampValue; + + PIntTimeStampValue MEDWRAPPER_EXPORT + CastToIntTimeStampValue(const PTimeStampValueBase& theTimeStampValue); + + //--------------------------------------------------------------- + template + void + CopyTimeStampValue(SharedPtr > theTimeStampValueFrom, + SharedPtr > theTimeStampValueTo) + { + typedef TTimeStampValue TimeStampValueTypeFrom; + typedef TTimeStampValue TimeStampValueTypeTo; + typedef typename TMeshValueTypeTo::TElement TElementTo; + + typename TimeStampValueTypeFrom::TTGeom2Value& aGeom2Value = theTimeStampValueFrom->myGeom2Value; + typename TimeStampValueTypeFrom::TTGeom2Value::const_iterator anIter = aGeom2Value.begin(); + for(; anIter != aGeom2Value.end(); anIter++){ + const EGeometrieElement& aGeom = anIter->first; + const typename TimeStampValueTypeFrom::TTMeshValue& aMeshValue = *anIter->second; + typename TimeStampValueTypeTo::TTMeshValue& aMeshValue2 = theTimeStampValueTo->GetMeshValue(aGeom); + aMeshValue2.Allocate(aMeshValue.myNbElem, + aMeshValue.myNbGauss, + aMeshValue.myNbComp, + aMeshValue.myModeSwitch); + const typename TimeStampValueTypeFrom::TTMeshValue::TValue& aValue = aMeshValue.myValue; + typename TimeStampValueTypeTo::TTMeshValue::TValue& aValue2 = aMeshValue2.myValue; + TInt aSize = aValue.size(); + for(TInt anId = 0; anId < aSize; anId++) + aValue2[anId] = TElementTo(aValue[anId]); + } + } + + //--------------------------------------------------------------- + template + void + CopyTimeStampValue(SharedPtr > theTimeStampValueFrom, + SharedPtr > theTimeStampValueTo) + { + typedef TTimeStampValue TimeStampValueType; + typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValueFrom->myGeom2Value; + typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin(); + for(; anIter != aGeom2Value.end(); anIter++){ + const EGeometrieElement& aGeom = anIter->first; + const typename TimeStampValueType::TTMeshValue& aMeshValue = *anIter->second; + typename TimeStampValueType::TTMeshValue& aMeshValue2 = theTimeStampValueTo->GetMeshValue(aGeom); + aMeshValue2 = aMeshValue; + } + } + + //--------------------------------------------------------------- + inline + void + CopyTimeStampValueBase(const PTimeStampValueBase& theValueFrom, + const PTimeStampValueBase& theValueTo) + { + if(theValueFrom->GetTypeChamp() == theValueTo->GetTypeChamp()){ + if(theValueFrom->GetTypeChamp() == eFLOAT64) + CopyTimeStampValue(theValueFrom, theValueTo); + else if(theValueFrom->GetTypeChamp() == eINT) + CopyTimeStampValue(theValueFrom, theValueTo); + }else{ + if(theValueFrom->GetTypeChamp() == eFLOAT64 && theValueTo->GetTypeChamp() == eINT) + CopyTimeStampValue(theValueFrom, theValueTo); + else if(theValueFrom->GetTypeChamp() == eINT && theValueTo->GetTypeChamp() == eFLOAT64) + CopyTimeStampValue(theValueFrom, theValueTo); + } + } + + //--------------------------------------------------------------- + // Backward compatibility declarations + typedef TFloatTimeStampValue TTimeStampVal; + typedef PFloatTimeStampValue PTimeStampVal; + + //--------------------------------------------------------------- + typedef std::map TIndexes; + typedef std::map TNames; + + //--------------------------------------------------------------- + //! Define a base class which represents MED Grille (structured mesh) + struct MEDWRAPPER_EXPORT TGrilleInfo: + virtual TModeSwitchInfo + { + PMeshInfo myMeshInfo; + const PMeshInfo& GetMeshInfo() const { return myMeshInfo; } + + TNodeCoord myCoord; //!< Contains all nodal coordinates, now used only for eGRILLE_STANDARD + //! Gives coordinates for mesh nodes (const version) + const TNodeCoord& GetNodeCoord() const; + TNodeCoord& GetNodeCoord(); + //! Gives coordinates for mesh node by its number, array index from 0 + TNodeCoord GetCoord(TInt theId); + //! Gives ids of nodes for mesh cell or sub-cell by its number, array index from 0 + TIntVector GetConn(TInt theId, const bool isSub=false); + + EGrilleType myGrilleType; //!< Defines grille type (eGRILLE_CARTESIENNE,eGRILLE_POLAIRE,eGRILLE_STANDARD) + //!Gets grille type (const version) + const EGrilleType& GetGrilleType() const; + //!Gets grille type + EGrilleType GetGrilleType(); + //!Sets grille type + void SetGrilleType(EGrilleType theGrilleType); + + TString myCoordNames; //!< Contains names for the coordinate dimensions + //! Get name of the coordinate dimension by its order number + virtual std::string GetCoordName(TInt theId) const = 0 ; + //! Set name of the coordinate dimension by its order number + virtual void SetCoordName(TInt theId, const std::string& theValue) = 0; + + TString myCoordUnits; //!< Contains units for the coordinate dimensions + //! Get name of unit for the coordinate dimension by its order number + virtual std::string GetCoordUnit(TInt theId) const = 0; + //! Set name of unit for the coordinate dimension by its order number + virtual void SetCoordUnit(TInt theId, const std::string& theValue) = 0; + + //! Map of index of axes and Table of indexes for certain axe, now used for eGRILLE_CARTESIENNE and eGRILLE_POLAIRE + TIndexes myIndixes; + //!Gets a map of Tables (const version) + const TIndexes& GetMapOfIndexes() const ; + //!Gets a map of Tables + TIndexes& GetMapOfIndexes(); + //!Gets a Table of indexes for certain axe(const version) + const TFloatVector& GetIndexes(TInt theAxisNumber) const; + //!Gets a Table of indexes for certain axe + TFloatVector& GetIndexes(TInt theAxisNumber); + //!Gets a number of indices per axe + TInt GetNbIndexes(TInt theAxisNumber); + + TInt GetNbNodes();//! Return count of all points + TInt GetNbCells();//! Return count of all cells + TInt GetNbSubCells();//! Return count of all entities of + EGeometrieElement GetGeom();//! Return geometry of cells (calculated from mesh dimension) + EGeometrieElement GetSubGeom();//! Return geometry of subcells (calculated from mesh dimension) + EEntiteMaillage GetEntity();//! Return entity (eMAILLE) + EEntiteMaillage GetSubEntity();//! Return sub entity + + /*! + *Vector of grille structure (Example: {3,4,5}, 3 nodes in X axe, 4 nodes in Y axe, ...) + */ + TIntVector myGrilleStructure; + //!Gets grille structure(const version) + const TIntVector& GetGrilleStructure() const; + //!Gets grille structure + TIntVector GetGrilleStructure(); + //!Sets the grille structure of theAxis axe to theNb. + void SetGrilleStructure(TInt theAxis,TInt theNb); + + /*! - *Defines sequence MED Family indexes for corresponding mesh entites ++ *Defines sequence MED Family indexes for corresponding mesh entities + */ + TElemNum myFamNum; + //! Get number of a MED FAMILY by order number of the mesh element + TInt GetFamNum(TInt theId) const; + //! Set number of a MED FAMILY for the mesh element with the order number + void SetFamNum(TInt theId, TInt theVal); + + /*! - *Defines sequence MED Family indexes for sub entites ++ *Defines sequence MED Family indexes for sub entities + */ + TElemNum myFamSubNum; + //! Get number of a MED FAMILY by order number of sub element + TInt GetFamSubNum(TInt theId) const; + //! Set number of a MED FAMILY for theId-th sub element + void SetFamSubNum(TInt theId, TInt theVal); + + /*! + *Defines sequence MED Family indexes for corresponding mesh nodes + */ + TElemNum myFamNumNode; + //! Get number of a MED FAMILY by order number of the mesh node + TInt GetFamNumNode(TInt theId) const; + //! Set number of a MED FAMILY for the mesh node with the order number + void SetFamNumNode(TInt theId, TInt theVal); + }; +} + +#endif // MED_Structures_HeaderFile diff --cc src/MEDWrapper/MED_TStructures.hxx index b687ce369,000000000..d4c708c16 mode 100644,000000..100644 --- a/src/MEDWrapper/MED_TStructures.hxx +++ b/src/MEDWrapper/MED_TStructures.hxx @@@ -1,1193 -1,0 +1,1193 @@@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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, or (at your option) any later version. +// +// 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.com +// + +#ifndef MED_TStructures_HeaderFile +#define MED_TStructures_HeaderFile + +#include "MED_Structures.hxx" + +#ifdef WIN32 +#pragma warning(disable:4250) +#endif - ++#include +namespace MED +{ + //--------------------------------------------------------------- + //! To provide a common way to handle values of MEDWrapper types as native MED types + template + struct TValueHolder + { + TValue& myValue; + TRepresentation myRepresentation; + + TValueHolder(TValue& theValue): + myValue(theValue), + myRepresentation(TRepresentation(theValue)) + {} + + ~TValueHolder() + { + myValue = TValue(myRepresentation); + } + + TRepresentation* + operator& () + { + return &myRepresentation; + } + + operator TRepresentation () const + { + return myRepresentation; + } + + const TValue& + operator() () const + { + return myValue; + } + }; + + //! To customize TValueHolder common template definition for TVector + template + struct TValueHolder, TRepresentation> + { + typedef TVector TValue; + TValue& myValue; + TRepresentation* myRepresentation; + + TValueHolder(TValue& theValue): + myValue(theValue) + { + if(theValue.empty()) + myRepresentation = (TRepresentation*)NULL; + else + myRepresentation = (TRepresentation*)&theValue[0]; + } + + TRepresentation* + operator& () + { + return myRepresentation; + } + }; + + //--------------------------------------------------------------- + struct TTNameInfo: virtual TNameInfo + { + TTNameInfo(const std::string& theValue) + { + myName.resize(GetNOMLength()+1); + SetName(theValue); + } + + virtual + std::string + GetName() const + { + return GetString(0, GetNOMLength(), myName); + } + + virtual + void + SetName(const std::string& theValue) + { + SetString(0, GetNOMLength(), myName, theValue); + } + + virtual + void + SetName(const TString& theValue) + { + SetString(0, GetNOMLength(), myName, theValue); + } + }; + + //--------------------------------------------------------------- + struct TTMeshInfo: + virtual TMeshInfo, + virtual TTNameInfo + { + typedef TTNameInfo TNameInfoBase; + + TTMeshInfo(const PMeshInfo& theInfo): + TNameInfoBase(theInfo->GetName()) + { + myDim = theInfo->GetDim(); + mySpaceDim = theInfo->GetSpaceDim(); + myType = theInfo->GetType(); + + myDesc.resize(GetDESCLength()+1); + SetDesc(theInfo->GetDesc()); + } + + TTMeshInfo(TInt theDim, TInt theSpaceDim, + const std::string& theValue, + EMaillage theType, + const std::string& theDesc): + TNameInfoBase(theValue) + { + myDim = theDim; + mySpaceDim = theSpaceDim; + myType = theType; + + myDesc.resize(GetDESCLength()+1); + SetDesc(theDesc); + } + + virtual + std::string + GetDesc() const + { + return GetString(0, GetDESCLength(), myDesc); + } + + virtual + void + SetDesc(const std::string& theValue) + { + SetString(0, GetDESCLength(), myDesc, theValue); + } + }; + + //--------------------------------------------------------------- + struct TTFamilyInfo: + virtual TFamilyInfo, + virtual TTNameInfo + { + typedef TTNameInfo TNameInfoBase; + + TTFamilyInfo(const PMeshInfo& theMeshInfo, const PFamilyInfo& theInfo): + TNameInfoBase(theInfo->GetName()) + { + myMeshInfo = theMeshInfo; + + myId = theInfo->GetId(); + + myNbGroup = theInfo->GetNbGroup(); + myGroupNames.resize(myNbGroup*GetLNOMLength()+1); + if(myNbGroup){ + for(TInt anId = 0; anId < myNbGroup; anId++){ + SetGroupName(anId,theInfo->GetGroupName(anId)); + } + } + + myNbAttr = theInfo->GetNbAttr(); + myAttrId.resize(myNbAttr); + myAttrVal.resize(myNbAttr); + myAttrDesc.resize(myNbAttr*GetDESCLength()+1); + if(myNbAttr){ + for(TInt anId = 0; anId < myNbAttr; anId++){ + SetAttrDesc(anId,theInfo->GetAttrDesc(anId)); + myAttrVal[anId] = theInfo->GetAttrVal(anId); + myAttrId[anId] = theInfo->GetAttrId(anId); + } + } + } + + TTFamilyInfo(const PMeshInfo& theMeshInfo, + TInt theNbGroup, + TInt theNbAttr, + TInt theId, + const std::string& theValue): + TNameInfoBase(theValue) + { + myMeshInfo = theMeshInfo; + + myId = theId; + + myNbGroup = theNbGroup; + myGroupNames.resize(theNbGroup*GetLNOMLength()+1); + + myNbAttr = theNbAttr; + myAttrId.resize(theNbAttr); + myAttrVal.resize(theNbAttr); + myAttrDesc.resize(theNbAttr*GetDESCLength()+1); + } + + TTFamilyInfo(const PMeshInfo& theMeshInfo, + const std::string& theValue, + TInt theId, + const TStringSet& theGroupNames, + const TStringVector& theAttrDescs, + const TIntVector& theAttrIds, + const TIntVector& theAttrVals): + TNameInfoBase(theValue) + { + myMeshInfo = theMeshInfo; + + myId = theId; + + myNbGroup = (TInt)theGroupNames.size(); + myGroupNames.resize(myNbGroup*GetLNOMLength()+1); + if(myNbGroup){ + TStringSet::const_iterator anIter = theGroupNames.begin(); + for(TInt anId = 0; anIter != theGroupNames.end(); anIter++, anId++){ + const std::string& aVal = *anIter; + SetGroupName(anId,aVal); + } + } + + myNbAttr = (TInt)theAttrDescs.size(); + myAttrId.resize(myNbAttr); + myAttrVal.resize(myNbAttr); + myAttrDesc.resize(myNbAttr*GetDESCLength()+1); + if(myNbAttr){ + for(TInt anId = 0, anEnd = (TInt)theAttrDescs.size(); anId < anEnd; anId++){ + SetAttrDesc(anId,theAttrDescs[anId]); + myAttrVal[anId] = theAttrVals[anId]; + myAttrId[anId] = theAttrIds[anId]; + } + } + } + + virtual + std::string + GetGroupName(TInt theId) const + { + return GetString(theId, GetLNOMLength(), myGroupNames); + } + + virtual + void + SetGroupName(TInt theId, const std::string& theValue) + { + SetString(theId, GetLNOMLength(), myGroupNames, theValue); + } + + virtual + std::string + GetAttrDesc(TInt theId) const + { + return GetString(theId, GetDESCLength(), myAttrDesc); + } + + virtual + void + SetAttrDesc(TInt theId, const std::string& theValue) + { + SetString(theId, GetDESCLength(), myAttrDesc, theValue); + } + }; + + //--------------------------------------------------------------- + struct TTElemInfo: virtual TElemInfo + { + TTElemInfo(const PMeshInfo& theMeshInfo, const PElemInfo& theInfo) + { + myMeshInfo = theMeshInfo; + + myNbElem = theInfo->GetNbElem(); + myFamNum.reset(new TElemNum(myNbElem)); + myIsFamNum = eFAUX; // is set to eVRAI in SetFamNum() + + myIsElemNum = theInfo->IsElemNum(); + if(theInfo->IsElemNum()) + myElemNum.reset(new TElemNum(myNbElem)); + else + myElemNum.reset(new TElemNum()); + + myIsElemNames = theInfo->IsElemNames(); + if(theInfo->IsElemNames()) + myElemNames.reset(new TString(myNbElem*GetPNOMLength() + 1)); + else + myElemNames.reset(new TString()); + + if(theInfo->GetNbElem()){ + for(TInt anId = 0; anId < myNbElem; anId++){ + SetFamNum(anId, theInfo->GetFamNum(anId)); + } + if(theInfo->IsElemNum() == eVRAI){ + for(TInt anId = 0; anId < myNbElem; anId++){ + SetElemNum(anId, theInfo->GetElemNum(anId)); + } + } + if(theInfo->IsElemNames() == eVRAI){ + for(TInt anId = 0; anId < myNbElem; anId++){ + SetElemName(anId,theInfo->GetElemName(anId)); + } + } + } + } + + TTElemInfo(const PMeshInfo& theMeshInfo, + TInt theNbElem, + EBooleen theIsElemNum, + EBooleen theIsElemNames) + { + myMeshInfo = theMeshInfo; + + myNbElem = theNbElem; + myFamNum.reset(new TElemNum(theNbElem)); + myIsFamNum = eFAUX; // is set to eVRAI in SetFamNum() + + myIsElemNum = theIsElemNum; + if(theIsElemNum) + myElemNum.reset(new TElemNum(theNbElem)); + else + myElemNum.reset(new TElemNum()); + + myIsElemNames = theIsElemNames; + if(theIsElemNames) + myElemNames.reset(new TString(theNbElem*GetPNOMLength() + 1)); + else + myElemNames.reset(new TString()); + } + + TTElemInfo(const PMeshInfo& theMeshInfo, + TInt theNbElem, + const TIntVector& theFamilyNums, + const TIntVector& theElemNums, + const TStringVector& theElemNames) + { + myMeshInfo = theMeshInfo; + + myNbElem = theNbElem; + myFamNum.reset(new TElemNum(theNbElem)); + myIsFamNum = eFAUX; // is set to eVRAI in SetFamNum() + + myIsElemNum = theElemNums.size()? eVRAI: eFAUX; + if(myIsElemNum) + myElemNum.reset(new TElemNum(theNbElem)); + else + myElemNum.reset(new TElemNum()); + + myIsElemNames = theElemNames.size()? eVRAI: eFAUX; + if(myIsElemNames) + myElemNames.reset(new TString(theNbElem*GetPNOMLength() + 1)); + else + myElemNames.reset(new TString()); + + if(theNbElem){ + + if(theFamilyNums.size()) + *myFamNum = theFamilyNums; + + if(myIsElemNum) + *myElemNum = theElemNums; + + if(myIsElemNames){ + for(TInt anId = 0; anId < theNbElem; anId++){ + const std::string& aVal = theElemNames[anId]; + SetElemName(anId,aVal); + } + } + } + } + + virtual + std::string + GetElemName(TInt theId) const + { + return GetString(theId,GetPNOMLength(), *myElemNames); + } + + virtual + void + SetElemName(TInt theId, const std::string& theValue) + { + SetString(theId,GetPNOMLength(), *myElemNames, theValue); + } + }; + + //--------------------------------------------------------------- + struct TTNodeInfo: + virtual TNodeInfo, + virtual TTElemInfo + { + typedef TTElemInfo TElemInfoBase; + + TTNodeInfo(const PMeshInfo& theMeshInfo, const PNodeInfo& theInfo): + TNodeInfo(theInfo), + TElemInfoBase(theMeshInfo, theInfo) + { + myModeSwitch = theInfo->GetModeSwitch(); + + mySystem = theInfo->GetSystem(); + + myCoord.reset(new TNodeCoord(*theInfo->myCoord)); + + TInt aSpaceDim = theMeshInfo->GetSpaceDim(); + + myCoordNames.resize(aSpaceDim*GetPNOMLength()+1); + for(TInt anId = 0; anId < aSpaceDim; anId++) + SetCoordName(anId,theInfo->GetCoordName(anId)); + + myCoordUnits.resize(aSpaceDim*GetPNOMLength()+1); + for(TInt anId = 0; anId < aSpaceDim; anId++) + SetCoordUnit(anId,theInfo->GetCoordUnit(anId)); + } + + TTNodeInfo(const PMeshInfo& theMeshInfo, + TInt theNbElem, + EModeSwitch theMode, + ERepere theSystem, + EBooleen theIsElemNum, + EBooleen theIsElemNames): + TModeSwitchInfo(theMode), + TElemInfoBase(theMeshInfo, + theNbElem, + theIsElemNum, + theIsElemNames) + { + mySystem = theSystem; + + myCoord.reset(new TNodeCoord(theNbElem * theMeshInfo->mySpaceDim)); + + myCoordUnits.resize(theMeshInfo->mySpaceDim*GetPNOMLength()+1); + + myCoordNames.resize(theMeshInfo->mySpaceDim*GetPNOMLength()+1); + } + + + TTNodeInfo(const PMeshInfo& theMeshInfo, + const TFloatVector& theNodeCoords, + EModeSwitch theMode, + ERepere theSystem, + const TStringVector& theCoordNames, + const TStringVector& theCoordUnits, + const TIntVector& theFamilyNums, + const TIntVector& theElemNums, + const TStringVector& theElemNames): + TModeSwitchInfo(theMode), + TElemInfoBase(theMeshInfo, + (TInt)theNodeCoords.size()/theMeshInfo->GetDim(), + theFamilyNums, + theElemNums, + theElemNames) + { + mySystem = theSystem; + + myCoord.reset(new TNodeCoord(theNodeCoords)); + + TInt aSpaceDim = theMeshInfo->GetSpaceDim(); + + myCoordNames.resize(aSpaceDim*GetPNOMLength()+1); + if(!theCoordNames.empty()) + for(TInt anId = 0; anId < aSpaceDim; anId++) + SetCoordName(anId,theCoordNames[anId]); + + myCoordUnits.resize(aSpaceDim*GetPNOMLength() + 1); + if(!theCoordUnits.empty()) + for(TInt anId = 0; anId < aSpaceDim; anId++) + SetCoordUnit(anId, theCoordUnits[anId]); + } + + virtual + std::string + GetCoordName(TInt theId) const + { + return GetString(theId,GetPNOMLength(),myCoordNames); + } + + virtual + void + SetCoordName(TInt theId, const std::string& theValue) + { + SetString(theId,GetPNOMLength(),myCoordNames,theValue); + } + + virtual + std::string + GetCoordUnit(TInt theId) const + { + return GetString(theId,GetPNOMLength(),myCoordUnits); + } + + virtual + void + SetCoordUnit(TInt theId, const std::string& theValue) + { + SetString(theId,GetPNOMLength(),myCoordUnits,theValue); + } + }; + + //--------------------------------------------------------------- + struct TTPolygoneInfo: + virtual TPolygoneInfo, + virtual TTElemInfo + { + typedef TTElemInfo TElemInfoBase; + + TTPolygoneInfo(const PMeshInfo& theMeshInfo, const PPolygoneInfo& theInfo): + TElemInfoBase(theMeshInfo,theInfo) + { + myEntity = theInfo->GetEntity(); + myGeom = theInfo->GetGeom(); + + myIndex.reset(new TElemNum(*theInfo->myIndex)); + myConn.reset(new TElemNum(*theInfo->myConn)); + + myConnMode = theInfo->GetConnMode(); + } + + TTPolygoneInfo(const PMeshInfo& theMeshInfo, + EEntiteMaillage theEntity, + EGeometrieElement theGeom, + TInt theNbElem, + TInt theConnSize, + EConnectivite theConnMode, + EBooleen theIsElemNum, + EBooleen theIsElemNames): + TElemInfoBase(theMeshInfo, + theNbElem, + theIsElemNum, + theIsElemNames) + { + myEntity = theEntity; + myGeom = theGeom; + + myIndex.reset(new TElemNum(theNbElem + 1)); + myConn.reset(new TElemNum(theConnSize)); + + myConnMode = theConnMode; + } + + TTPolygoneInfo(const PMeshInfo& theMeshInfo, + EEntiteMaillage theEntity, + EGeometrieElement theGeom, + const TIntVector& theIndexes, + const TIntVector& theConnectivities, + EConnectivite theConnMode, + const TIntVector& theFamilyNums, + const TIntVector& theElemNums, + const TStringVector& theElemNames): + TElemInfoBase(theMeshInfo, + (TInt)theIndexes.size() - 1, + theFamilyNums, + theElemNums, + theElemNames) + { + myEntity = theEntity; + myGeom = theGeom; + + myIndex.reset(new TElemNum(theIndexes)); + myConn.reset(new TElemNum(theConnectivities)); + + myConnMode = theConnMode; + } + }; + + //--------------------------------------------------------------- + struct TTPolyedreInfo: + virtual TPolyedreInfo, + virtual TTElemInfo + { + typedef TTElemInfo TElemInfoBase; + + TTPolyedreInfo(const PMeshInfo& theMeshInfo, const PPolyedreInfo& theInfo): + TElemInfoBase(theMeshInfo,theInfo) + { + myEntity = theInfo->GetEntity(); + myGeom = theInfo->GetGeom(); + + myIndex.reset(new TElemNum(*theInfo->myIndex)); + myFaces.reset(new TElemNum(*theInfo->myFaces)); + myConn.reset(new TElemNum(*theInfo->myConn)); + + myConnMode = theInfo->GetConnMode(); + } + + TTPolyedreInfo(const PMeshInfo& theMeshInfo, + EEntiteMaillage theEntity, + EGeometrieElement theGeom, + TInt theNbElem, + TInt theNbFaces, + TInt theConnSize, + EConnectivite theConnMode, + EBooleen theIsElemNum, + EBooleen theIsElemNames): + TElemInfoBase(theMeshInfo, + theNbElem, + theIsElemNum, + theIsElemNames) + { + myEntity = theEntity; + myGeom = theGeom; + + myIndex.reset(new TElemNum(theNbElem + 1)); + myFaces.reset(new TElemNum(theNbFaces)); + myConn.reset(new TElemNum(theConnSize)); + + myConnMode = theConnMode; + } + + TTPolyedreInfo(const PMeshInfo& theMeshInfo, + EEntiteMaillage theEntity, + EGeometrieElement theGeom, + const TIntVector& theIndexes, + const TIntVector& theFaces, + const TIntVector& theConnectivities, + EConnectivite theConnMode, + const TIntVector& theFamilyNums, + const TIntVector& theElemNums, + const TStringVector& theElemNames): + TElemInfoBase(theMeshInfo, + (TInt)theIndexes.size()-1, + theFamilyNums, + theElemNums, + theElemNames) + { + myEntity = theEntity; + myGeom = theGeom; + + myIndex.reset(new TElemNum(theIndexes)); + myFaces.reset(new TElemNum(theFaces)); + myConn.reset(new TElemNum(theConnectivities)); + + myConnMode = theConnMode; + } + }; + + //--------------------------------------------------------------- + struct TTCellInfo: + virtual TCellInfo, + virtual TTElemInfo + { + typedef TTElemInfo TElemInfoBase; + + TTCellInfo(const PMeshInfo& theMeshInfo, const PCellInfo& theInfo): + TElemInfoBase(theMeshInfo,theInfo) + { + myEntity = theInfo->GetEntity(); + myGeom = theInfo->GetGeom(); + myConnMode = theInfo->GetConnMode(); + + TInt aConnDim = GetNbNodes(myGeom); + TInt aNbConn = GetNbConn(myGeom, myEntity, myMeshInfo->myDim); + myConn.reset(new TElemNum(myNbElem * aNbConn)); + for(TInt anElemId = 0; anElemId < myNbElem; anElemId++){ + TConnSlice aConnSlice = GetConnSlice(anElemId); + TCConnSlice aConnSlice2 = theInfo->GetConnSlice(anElemId); + for(TInt anConnId = 0; anConnId < aConnDim; anConnId++){ + aConnSlice[anConnId] = aConnSlice2[anConnId]; + } + } + } + + TTCellInfo(const PMeshInfo& theMeshInfo, + EEntiteMaillage theEntity, + EGeometrieElement theGeom, + TInt theNbElem, + EConnectivite theConnMode, + EBooleen theIsElemNum, + EBooleen theIsElemNames, + EModeSwitch theMode): + TModeSwitchInfo(theMode), + TElemInfoBase(theMeshInfo, + theNbElem, + theIsElemNum, + theIsElemNames) + { + myEntity = theEntity; + myGeom = theGeom; + + myConnMode = theConnMode; + TInt aNbConn = GetNbConn(theGeom, myEntity, theMeshInfo->myDim); + myConn.reset(new TElemNum(theNbElem * aNbConn)); + } + + TTCellInfo(const PMeshInfo& theMeshInfo, + EEntiteMaillage theEntity, + EGeometrieElement theGeom, + const TIntVector& theConnectivities, + EConnectivite theConnMode, + const TIntVector& theFamilyNums, + const TIntVector& theElemNums, + const TStringVector& theElemNames, + EModeSwitch theMode): + TModeSwitchInfo(theMode), + TElemInfoBase(theMeshInfo, + (TInt)theConnectivities.size() / GetNbNodes(theGeom), + theFamilyNums, + theElemNums, + theElemNames) + { + myEntity = theEntity; + myGeom = theGeom; + + myConnMode = theConnMode; + TInt aConnDim = GetNbNodes(myGeom); + TInt aNbConn = GetNbConn(myGeom, myEntity, myMeshInfo->myDim); + myConn.reset(new TElemNum(myNbElem * aNbConn)); + for(TInt anElemId = 0; anElemId < myNbElem; anElemId++){ + TConnSlice aConnSlice = GetConnSlice(anElemId); + for(TInt anConnId = 0; anConnId < aConnDim; anConnId++){ + aConnSlice[anConnId] = theConnectivities[anElemId*aConnDim + anConnId]; + } + } + } + + virtual + TInt + GetConnDim() const + { + return GetNbConn(myGeom, myEntity, myMeshInfo->myDim); + } + + }; + + //--------------------------------------------------------------- + struct TTBallInfo: + virtual TBallInfo, + virtual TTCellInfo + { + typedef TTCellInfo TCellInfoBase; + + TTBallInfo(const PMeshInfo& theMeshInfo, const PBallInfo& theInfo): + TCellInfoBase::TElemInfoBase(theMeshInfo, theInfo), + TCellInfoBase(theMeshInfo,theInfo) + { + myDiameters = theInfo->myDiameters; + } + + TTBallInfo(const PMeshInfo& theMeshInfo, + TInt theNbElem, + EBooleen theIsElemNum ): + TCellInfoBase::TElemInfoBase(theMeshInfo, + theNbElem, + theIsElemNum, + /*theIsElemNames=*/eFAUX), + TCellInfoBase(theMeshInfo, + eSTRUCT_ELEMENT, + eBALL, + theNbElem, + /*EConnectivite=*/eNOD, + theIsElemNum, + /*theIsElemNames=*/eFAUX, + eFULL_INTERLACE) + { + myDiameters.resize( theNbElem ); + } + + TTBallInfo(const PMeshInfo& theMeshInfo, + const TIntVector& theNodes, + TFloatVector& theDiameters, + const TIntVector& theFamilyNums, + const TIntVector& theElemNums): + TCellInfoBase::TElemInfoBase(theMeshInfo, + (TInt)std::max(theNodes.size(),theDiameters.size() ), + theFamilyNums, + theElemNums, + TStringVector()), + TCellInfoBase(theMeshInfo, + eSTRUCT_ELEMENT, + eBALL, + theNodes, + /*EConnectivite=*/eNOD, + theFamilyNums, + theElemNums, + TStringVector(), + eFULL_INTERLACE) + { + myDiameters.swap( theDiameters ); + } + }; + + //--------------------------------------------------------------- + struct TTFieldInfo: + virtual TFieldInfo, + virtual TTNameInfo + { + typedef TTNameInfo TNameInfoBase; + + TTFieldInfo(const PMeshInfo& theMeshInfo, const PFieldInfo& theInfo): + TNameInfoBase(theInfo->GetName()) + { + myMeshInfo = theMeshInfo; + + myNbComp = theInfo->GetNbComp(); + myCompNames.resize(myNbComp*GetPNOMLength()+1); + for(TInt anId = 0; anId < myNbComp; anId++){ + SetCompName(anId,theInfo->GetCompName(anId)); + } + + myUnitNames.resize(myNbComp*GetPNOMLength()+1); + for(TInt anId = 0; anId < myNbComp; anId++){ + SetUnitName(anId,theInfo->GetUnitName(anId)); + } + + myType = theInfo->GetType(); + + myIsLocal = theInfo->GetIsLocal(); + myNbRef = theInfo->GetNbRef(); + } + + TTFieldInfo(const PMeshInfo& theMeshInfo, + TInt theNbComp, + ETypeChamp theType, + const std::string& theValue, + EBooleen theIsLocal, + TInt theNbRef): + TNameInfoBase(theValue) + { + myMeshInfo = theMeshInfo; + + myNbComp = theNbComp; + myCompNames.resize(theNbComp*GetPNOMLength()+1); + myUnitNames.resize(theNbComp*GetPNOMLength()+1); + + myType = theType; + + myIsLocal = theIsLocal; + myNbRef = theNbRef; + } + + virtual + std::string + GetCompName(TInt theId) const + { + return GetString(theId,GetPNOMLength(),myCompNames); + } + + virtual + void + SetCompName(TInt theId, const std::string& theValue) + { + SetString(theId,GetPNOMLength(),myCompNames,theValue); + } + + virtual + std::string + GetUnitName(TInt theId) const + { + return GetString(theId,GetPNOMLength(),myUnitNames); + } + + virtual + void + SetUnitName(TInt theId, const std::string& theValue) + { + SetString(theId,GetPNOMLength(),myUnitNames,theValue); + } + }; + + //--------------------------------------------------------------- + struct TTGaussInfo: + virtual TGaussInfo, + virtual TTNameInfo + { + typedef TTNameInfo TNameInfoBase; + + TTGaussInfo(const TGaussInfo::TInfo& theInfo, + EModeSwitch theMode): + TModeSwitchInfo(theMode), + TNameInfoBase(boost::get<1>(boost::get<0>(theInfo))) + { + const TGaussInfo::TKey& aKey = boost::get<0>(theInfo); + + myGeom = boost::get<0>(aKey); + myRefCoord.resize(GetNbRef()*GetDim()); + + TInt aNbGauss = boost::get<1>(theInfo); + myGaussCoord.resize(aNbGauss*GetDim()); + myWeight.resize(aNbGauss); + } + }; + + //--------------------------------------------------------------- + struct TTTimeStampInfo: virtual TTimeStampInfo + { + TTTimeStampInfo(const PFieldInfo& theFieldInfo, const PTimeStampInfo& theInfo) + { + myFieldInfo = theFieldInfo; + + myEntity = theInfo->GetEntity(); + myGeom2Size = theInfo->GetGeom2Size(); + + myNumDt = theInfo->GetNumDt(); + myNumOrd = theInfo->GetNumOrd(); + myDt = theInfo->GetDt(); + + myUnitDt.resize(GetPNOMLength()+1); + SetUnitDt(theInfo->GetUnitDt()); + + myGeom2NbGauss = theInfo->myGeom2NbGauss; + myGeom2Gauss = theInfo->GetGeom2Gauss(); + } + + TTTimeStampInfo(const PFieldInfo& theFieldInfo, + EEntiteMaillage theEntity, + const TGeom2Size& theGeom2Size, + const TGeom2NbGauss& theGeom2NbGauss, + TInt theNumDt, + TInt theNumOrd, + TFloat theDt, + const std::string& theUnitDt, + const TGeom2Gauss& theGeom2Gauss) + { + myFieldInfo = theFieldInfo; + + myEntity = theEntity; + myGeom2Size = theGeom2Size; + + myNumDt = theNumDt; + myNumOrd = theNumDt; + myDt = theDt; + + myUnitDt.resize(GetPNOMLength()+1); + SetUnitDt(theUnitDt); + + myGeom2NbGauss = theGeom2NbGauss; + myGeom2Gauss = theGeom2Gauss; + } + + virtual + std::string + GetUnitDt() const + { + return GetString(0,GetPNOMLength(),myUnitDt); + } + + virtual + void + SetUnitDt(const std::string& theValue) + { + SetString(0,GetPNOMLength(),myUnitDt,theValue); + } + }; + + //--------------------------------------------------------------- + struct TTProfileInfo: + virtual TProfileInfo, + virtual TTNameInfo + { + typedef TTNameInfo TNameInfoBase; + + TTProfileInfo(const TProfileInfo::TInfo& theInfo, + EModeProfil theMode): + TNameInfoBase(boost::get<0>(theInfo)) + { + TInt aSize = boost::get<1>(theInfo); + myElemNum.reset(new TElemNum(aSize)); + myMode = aSize > 0? theMode: eNO_PFLMOD; + } + }; + + //--------------------------------------------------------------- + template + struct TTTimeStampValue: virtual TTimeStampValue + { + TTTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + const PTimeStampValueBase& theInfo, + ETypeChamp theTypeChamp) + { + typedef TTimeStampValue TCompatible; + if(TCompatible* aCompatible = dynamic_cast(theInfo.get())){ + this->myTimeStampInfo = theTimeStampInfo; + this->myTypeChamp = theTypeChamp; + this->myGeom2Profile = aCompatible->GetGeom2Profile(); + this->myGeom2Value = aCompatible->myGeom2Value; + this->myGeomSet = aCompatible->GetGeomSet(); + }else + EXCEPTION(std::runtime_error,"TTTimeStampValue::TTTimeStampValue - use incompatible arguments!"); + } + + TTTimeStampValue(const PTimeStampInfo& theTimeStampInfo, + ETypeChamp theTypeChamp, + const TGeom2Profile& theGeom2Profile, + EModeSwitch theMode): + TModeSwitchInfo(theMode) + { + this->myTimeStampInfo = theTimeStampInfo; + + this->myTypeChamp = theTypeChamp; + + this->myGeom2Profile = theGeom2Profile; + + TInt aNbComp = theTimeStampInfo->myFieldInfo->myNbComp; + + const TGeom2Size& aGeom2Size = theTimeStampInfo->GetGeom2Size(); + TGeom2Size::const_iterator anIter = aGeom2Size.begin(); + for(; anIter != aGeom2Size.end(); anIter++){ + const EGeometrieElement& aGeom = anIter->first; + TInt aNbElem = anIter->second; + + MED::PProfileInfo aProfileInfo; + MED::TGeom2Profile::const_iterator anIter = theGeom2Profile.find(aGeom); + if(anIter != theGeom2Profile.end()) + aProfileInfo = anIter->second; + + if(aProfileInfo && aProfileInfo->IsPresent()) + aNbElem = aProfileInfo->GetSize(); + + TInt aNbGauss = theTimeStampInfo->GetNbGauss(aGeom); + + this->GetMeshValue(aGeom).Allocate(aNbElem,aNbGauss,aNbComp); + } + } + + virtual + size_t + GetValueSize(EGeometrieElement theGeom) const + { + return this->GetMeshValue(theGeom).GetSize(); + } + + virtual + size_t + GetNbVal(EGeometrieElement theGeom) const + { + return this->GetMeshValue(theGeom).GetNbVal(); + } + + virtual + size_t + GetNbGauss(EGeometrieElement theGeom) const + { + return this->GetMeshValue(theGeom).GetNbGauss(); + } + + virtual + void + AllocateValue(EGeometrieElement theGeom, + TInt theNbElem, + TInt theNbGauss, + TInt theNbComp, + EModeSwitch theMode = eFULL_INTERLACE) + { + this->GetMeshValue(theGeom).Allocate(theNbElem,theNbGauss,theNbComp,theMode); + } + + virtual + unsigned char* + GetValuePtr(EGeometrieElement theGeom) + { + return this->GetMeshValue(theGeom).GetValuePtr(); + } + }; + + //--------------------------------------------------------------- + struct TTGrilleInfo: + virtual TGrilleInfo + { + TTGrilleInfo(const PMeshInfo& theMeshInfo, + const PGrilleInfo& theInfo) + { + myMeshInfo = theMeshInfo; + + myCoord = theInfo->GetNodeCoord(); + + myGrilleType = theInfo->GetGrilleType(); + + myCoordNames = theInfo->myCoordNames; + + myCoordUnits = theInfo->myCoordUnits; + + myIndixes = theInfo->GetMapOfIndexes(); + + myGrilleStructure = theInfo->GetGrilleStructure(); + + myGrilleType = theInfo->GetGrilleType(); + + myFamNumNode.resize(theInfo->GetNbNodes()); + myFamNumNode = theInfo->myFamNumNode; + + myFamNum = theInfo->myFamNum; + } + + TTGrilleInfo(const PMeshInfo& theMeshInfo, + const EGrilleType& type, + const TInt nnoeuds) + { + myMeshInfo = theMeshInfo; + TInt aSpaceDim = theMeshInfo->GetSpaceDim(); + if(type == eGRILLE_STANDARD){ + myCoord.resize(aSpaceDim*nnoeuds); + myCoordNames.resize(aSpaceDim*GetPNOMLength()+1); + myCoordUnits.resize(aSpaceDim*GetPNOMLength()+1); + } else { //if(type == eGRILLE_CARTESIENNE){ + myCoordNames.resize(aSpaceDim*GetPNOMLength()+aSpaceDim); + myCoordUnits.resize(aSpaceDim*GetPNOMLength()+aSpaceDim); + } + myGrilleStructure.resize(aSpaceDim); + myFamNumNode.resize(nnoeuds); + } + + TTGrilleInfo(const PMeshInfo& theMeshInfo, + const EGrilleType& type) + { + myMeshInfo = theMeshInfo; + TInt aSpaceDim = theMeshInfo->GetSpaceDim(); + if(type == eGRILLE_STANDARD){ + myCoordNames.resize(aSpaceDim*GetPNOMLength()+1); + myCoordUnits.resize(aSpaceDim*GetPNOMLength()+1); + } else {// if(type == eGRILLE_CARTESIENNE){ + myCoordNames.resize(aSpaceDim*GetPNOMLength()+aSpaceDim); + myCoordUnits.resize(aSpaceDim*GetPNOMLength()+aSpaceDim); + } + myGrilleStructure.resize(aSpaceDim); + } + + TTGrilleInfo(const PMeshInfo& theMeshInfo, + const EGrilleType& type, + const MED::TIntVector& nbNodeVec) + { + myMeshInfo = theMeshInfo; + + TInt aSpaceDim = theMeshInfo->GetSpaceDim(); + if(type == eGRILLE_STANDARD){ + myCoordNames.resize(aSpaceDim*GetPNOMLength()+1); + myCoordUnits.resize(aSpaceDim*GetPNOMLength()+1); + } else {// if(type == eGRILLE_CARTESIENNE){ + myCoordNames.resize(aSpaceDim*GetPNOMLength()+aSpaceDim); + myCoordUnits.resize(aSpaceDim*GetPNOMLength()+aSpaceDim); + } + + if(type != eGRILLE_STANDARD) + for(unsigned int aAxe=0;aAxe 0x060100 OCC_CATCH_SIGNALS; - #endif SMESH::UpdateView(); } catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups) diff --cc src/SMESH_I/SMESH_Gen_i.hxx index b67e4f1dd,ef9842298..abeb3777d --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@@ -565,9 -563,9 +563,9 @@@ public // Return an object that previously had an oldID template - typename TInterface::_var_type GetObjectByOldId( const int oldID ) + typename TInterface::_var_type GetObjectByOldId( const int oldID ) { - if ( StudyContext* myStudyContext = GetCurrentStudyContext() ) { + if ( myStudyContext ) { std::string ior = myStudyContext->getIORbyOldId( oldID ); if ( !ior.empty() ) return TInterface::_narrow(GetORB()->string_to_object( ior.c_str() )); diff --cc src/SMESH_I/SMESH_Mesh_i.cxx index c9c4013ad,b598cc0eb..0f56d3035 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@@ -2964,12 -3015,14 +2964,13 @@@ string SMESH_Mesh_i::prepareMeshNameAnd */ //================================================================================ -void SMESH_Mesh_i::ExportToMEDX (const char* file, - CORBA::Boolean auto_groups, - SMESH::MED_VERSION theVersion, - CORBA::Boolean overwrite, - CORBA::Boolean autoDimension) +void SMESH_Mesh_i::ExportMED(const char* file, + CORBA::Boolean auto_groups, + CORBA::Boolean overwrite, + CORBA::Boolean autoDimension) throw(SALOME::SALOME_Exception) { + //MESSAGE("SMESH::MED_VERSION:"<< theVersion); SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); diff --cc src/SMESH_I/SMESH_PythonDump.cxx index d92f15da7,000000000..0052d85e2 mode 100644,000000..100644 --- a/src/SMESH_I/SMESH_PythonDump.cxx +++ b/src/SMESH_I/SMESH_PythonDump.cxx @@@ -1,1382 -1,0 +1,1384 @@@ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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, or (at your option) any later version. +// +// 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.com +// +// File : SMESH_DumpPython.cxx +// Created : Thu Mar 24 17:17:59 2005 +// Author : Julia DOROVSKIKH +// Module : SMESH + +#include "SMESH_PythonDump.hxx" + +#include "SMESH_2smeshpy.hxx" +#include "SMESH_Comment.hxx" +#include "SMESH_Filter_i.hxx" +#include "SMESH_Gen_i.hxx" +#include "SMESH_MeshEditor_i.hxx" + +#include + +#include +#include +#include +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +#include "SMESH_TryCatch.hxx" + +namespace SMESH +{ + + size_t TPythonDump::myCounter = 0; + const char theNotPublishedObjectName[] = "__NOT__Published__Object__"; + + TVar::TVar(CORBA::Double value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); } + TVar::TVar(CORBA::Long value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); } + TVar::TVar(CORBA::Short value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); } + TVar::TVar(const SMESH::double_array& value):myVals(value.length()), myIsList(true) + { + for ( size_t i = 0; i < value.length(); i++) + myVals[i] = SMESH_Comment(value[i]); + } + + TPythonDump:: + TPythonDump():myVarsCounter(0) + { + ++myCounter; + } + TPythonDump:: + ~TPythonDump() + { + if(--myCounter == 0){ + SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); + std::string aString = myStream.str(); + TCollection_AsciiString aCollection(Standard_CString(aString.c_str())); + if(!aCollection.IsEmpty()) + { + const std::string & objEntry = SMESH_Gen_i::GetSMESHGen()->GetLastObjEntry(); + if ( !objEntry.empty() ) + aCollection += (TVar::ObjPrefix() + objEntry ).c_str(); + aSMESHGen->AddToPythonScript(aCollection); + if(MYDEBUG) MESSAGE(aString); + // prevent misuse of already treated variables + aSMESHGen->UpdateParameters(CORBA::Object_var().in(),""); + } + } + } + + TPythonDump& //!< store a variable value. Write either a value or '$varID$' + TPythonDump:: + operator<<(const TVar& theVarValue) + { + const std::vector< int >& varIDs = SMESH_Gen_i::GetSMESHGen()->GetLastParamIndices(); + if ( theVarValue.myIsList ) + { + myStream << "[ "; + for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i ) + { + if ( myVarsCounter < (int)varIDs.size() && varIDs[ myVarsCounter ] >= 0 ) + myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote(); + else + myStream << theVarValue.myVals[i-1]; + if ( i < theVarValue.myVals.size() ) + myStream << ", "; + ++myVarsCounter; + } + myStream << " ]"; + } + else + { + if ( myVarsCounter < (int)varIDs.size() && varIDs[ myVarsCounter ] >= 0 ) + myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote(); + else + myStream << theVarValue.myVals[0]; + ++myVarsCounter; + } + return *this; + } + + TPythonDump& + TPythonDump:: + operator<<(long int theArg){ + myStream< + void DumpArray(const TArray& theArray, TPythonDump & theStream) + { + if ( theArray.length() == 0 ) + { + theStream << "[]"; + } + else + { + theStream << "[ "; + for (CORBA::ULong i = 1; i <= theArray.length(); i++) { + theStream << theArray[i-1]; + if ( i < theArray.length() ) + theStream << ", "; + } + theStream << " ]"; + } + } + + TPythonDump& + TPythonDump::operator<<(const SMESH::long_array& theArg) + { + DumpArray( theArg, *this ); + return *this; + } + + TPythonDump& + TPythonDump::operator<<(const SMESH::double_array& theArg) + { + DumpArray( theArg, *this ); + return *this; + } + + TPythonDump& + TPythonDump::operator<<(const SMESH::nodes_array& theArg) + { + DumpArray( theArg, *this ); + return *this; + } + + TPythonDump& + TPythonDump::operator<<(const SMESH::string_array& theArray) + { + myStream << "[ "; + for ( CORBA::ULong i = 1; i <= theArray.length(); i++ ) { + myStream << "'" << theArray[i-1] << "'"; + if ( i < theArray.length() ) + myStream << ", "; + } + myStream << " ]"; + return *this; + } + + TPythonDump& + TPythonDump:: + operator<<(SALOMEDS::SObject_ptr aSObject) + { + if ( !aSObject->_is_nil() ) { + CORBA::String_var entry = aSObject->GetID(); + myStream << entry.in(); + } + else { + myStream << theNotPublishedObjectName; + } + return *this; + } + + TPythonDump& + TPythonDump:: + operator<<(CORBA::Object_ptr theArg) + { + SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); + SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg); + if(!aSObject->_is_nil()) { + CORBA::String_var id = aSObject->GetID(); + myStream << id; + } else if ( !CORBA::is_nil(theArg)) { + if ( aSMESHGen->CanPublishInStudy( theArg )) // not published SMESH object + myStream << "smeshObj_" << size_t(theArg); + else + myStream << theNotPublishedObjectName; + } + else + myStream << "None"; + return *this; + } + + TPythonDump& + TPythonDump:: + operator<<(SMESH::SMESH_Hypothesis_ptr theArg) + { + SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg); + if(aSObject->_is_nil() && !CORBA::is_nil(theArg)) + myStream << "hyp_" << theArg->GetId(); + else + *this << aSObject; + return *this; + } + + TPythonDump& + TPythonDump:: + operator<<(SMESH::SMESH_IDSource_ptr theArg) + { + if ( CORBA::is_nil( theArg ) ) + return *this << "None"; + SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); + SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg); + if(!aSObject->_is_nil()) + { + return *this << aSObject; + } + if ( SMESH::Filter_i* filter = SMESH::DownCast( theArg )) + { + return *this << filter; + } + if ( SMESH_MeshEditor_i::IsTemporaryIDSource( theArg )) + { + SMESH::SMESH_Mesh_var mesh = theArg->GetMesh(); + SMESH::long_array_var anElementsId = theArg->GetIDs(); + SMESH::array_of_ElementType_var types = theArg->GetTypes(); + SMESH::ElementType type = types->length() ? types[0] : SMESH::ALL; + SALOMEDS::SObject_wrap meshSO = SMESH_Gen_i::ObjectToSObject(mesh); + if ( meshSO->_is_nil() ) // don't waste memory for dumping not published objects + return *this << mesh << ".GetIDSource([], " << type << ")"; + else + return *this << mesh << ".GetIDSource(" << anElementsId << ", " << type << ")"; + } + return *this << theNotPublishedObjectName; + } + + TPythonDump& + TPythonDump:: + operator<<(SMESH::FilterLibrary_i* theArg) + { + myStream<<"aFilterLibrary"<GetFunctorType(); + switch(aFunctorType) { + case FT_AspectRatio: myStream<< "aAspectRatio"; break; + case FT_AspectRatio3D: myStream<< "aAspectRatio3D"; break; + case FT_Warping: myStream<< "aWarping"; break; + case FT_MinimumAngle: myStream<< "aMinimumAngle"; break; + case FT_Taper: myStream<< "aTaper"; break; + case FT_Skew: myStream<< "aSkew"; break; + case FT_Area: myStream<< "aArea"; break; + case FT_Volume3D: myStream<< "aVolume3D"; break; + case FT_MaxElementLength2D: myStream<< "aMaxElementLength2D"; break; + case FT_MaxElementLength3D: myStream<< "aMaxElementLength3D"; break; + case FT_FreeBorders: myStream<< "aFreeBorders"; break; + case FT_FreeEdges: myStream<< "aFreeEdges"; break; + case FT_FreeNodes: myStream<< "aFreeNodes"; break; + case FT_FreeFaces: myStream<< "aFreeFaces"; break; + case FT_EqualNodes: myStream<< "aEqualNodes"; break; + case FT_EqualEdges: myStream<< "aEqualEdges"; break; + case FT_EqualFaces: myStream<< "aEqualFaces"; break; + case FT_EqualVolumes: myStream<< "aEqualVolumes"; break; + case FT_MultiConnection: myStream<< "aMultiConnection"; break; + case FT_MultiConnection2D: myStream<< "aMultiConnection2D"; break; + case FT_Length: myStream<< "aLength"; break; + case FT_Length2D: myStream<< "aLength2D"; break; ++ case FT_Deflection2D: myStream<< "aDeflection2D"; break; + case FT_NodeConnectivityNumber:myStream<< "aNodeConnectivityNumber";break; + case FT_BelongToMeshGroup: myStream<< "aBelongToMeshGroup"; break; + case FT_BelongToGeom: myStream<< "aBelongToGeom"; break; + case FT_BelongToPlane: myStream<< "aBelongToPlane"; break; + case FT_BelongToCylinder: myStream<< "aBelongToCylinder"; break; + case FT_BelongToGenSurface: myStream<< "aBelongToGenSurface"; break; + case FT_LyingOnGeom: myStream<< "aLyingOnGeom"; break; + case FT_RangeOfIds: myStream<< "aRangeOfIds"; break; + case FT_BadOrientedVolume: myStream<< "aBadOrientedVolume"; break; + case FT_BareBorderVolume: myStream<< "aBareBorderVolume"; break; + case FT_BareBorderFace: myStream<< "aBareBorderFace"; break; + case FT_OverConstrainedVolume: myStream<< "aOverConstrainedVolume"; break; + case FT_OverConstrainedFace: myStream<< "aOverConstrainedFace"; break; + case FT_LinearOrQuadratic: myStream<< "aLinearOrQuadratic"; break; + case FT_GroupColor: myStream<< "aGroupColor"; break; + case FT_ElemGeomType: myStream<< "aElemGeomType"; break; + case FT_EntityType: myStream<< "aEntityType"; break; + case FT_CoplanarFaces: myStream<< "aCoplanarFaces"; break; + case FT_BallDiameter: myStream<< "aBallDiameter"; break; + case FT_ConnectedElements: myStream<< "aConnectedElements"; break; + case FT_LessThan: myStream<< "aLessThan"; break; + case FT_MoreThan: myStream<< "aMoreThan"; break; + case FT_EqualTo: myStream<< "aEqualTo"; break; + case FT_LogicalNOT: myStream<< "aLogicalNOT"; break; + case FT_LogicalAND: myStream<< "aLogicalAND"; break; + case FT_LogicalOR: myStream<< "aLogicalOR"; break; + case FT_Undefined: myStream<< "anUndefined"; break; + //default: -- commented to have a compilation warning + } + myStream<GetMeshId() : -1 ); return *this; + } + + TPythonDump& TPythonDump::operator<<(const TCollection_AsciiString & theStr) + { + myStream << theStr; return *this; + } + + TPythonDump& TPythonDump::operator<<(const SMESH::AxisStruct & theAxis) + { + *this << "SMESH.AxisStruct( " + << TVar( theAxis.x ) << ", " + << TVar( theAxis.y ) << ", " + << TVar( theAxis.z ) << ", " + << TVar( theAxis.vx ) << ", " + << TVar( theAxis.vy ) << ", " + << TVar( theAxis.vz ) << " )"; + return *this; + } + + TPythonDump& TPythonDump::operator<<(const SMESH::DirStruct & theDir) + { + const SMESH::PointStruct & P = theDir.PS; + *this << "SMESH.DirStruct( SMESH.PointStruct ( " + << TVar( P.x ) << ", " + << TVar( P.y ) << ", " + << TVar( P.z ) << " ))"; + return *this; + } + + TPythonDump& TPythonDump::operator<<(const SMESH::PointStruct & P) + { + *this << "SMESH.PointStruct ( " + << TVar( P.x ) << ", " + << TVar( P.y ) << ", " + << TVar( P.z ) << " )"; + return *this; + } + + TPythonDump& TPythonDump::operator<<(const SMESH::ListOfGroups& theList) + { + DumpArray( theList, *this ); + return *this; + } + TPythonDump& TPythonDump::operator<<(const SMESH::ListOfGroups * theList) + { + DumpArray( *theList, *this ); + return *this; + } + TPythonDump& TPythonDump::operator<<(const GEOM::ListOfGO& theList) + { + DumpArray( theList, *this ); + return *this; + } + TPythonDump& TPythonDump::operator<<(const GEOM::ListOfGBO& theList) + { + DumpArray( theList, *this ); + return *this; + } + TPythonDump& TPythonDump::operator<<(const SMESH::ListOfIDSources& theList) + { + DumpArray( theList, *this ); + return *this; + } + TPythonDump& TPythonDump::operator<<(const SMESH::CoincidentFreeBorders& theCFB) + { + // dump CoincidentFreeBorders as a list of lists, each enclosed list + // contains node IDs of a group of coincident free borders where + // each consequent triple of IDs describe a free border: (n1, n2, nLast) + // For example [[1, 2, 10, 20, 21, 40], [11, 12, 15, 55, 54, 41]] describes + // two groups of coincident free borders, each group including two borders + + myStream << "["; + for ( CORBA::ULong i = 0; i < theCFB.coincidentGroups.length(); ++i ) + { + const SMESH::FreeBordersGroup& aGRP = theCFB.coincidentGroups[ i ]; + if ( i ) myStream << ","; + myStream << "["; + for ( CORBA::ULong iP = 0; iP < aGRP.length(); ++iP ) + { + const SMESH::FreeBorderPart& aPART = aGRP[ iP ]; + if ( 0 <= aPART.border && aPART.border < (CORBA::Long)theCFB.borders.length() ) + { + if ( iP ) myStream << ", "; + const SMESH::FreeBorder& aBRD = theCFB.borders[ aPART.border ]; + myStream << aBRD.nodeIDs[ aPART.node1 ] << ","; + myStream << aBRD.nodeIDs[ aPART.node2 ] << ","; + myStream << aBRD.nodeIDs[ aPART.nodeLast ]; + } + } + myStream << "]"; + } + myStream << "]"; + + return *this; + } + + const char* TPythonDump::NotPublishedObjectName() + { + return theNotPublishedObjectName; + } + + TCollection_AsciiString myLongStringStart( "TPythonDump::LongStringStart" ); + TCollection_AsciiString myLongStringEnd ( "TPythonDump::LongStringEnd" ); + + //================================================================================ + /*! + * \brief Return marker of long string literal beginning + * \param type - a name of functionality producing the string literal + * \retval TCollection_AsciiString - the marker string to be written into + * a raw python script + */ + //================================================================================ + + TCollection_AsciiString TPythonDump::LongStringStart(const char* type) + { + return + myLongStringStart + + (Standard_Integer) strlen(type) + + " " + + (char*) type; + } + + //================================================================================ + /*! + * \brief Return marker of long string literal end + * \retval TCollection_AsciiString - the marker string to be written into + * a raw python script + */ + //================================================================================ + + TCollection_AsciiString TPythonDump::LongStringEnd() + { + return myLongStringEnd; + } + + //================================================================================ + /*! + * \brief Cut out a long string literal from a string + * \param theText - text possibly containing string literals + * \param theFrom - position in the text to search from + * \param theLongString - the retrieved literal + * \param theStringType - a name of functionality produced the literal + * \retval bool - true if a string literal found + * + * The literal is removed from theText; theFrom points position right after + * the removed literal + */ + //================================================================================ + + bool TPythonDump::CutoutLongString( TCollection_AsciiString & theText, + int & theFrom, + TCollection_AsciiString & theLongString, + TCollection_AsciiString & theStringType) + { + if ( theFrom < 1 || theFrom > theText.Length() ) + return false; + + // ...script \ beg marker \ \ type \ literal \ end marker \ script... + // "theText myLongStringStart7 Pattern!!! SALOME Mesh Pattern file myLongStringEndtextEnd" + // 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 + // 0 1 2 3 4 5 6 7 8 + + theFrom = theText.Location( myLongStringStart, theFrom, theText.Length() ); // = 09 + if ( !theFrom ) + return false; + + // find where literal begins + int literalBeg = theFrom + myLongStringStart.Length(); // = 26 + char* typeLenStr = (char*) theText.ToCString() + literalBeg - 1; // = "7 Pattern!!! SALO...." + int typeLen = atoi ( typeLenStr ); // = 7 + while ( *typeLenStr != ' ' ) { // look for ' ' after typeLen + literalBeg++; // 26 -> 27 + typeLenStr++; + } + literalBeg += typeLen + 1; // = 35 + if ( literalBeg > theText.Length() ) + return false; + + // where literal ends (i.e. end marker begins) + int literalEnd = theText.Location( myLongStringEnd, literalBeg, theText.Length() ); // = 64 + if ( !literalEnd ) + literalEnd = theText.Length(); + + // literal + theLongString = theText.SubString( literalBeg, literalEnd - 1); // "!!! SALOME Mesh Pattern file " + // type + theStringType = theText.SubString( literalBeg - typeLen, literalBeg - 1 ); // "Pattern" + // cut off literal + literalEnd += myLongStringEnd.Length(); // = 79 + TCollection_AsciiString textEnd = theText.SubString( literalEnd, theText.Length() ); // "textE..." + theText = theText.SubString( 1, theFrom - 1 ) + textEnd; + + return true; + } + + void printException( const char* text ) + { +#ifdef _DEBUG_ + cout << "Exception in SMESH_Gen_i::DumpPython(): " << text << endl; +#endif + } +} + +//======================================================================= +//function : RemoveTabulation +//purpose : +//======================================================================= +void RemoveTabulation( TCollection_AsciiString& theScript ) +{ + std::string aString( theScript.ToCString() ); + std::string::size_type aPos = 0; + while( aPos < aString.length() ) + { + aPos = aString.find( "\n\t", aPos ); + if( aPos == std::string::npos ) + break; + aString.replace( aPos, 2, "\n" ); + aPos++; + } + theScript = aString.c_str(); +} + +//======================================================================= +//function : DumpPython +//purpose : +//======================================================================= +Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile, + CORBA::Boolean& isValidScript) +{ + SALOMEDS::Study_var aStudy = getStudyServant(); + if (CORBA::is_nil(aStudy)) + return new Engines::TMPFile(0); + + CORBA::String_var compDataType = ComponentDataType(); + SALOMEDS::SObject_wrap aSO = aStudy->FindComponent( compDataType.in() ); + if (CORBA::is_nil(aSO)) + return new Engines::TMPFile(0); + + // Map study entries to object names + Resource_DataMapOfAsciiStringAsciiString aMap; + Resource_DataMapOfAsciiStringAsciiString aMapNames; + + SALOMEDS::ChildIterator_wrap Itr = aStudy->NewChildIterator(aSO); + for (Itr->InitEx(true); Itr->More(); Itr->Next()) { + SALOMEDS::SObject_wrap aValue = Itr->Value(); + CORBA::String_var anID = aValue->GetID(); + CORBA::String_var aName = aValue->GetName(); + TCollection_AsciiString aGUIName ( (char*) aName.in() ); + TCollection_AsciiString anEntry ( (char*) anID.in() ); + if (aGUIName.Length() > 0) { + aMapNames.Bind( anEntry, aGUIName ); + aMap.Bind( anEntry, aGUIName ); + } + } + + // Get trace of restored study + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + SALOMEDS::GenericAttribute_wrap anAttr = + aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject"); + + SALOMEDS::AttributePythonObject_var pyAttr = + SALOMEDS::AttributePythonObject::_narrow(anAttr); + CORBA::String_var oldValue = pyAttr->GetObject(); + TCollection_AsciiString aSavedTrace (oldValue.in()); + + // Add trace of API methods calls and replace study entries by names + TCollection_AsciiString aScript; + aScript += DumpPython_impl(aMap, aMapNames, isPublished, isMultiFile, + myIsHistoricalPythonDump, isValidScript, aSavedTrace); + + int aLen = aScript.Length(); + unsigned char* aBuffer = new unsigned char[aLen+1]; + strcpy((char*)aBuffer, aScript.ToCString()); + + CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer; + Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1); + + bool hasNotPublishedObjects = aScript.Location( SMESH::theNotPublishedObjectName, 1, aLen); + isValidScript = isValidScript && !hasNotPublishedObjects; + + return aStreamFile._retn(); +} + +//============================================================================= +/*! + * AddToPythonScript + */ +//============================================================================= +void SMESH_Gen_i::AddToPythonScript (const TCollection_AsciiString& theString) +{ + if (myPythonScript.IsNull()) { + myPythonScript = new TColStd_HSequenceOfAsciiString; + } + myPythonScript->Append(theString); +} + +//============================================================================= +/*! + * RemoveLastFromPythonScript + */ +//============================================================================= +void SMESH_Gen_i::RemoveLastFromPythonScript() +{ + if (!myPythonScript.IsNull()) { + int aLen = myPythonScript->Length(); + myPythonScript->Remove(aLen); + } +} + +//======================================================================= +//function : SavePython +//purpose : +//======================================================================= +void SMESH_Gen_i::SavePython() +{ + // Dump trace of API methods calls + TCollection_AsciiString aScript = GetNewPythonLines(); + + // Check contents of PythonObject attribute + CORBA::String_var compDataType = ComponentDataType(); + SALOMEDS::SObject_wrap aSO = getStudyServant()->FindComponent( compDataType.in() ); + SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder(); + SALOMEDS::GenericAttribute_wrap anAttr = + aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject"); + + SALOMEDS::AttributePythonObject_var pyAttr = + SALOMEDS::AttributePythonObject::_narrow(anAttr); + CORBA::String_var oldValue = pyAttr->GetObject(); + TCollection_AsciiString oldScript (oldValue.in()); + + if (oldScript.Length() > 0) { + oldScript += "\n"; + oldScript += aScript; + } else { + oldScript = aScript; + } + + // Store in PythonObject attribute + pyAttr->SetObject(oldScript.ToCString(), 1); + + // Clean trace of API methods calls + CleanPythonTrace(); +} + + +// impl + + +//============================================================================= +/*! + * FindEntries: Returns a sequence of start/end positions of entries in the string + */ +//============================================================================= +Handle(TColStd_HSequenceOfInteger) FindEntries (TCollection_AsciiString& theString) +{ + Handle(TColStd_HSequenceOfInteger) aSeq = new TColStd_HSequenceOfInteger; + Standard_Integer aLen = theString.Length(); + Standard_Boolean isFound = Standard_False; + + char* arr = (char*) theString.ToCString(); + Standard_Integer i = 0, j; + + while(i < aLen) { + int c = (int)arr[i]; + j = i+1; + if ( isdigit( c )) { //Is digit? + + isFound = Standard_False; + while((j < aLen) && ( isdigit(c) || c == ':' )) { //Check if it is an entry + c = (int)arr[j++]; + if(c == ':') isFound = Standard_True; + } + + if (isFound) { + int prev = (i < 1) ? 0 : (int)arr[i - 1]; + // to distinguish from a sketcher command: + // last char should be a digit, not ":", + // previous char should not be '"'. + if (arr[j-2] != ':' && prev != '"') { + aSeq->Append(i+1); // +1 because AsciiString starts from 1 + aSeq->Append(j-1); + } + } + } + + i = j; + } + + return aSeq; +} + +namespace { + + //================================================================================ + /*! + * \brief Make a string be a valid python name + * \param aName - a string to fix + * \retval bool - true if aName was not modified + */ + //================================================================================ + + bool fixPythonName(TCollection_AsciiString & aName) + { + bool isValidName = true; + int nbUnderscore = 0; + int p; + // replace not allowed chars by underscore + const char* name = aName.ToCString(); + for ( p = 0; name[p]; ++p ) { + if ( !isalnum( name[p] ) && name[p] != '_' ) + { + if ( p == 0 || p+1 == aName.Length() || name[p-1] == '_') + { + aName.Remove( p+1, 1 ); // remove __ and _ from the start and the end + --p; + name = aName.ToCString(); + } + else + { + aName.SetValue( p+1, '_'); + nbUnderscore++; + } + isValidName = false; + } + } + // aName must not start with a digit + if ( aName.IsIntegerValue() ) { + aName.Insert( 1, 'a' ); + isValidName = false; + } + // shorten names like CartesianParameters3D_400_400_400_1000000_1 + const int nbAllowedUnderscore = 3; /* changed from 2 to 3 by an user request + posted to SALOME Forum */ + if ( aName.Length() > 20 && nbUnderscore > nbAllowedUnderscore ) + { + p = aName.Location( "_", 20, aName.Length()); + if ( p > 1 ) + aName.Trunc( p-1 ); + } + return isValidName; + } + + //================================================================================ + /*! + * \brief Return Python module names of available plug-ins. + */ + //================================================================================ + + std::vector getPluginNames() + { + std::vector pluginNames; + std::vector< std::string > xmlPaths = SMESH_Gen::GetPluginXMLPaths(); + LDOMParser xmlParser; + for ( size_t i = 0; i < xmlPaths.size(); ++i ) + { + bool error = xmlParser.parse( xmlPaths[i].c_str() ); + if ( error ) + { + TCollection_AsciiString data; + INFOS( xmlParser.GetError(data) ); + continue; + } + // + LDOM_Document xmlDoc = xmlParser.getDocument(); + LDOM_NodeList nodeList = xmlDoc.getElementsByTagName( "meshers-group" ); + for ( int i = 0; i < nodeList.getLength(); ++i ) + { + LDOM_Node node = nodeList.item( i ); + LDOM_Element& elem = (LDOM_Element&) node; + LDOMString idlModule = elem.getAttribute( "idl-module" ); + if ( strlen( idlModule.GetString() ) > 0 ) + pluginNames.push_back( idlModule.GetString() ); + } + } + return pluginNames; + } +} + +//================================================================================ +/*! + * \brief Createa a Dump Python script + * \param [in,out] theObjectNames - map of an entry to a study and python name + * \param [in] theNames - - map of an entry to a study name + * \param [in] isPublished - \c true if dump of object publication in study is needed + * \param [in] isMultiFile - \c true if dump of each module goes to a separate file + * \param [in] isHistoricalDump - \c true if removed object should be dumped + * \param [out] aValidScript - returns \c true if the returned script seems valid + * \param [in,out] theSavedTrace - the dump stored in the study. It's cleared to + * decrease memory usage. + * \return TCollection_AsciiString - the result dump script. + */ +//================================================================================ + +TCollection_AsciiString SMESH_Gen_i::DumpPython_impl + (Resource_DataMapOfAsciiStringAsciiString& theObjectNames, + Resource_DataMapOfAsciiStringAsciiString& theNames, + bool isPublished, + bool isMultiFile, + bool isHistoricalDump, + bool& aValidScript, + TCollection_AsciiString& theSavedTrace) +{ + SMESH_TRY; + + const TCollection_AsciiString aSmeshpy ( SMESH_2smeshpy::SmeshpyName() ); + const TCollection_AsciiString aSMESHGen( SMESH_2smeshpy::GenName() ); + const TCollection_AsciiString anOldGen ( SMESH::TPythonDump::SMESHGenName() ); + const TCollection_AsciiString helper; // to comfortably append C strings to TCollection_AsciiString + const TCollection_AsciiString tab( isMultiFile ? "\t" : "" ), nt = helper + "\n" + tab; + + std::list< TCollection_AsciiString > lines; // lines of a script + std::list< TCollection_AsciiString >::iterator linesIt; + + if ( isPublished ) + lines.push_back( aSMESHGen + " = smeshBuilder.New()" ); + else + lines.push_back( aSMESHGen + " = smeshBuilder.New(False)" ); + lines.push_back( helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()" ); + lines.push_back( helper + "aMeasurements = " + aSMESHGen + ".CreateMeasurements()" ); + + // Treat dump trace of restored study + if (theSavedTrace.Length() > 0) + { + linesIt = --lines.end(); + // Split theSavedTrace into lines + int from = 1, end = theSavedTrace.Length(), to; + while ( from < end && ( to = theSavedTrace.Location( "\n", from, end ))) + { + if ( theSavedTrace.ToCString()[from-1] == '\t' ) + ++from; + if ( to != from ) + lines.push_back( theSavedTrace.SubString( from, to - 1 )); + from = to + 1; + } + // For the conversion of IDL API calls -> smeshBuilder.py API, "smesh" standing for SMESH_Gen + // was replaces with "smeshgen" (==TPythonDump::SMESHGenName()). + // Change "smesh" -> "smeshgen" in the trace saved before passage to smeshBuilder.py API + bool isNewVersion = + theSavedTrace.Location( anOldGen + ".", 1, theSavedTrace.Length() ); + theSavedTrace.Clear(); + if ( !isNewVersion ) + { + const TCollection_AsciiString aSmeshCall ( "smesh." ), gen( "gen" ); + int beg, end, from; + for ( ++linesIt; linesIt != lines.end(); ++linesIt ) + { + TCollection_AsciiString& aSavedLine = *linesIt; + end = aSavedLine.Length(), from = 1; + while ( from < end && ( beg = aSavedLine.Location( aSmeshCall, from, end ))) + { + char charBefore = ( beg == 1 ) ? ' ' : aSavedLine.Value( beg - 1 ); + if ( isspace( charBefore ) || charBefore == '=' ) { // "smesh." is not a part of a long word + aSavedLine.Insert( beg + aSmeshCall.Length() - 1, gen );// "smesh" -> "smeshgen" + end += gen.Length(); + } + from = beg + aSmeshCall.Length(); + } + } + } + } + + // Add new dump trace of API methods calls to script lines + if (!myPythonScript.IsNull()) + { + Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScript; + Standard_Integer istr, aLen = aPythonScript->Length(); + for (istr = 1; istr <= aLen; istr++) + lines.push_back( aPythonScript->Value( istr )); + } + + // Convert IDL API calls into smeshBuilder.py API. + // Some objects are wrapped with python classes and + // Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects + Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod; + std::set< TCollection_AsciiString > aRemovedObjIDs; + if ( !getenv("NO_2smeshpy_conversion")) + SMESH_2smeshpy::ConvertScript( lines, anEntry2AccessorMethod, + theObjectNames, aRemovedObjIDs, + isHistoricalDump ); + + bool importGeom = false; + GEOM::GEOM_Gen_ptr geom = GetGeomEngine(); + { + // Add names of GEOM objects to theObjectNames to exclude same names of SMESH objects + GEOM::string_array_var aGeomNames = geom->GetAllDumpNames(); + int ign = 0, nbgn = aGeomNames->length(); + for (; ign < nbgn; ign++) { + TCollection_AsciiString aName = aGeomNames[ign].in(); + theObjectNames.Bind(aName, "1"); + } + } + + TCollection_AsciiString anUpdatedScript; + + Resource_DataMapOfAsciiStringAsciiString mapRemoved; + Resource_DataMapOfAsciiStringAsciiString mapEntries; // names and entries present in anUpdatedScript + Standard_Integer objectCounter = 0; + TCollection_AsciiString anEntry, aName, aGUIName, aBaseName("smeshObj_"); + + // Treat every script line and add it to anUpdatedScript + for ( linesIt = lines.begin(); linesIt != lines.end(); ++linesIt ) + { + TCollection_AsciiString& aLine = *linesIt; + anUpdatedScript += tab; + { + //Replace characters used instead of quote marks to quote notebook variables + int pos = 1; + while (( pos = aLine.Location( 1, SMESH::TVar::Quote(), pos, aLine.Length() ))) + aLine.SetValue( pos, '"' ); + } + // Find entries to be replaced by names + Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aLine); + const Standard_Integer aSeqLen = aSeq->Length(); + Standard_Integer aStart = 1; + for (Standard_Integer i = 1; i <= aSeqLen; i += 2) + { + if ( aStart < aSeq->Value(i) ) + anUpdatedScript += aLine.SubString( aStart, aSeq->Value(i) - 1 ); // line part before i-th entry + anEntry = aLine.SubString( aSeq->Value(i), aSeq->Value(i + 1) ); + // is a GEOM object? + CORBA::String_var geomName = geom->GetDumpName( anEntry.ToCString() ); + if ( !geomName.in() || !geomName.in()[0] ) { + // is a SMESH object + if ( theObjectNames.IsBound( anEntry )) { + // The Object is in Study + aName = theObjectNames.Find( anEntry ); + // check validity of aName + bool isValidName = fixPythonName( aName ); + if (theObjectNames.IsBound(aName) && anEntry != theObjectNames(aName)) { + // diff objects have same name - make a new name by appending a digit + TCollection_AsciiString aName2; + Standard_Integer i = 0; + do { + aName2 = aName + "_" + ++i; + } while (theObjectNames.IsBound(aName2) && anEntry != theObjectNames(aName2)); + aName = aName2; + isValidName = false; + } + if ( !isValidName ) + theObjectNames(anEntry) = aName; + + if ( aLine.Value(1) != '#' ) + mapEntries.Bind(anEntry, aName); + } + else + { + // Removed Object + do { + aName = aBaseName + (++objectCounter); + } while (theObjectNames.IsBound(aName)); + + if ( !aRemovedObjIDs.count( anEntry ) && aLine.Value(1) != '#') + mapRemoved.Bind(anEntry, aName); + + theObjectNames.Bind(anEntry, aName); + } + theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects + } + else + { + aName = geomName.in(); + importGeom = true; + } + anUpdatedScript += aName; + aStart = aSeq->Value(i + 1) + 1; + + } // loop on entries within aLine + + if ( aSeqLen == 0 ) + anUpdatedScript += aLine; + else if ( aSeq->Value( aSeqLen ) < aLine.Length() ) + anUpdatedScript += aLine.SubString( aSeq->Value(aSeqLen) + 1, aLine.Length() ); + + anUpdatedScript += '\n'; + } + + // Make an initial part of aSript + + TCollection_AsciiString initPart = "import "; + if ( isMultiFile ) + initPart += "salome, "; + initPart += " SMESH, SALOMEDS\n"; + initPart += "from salome.smesh import smeshBuilder\n"; + if ( importGeom && isMultiFile ) + { + initPart += ("\n## import GEOM dump file ## \n" + "import string, os, sys, re, inspect\n" + "thisFile = inspect.getfile( inspect.currentframe() )\n" + "thisModule = os.path.splitext( os.path.basename( thisFile ))[0]\n" + "sys.path.insert( 0, os.path.dirname( thisFile ))\n" + "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",thisModule)+\" import *\")\n\n"); + } + // import python files corresponding to plugins if they are used in anUpdatedScript + { + TCollection_AsciiString importStr; + std::vector pluginNames = getPluginNames(); + for ( size_t i = 0; i < pluginNames.size(); ++i ) + { + // Convert access to plugin members: + // e.g. StdMeshers.QUAD_REDUCED -> StdMeshersBuilder.QUAD_REDUCED + TCollection_AsciiString pluginAccess = (pluginNames[i] + ".").c_str() ; + int iFrom = 1, iPos; + while (( iPos = anUpdatedScript.Location( pluginAccess, iFrom, anUpdatedScript.Length() ))) + { + anUpdatedScript.Insert( iPos + pluginNames[i].size(), "Builder" ); + iFrom = iPos + pluginNames[i].size() + 8; + } + // if any plugin member is used, import the plugin + if ( iFrom > 1 ) + importStr += ( helper + "\n" "from salome." + pluginNames[i].c_str() + + " import " + pluginNames[i].c_str() +"Builder" ); + } + if ( !importStr.IsEmpty() ) + initPart += importStr + "\n"; + } + + if ( isMultiFile ) + initPart += "def RebuildData():"; + initPart += "\n"; + + anUpdatedScript.Prepend( initPart ); + + // Make a final part of aScript + + // Dump object removal + TCollection_AsciiString removeObjPart; + if ( !mapRemoved.IsEmpty() ) { + removeObjPart += nt + "## some objects were removed"; + removeObjPart += nt + "aStudyBuilder = salome.myStudy.NewBuilder()"; + Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString mapRemovedIt; + for ( mapRemovedIt.Initialize( mapRemoved ); mapRemovedIt.More(); mapRemovedIt.Next() ) { + aName = mapRemovedIt.Value(); // python name + anEntry = mapRemovedIt.Key(); + removeObjPart += nt + "SO = salome.myStudy.FindObjectIOR(salome.myStudy.ConvertObjectToIOR("; + removeObjPart += aName; + // for object wrapped by class of smeshBuilder.py + if ( anEntry2AccessorMethod.IsBound( anEntry ) ) + removeObjPart += helper + "." + anEntry2AccessorMethod( anEntry ); + removeObjPart += helper + "))" + nt + "if SO: aStudyBuilder.RemoveObjectWithChildren(SO)"; + } + } + + // Set object names + TCollection_AsciiString setNamePart; + Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString mapEntriesIt; + for ( mapEntriesIt.Initialize( mapEntries ); mapEntriesIt.More(); mapEntriesIt.Next() ) + { + anEntry = mapEntriesIt.Key(); + aName = mapEntriesIt.Value(); // python name + if ( theNames.IsBound( anEntry )) + { + aGUIName = theNames.Find(anEntry); + aGUIName.RemoveAll('\''); // remove a quote from a name (issue 22360) + setNamePart += nt + aSMESHGen + ".SetName(" + aName; + if ( anEntry2AccessorMethod.IsBound( anEntry ) ) + setNamePart += helper + "." + anEntry2AccessorMethod( anEntry ); + setNamePart += helper + ", '" + aGUIName + "')"; + } + } + if ( !setNamePart.IsEmpty() ) + { + setNamePart.Insert( 1, nt + "## Set names of Mesh objects" ); + } + + // Store visual properties of displayed objects + + TCollection_AsciiString visualPropertiesPart; + if (isPublished) + { + //Output the script that sets up the visual parameters. + CORBA::String_var compDataType = ComponentDataType(); + CORBA::String_var script = getStudyServant()->GetDefaultScript( compDataType.in(), tab.ToCString() ); + if ( script.in() && script.in()[0] ) { + visualPropertiesPart += nt + "### Store presentation parameters of displayed objects\n"; + visualPropertiesPart += script.in(); + } + } + + anUpdatedScript += removeObjPart + '\n' + setNamePart + '\n' + visualPropertiesPart; + + if ( isMultiFile ) + { + anUpdatedScript += + "\n\tpass" + "\n" + "\nif __name__ == '__main__':" + "\n\tSMESH_RebuildData = RebuildData" + "\n\texec('import '+re.sub('SMESH$','GEOM',thisModule)+' as GEOM_dump')" + "\n\tGEOM_dump.RebuildData()" + "\n\texec('from '+re.sub('SMESH$','GEOM',thisModule)+' import * ')" + "\n\tSMESH_RebuildData()"; + } + anUpdatedScript += "\n"; + + // no need now as we use 'tab' and 'nt' variables depending on isMultiFile + // if( !isMultiFile ) // remove unnecessary tabulation + // RemoveTabulation( anUpdatedScript ); + + // ----------------------------------------------------------------- + // put string literals describing patterns into separate functions + // ----------------------------------------------------------------- + + TCollection_AsciiString aLongString, aFunctionType; + int where = 1; + std::set< std::string > functionNameSet; + while ( SMESH::TPythonDump::CutoutLongString( anUpdatedScript, where, aLongString, aFunctionType )) + { + // make a python string literal + aLongString.Prepend(":\n\treturn '''\n"); + aLongString += "\n\t'''\n\tpass\n"; + + TCollection_AsciiString functionName; + + // check if the function returning this literal is already defined + int posAlready = anUpdatedScript.Location( aLongString, where, anUpdatedScript.Length() ); + if ( posAlready ) // already defined + { + // find the function name + int functBeg = posAlready; + char* script = (char*) anUpdatedScript.ToCString() + posAlready - 1; // look at ":" after "def fuction()" + while ( *script != ' ' ) { + script--; + functBeg--; + } + functBeg++; // do not take ' ' + posAlready--; // do not take ':' + functionName = anUpdatedScript.SubString( functBeg, posAlready ); + } + else // not defined yet + { + // find a unique function name + fixPythonName( aFunctionType ); + Standard_Integer nb = 0; + do functionName = aFunctionType + "_" + ( nb++ ) + "()"; + while ( !functionNameSet.insert( functionName.ToCString() ).second ); + + // define function + TCollection_AsciiString funDef = helper + "def " + functionName + aLongString; + if ( isMultiFile ) + { + anUpdatedScript += helper + "\n\n" + funDef; + } + else + { + funDef += "\n\n"; + anUpdatedScript.Insert( 1, funDef); + where += funDef.Length(); + } + } + anUpdatedScript.InsertBefore( where, functionName ); // call function + } + + aValidScript = true; + + return anUpdatedScript; + + SMESH_CATCH( SMESH::printException ); + + aValidScript = false; + return ""; +} + +//============================================================================= +/*! + * GetNewPythonLines + */ +//============================================================================= +TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines() +{ + TCollection_AsciiString aScript; + + // Dump trace of API methods calls + if (!myPythonScript.IsNull()) { + Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScript; + Standard_Integer istr, aLen = aPythonScript->Length(); + for (istr = 1; istr <= aLen; istr++) { + aScript += "\n"; + aScript += aPythonScript->Value(istr); + } + aScript += "\n"; + } + + return aScript; +} + +//============================================================================= +/*! + * CleanPythonTrace + */ +//============================================================================= +void SMESH_Gen_i::CleanPythonTrace() +{ + TCollection_AsciiString aScript; + + // Clean trace of API methods calls + if (!myPythonScript.IsNull()) { + myPythonScript->Clear(); + } +} diff --cc src/SMESH_SWIG/smeshBuilder.py index b60dacbc8,9e30399e4..dc7f7de35 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@@ -4712,6 -4641,24 +4729,24 @@@ class Mesh(metaclass=MeshMeta) def MergeEqualElements(self): self.editor.MergeEqualElements() + ## Returns all or only closed free borders + # @return list of SMESH.FreeBorder's + # @ingroup l2_modif_trsf + def FindFreeBorders(self, ClosedOnly=True): + return self.editor.FindFreeBorders( ClosedOnly ) + + ## Fill with 2D elements a hole defined by a SMESH.FreeBorder. + # @param FreeBorder either a SMESH.FreeBorder or a list on node IDs. These nodes + # must describe all sequential nodes of the hole border. The first and the last + # nodes must be the same. Use FindFreeBorders() to get nodes of holes. + # @ingroup l2_modif_trsf + def FillHole(self, holeNodes): + if holeNodes and isinstance( holeNodes, list ) and isinstance( holeNodes[0], int ): + holeNodes = SMESH.FreeBorder(nodeIDs=holeNodes) + if not isinstance( holeNodes, SMESH.FreeBorder ): - raise TypeError, "holeNodes must be either SMESH.FreeBorder or list of integer and not %s" % holeNodes ++ raise TypeError("holeNodes must be either SMESH.FreeBorder or list of integer and not %s" % holeNodes) + self.editor.FillHole( holeNodes ) + ## Return groups of FreeBorder's coincident within the given tolerance. # @param tolerance the tolerance. If the tolerance <= 0.0 then one tenth of an average # size of elements adjacent to free borders being compared is used. diff --cc src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h index fa157d04a,931614c1e..fa564efa4 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h @@@ -136,8 -140,10 +140,9 @@@ public SelectionMode getSelectionMode(); void select( const char *id, std::vector ids, bool append = false ); void select( const char *id, int id1, bool append = false ); + void select( const char *id, std::vector >, bool apend = false ); private: - SALOMEDS::Study_var myStudy; SALOMEDS::StudyBuilder_var myStudyBuilder; SALOMEDS::SComponent_var mySComponentMesh; }; diff --cc src/Tools/MacMesh/MacMesh/MacObject.py index 162c7d5b7,6589ac8b0..c541fd949 --- a/src/Tools/MacMesh/MacMesh/MacObject.py +++ b/src/Tools/MacMesh/MacMesh/MacObject.py @@@ -20,279 -20,281 +20,279 @@@ class MacObject: - """ - This represents a python class definition which contains - all necessary information about the macro object being created - in Salome - """ + """ + This represents a python class definition which contains + all necessary information about the macro object being created + in Salome + """ - def __init__( self, ObjectType, GeoParameters, MeshParameters, **args ): - """ - Initializes the macro object to be created, saves parameters inside of it, checks for neighboring objects, - determines meshing parameters if necessary and finally launches the generation process. - """ - import Config,GenFunctions - if Config.debug : print "Initializing object No. " + str(len(Config.ListObj)+1) + def __init__( self, ObjectType, GeoParameters, MeshParameters, **args ): + """ + Initializes the macro object to be created, saves parameters inside of it, checks for neighboring objects, + determines meshing parameters if necessary and finally launches the generation process. + """ + import Config,GenFunctions + if Config.debug : print("Initializing object No. " + str(len(Config.ListObj)+1)) - if 'publish' in args : - if args['publish']==0 : Config.publish = 0 - else : Config.publish = 1 - else : Config.publish = 1 - - if 'groups' in args : - self.GroupNames = args['groups'] - for group in args['groups'] : - if not(group in Config.Groups) and group : Config.Groups.append(group) - else : self.GroupNames = [None, None, None, None] - - if ObjectType == 'NonOrtho': - if not(len(GeoParameters)==4): print "Error: trying to construct a non-ortho object but the 4 constitutive vertices are not given!" - else : - Xmin = min([GeoParameters[i][0] for i in range(4)]) - Xmax = max([GeoParameters[i][0] for i in range(4)]) - Ymin = min([GeoParameters[i][1] for i in range(4)]) - Ymax = max([GeoParameters[i][1] for i in range(4)]) - self.GeoPar = [(0.5*(Xmin+Xmax),0.5*(Ymin+Ymax)),(Xmax-Xmin,Ymax-Ymin)] - self.PtCoor = GenFunctions.SortPoints(GeoParameters) - else: - self.GeoPar = GeoParameters - [Xmin,Ymin,Xmax,Ymax] = [ self.GeoPar[0][0]-0.5*self.GeoPar[1][0], self.GeoPar[0][1]-0.5*self.GeoPar[1][1] ] + [ self.GeoPar[0][0]+0.5*self.GeoPar[1][0], self.GeoPar[0][1]+0.5*self.GeoPar[1][1] ] - self.PtCoor = [(Xmin,Ymin),(Xmax,Ymin),(Xmax,Ymax),(Xmin,Ymax)] - - self.Type = ObjectType - self.LowBound = [ self.GeoPar[0][0]-0.5*self.GeoPar[1][0], self.GeoPar[0][1]-0.5*self.GeoPar[1][1] ] - self.UpperBound = [ self.GeoPar[0][0]+0.5*self.GeoPar[1][0], self.GeoPar[0][1]+0.5*self.GeoPar[1][1] ] - self.MeshPar = MeshParameters - self.GeoChildren = [] - self.GeoChildrenNames = [] - self.Mesh = [] - self.MeshGroups = [] - self.CheckInterfaces() - if 'auto' in MeshParameters : self.AutoParam() - if not(self.MeshPar[0]<0): self.Generate() - else : - Config.ListObj.append(self) - print("Aborting object creation\n ") + if 'publish' in args : + if args['publish']==0 : Config.publish = 0 + else : Config.publish = 1 + else : Config.publish = 1 - def Generate(self) : - """ - This method generates the geometrical object with the corresponding mesh once all verifications (CheckInterfaces and AutoParam) - have been accomplished - """ - import GenFunctions, Alarms, Config - self = {'Box11' : lambda : GenFunctions.Box11(self), - 'Box42' : lambda : GenFunctions.Box42(self), - 'BoxAng32' : lambda : GenFunctions.BoxAng32(self), - 'CompBox' : lambda : GenFunctions.CompBox(self), - 'CompBoxF' : lambda : GenFunctions.CompBoxF(self), - 'NonOrtho' : lambda : GenFunctions.NonOrtho(self), - 'QuartCyl' : lambda : GenFunctions.QuartCyl(self) }[self.Type]() + if 'groups' in args : + self.GroupNames = args['groups'] + for group in args['groups'] : + if not(group in Config.Groups) and group : Config.Groups.append(group) + else : self.GroupNames = [None, None, None, None] - if Config.debug : Alarms.Message(self.status) # notification on the result of the generation algorithm - + if ObjectType == 'NonOrtho': + if not(len(GeoParameters)==4): print("Error: trying to construct a non-ortho object but the 4 constitutive vertices are not given!") + else : + Xmin = min([GeoParameters[i][0] for i in range(4)]) + Xmax = max([GeoParameters[i][0] for i in range(4)]) + Ymin = min([GeoParameters[i][1] for i in range(4)]) + Ymax = max([GeoParameters[i][1] for i in range(4)]) + self.GeoPar = [(0.5*(Xmin+Xmax),0.5*(Ymin+Ymax)),(Xmax-Xmin,Ymax-Ymin)] + self.PtCoor = GenFunctions.SortPoints(GeoParameters) + else: + self.GeoPar = GeoParameters + [Xmin,Ymin,Xmax,Ymax] = [ self.GeoPar[0][0]-0.5*self.GeoPar[1][0], self.GeoPar[0][1]-0.5*self.GeoPar[1][1] ] + [ self.GeoPar[0][0]+0.5*self.GeoPar[1][0], self.GeoPar[0][1]+0.5*self.GeoPar[1][1] ] + self.PtCoor = [(Xmin,Ymin),(Xmax,Ymin),(Xmax,Ymax),(Xmin,Ymax)] - def CheckInterfaces(self): - """ - This method searches for neighbours for the object being created and saves them inside the Config.Connections - array. This array contains 4 entries per object corresponding to West, East, South, and North neighbours. - Note that an object may have more than one neighbour for a given direction. - """ - import Alarms, Config - from GenFunctions import AddIfDifferent - from CompositeBox import FindCommonSide - - Config.Connections.append([(-1,),(-1,),(-1,),(-1,)]) - itemID = len(Config.ListObj) - # In all cases except non ortho, PrincipleBoxes is unitary and contains the box in question - # In the non-ortho case it contains all possible combinations of boxes with 3 vertices - PrincipleBoxes = self.PrincipleBoxes() - for i, TestObj in enumerate(Config.ListObj): - SecondaryBoxes = TestObj.PrincipleBoxes() - ConnX = 0 - ConnY = 0 - for Box0 in PrincipleBoxes: - for Box1 in SecondaryBoxes: - # Along X - CenterDis = abs(Box1[0][0]-Box0[0][0]) - Extension = 0.5*(Box1[1][0]+Box0[1][0]) - if CenterDis - Extension < -1e-7 : - ConnX = -1 - elif CenterDis - Extension < 1e-7 : - if not(FindCommonSide(self.DirBoundaries(2),TestObj.DirBoundaries(3))==[0,0]) and Box1[0][0] < Box0[0][0] : ConnX = 1 - elif not(FindCommonSide(self.DirBoundaries(3),TestObj.DirBoundaries(2))==[0,0]) and Box1[0][0] >= Box0[0][0]: ConnX = 2 - else : ConnX = 0 - - # Along Y - CenterDis = abs(Box1[0][1]-Box0[0][1]) - Extension = 0.5*(Box1[1][1]+Box0[1][1]) - if CenterDis - Extension < -1e-7 : - ConnY = -1 - elif CenterDis - Extension < 1e-7 : - if not(FindCommonSide(self.DirBoundaries(0),TestObj.DirBoundaries(1))==[0,0]) and Box1[0][1] < Box0[0][1] : ConnY = 1 - elif not(FindCommonSide(self.DirBoundaries(1),TestObj.DirBoundaries(0))==[0,0]) and Box1[0][1] >= Box0[0][1]: ConnY = 2 - else : ConnY = 0 + self.Type = ObjectType + self.LowBound = [ self.GeoPar[0][0]-0.5*self.GeoPar[1][0], self.GeoPar[0][1]-0.5*self.GeoPar[1][1] ] + self.UpperBound = [ self.GeoPar[0][0]+0.5*self.GeoPar[1][0], self.GeoPar[0][1]+0.5*self.GeoPar[1][1] ] + self.MeshPar = MeshParameters + self.GeoChildren = [] + self.GeoChildrenNames = [] + self.Mesh = [] + self.MeshGroups = [] + self.CheckInterfaces() + if 'auto' in MeshParameters : self.AutoParam() + if not(self.MeshPar[0]<0): self.Generate() + else : + Config.ListObj.append(self) + print("Aborting object creation\n ") - if not (ConnX*ConnY == 0) : - if max(ConnX,ConnY) == -1 and not('NonOrtho' in [self.Type,TestObj.Type]) : Alarms.Message(3) - else: - if ConnX == 1 and ConnY == -1: - if Config.Connections[i][1] == (-1,) : Config.Connections[i][1] = (itemID,) - else : Config.Connections[i][1] = AddIfDifferent(Config.Connections[i][1],itemID) - if Config.Connections[itemID][0] == (-1,) : Config.Connections[itemID][0] = (i,) - else : Config.Connections[itemID][0] = AddIfDifferent(Config.Connections[itemID][0],i) - elif ConnX == 2 and ConnY == -1: - if Config.Connections[i][0] == (-1,) : Config.Connections[i][0] = (itemID,) - else : Config.Connections[i][0] = AddIfDifferent(Config.Connections[i][0],itemID) - if Config.Connections[itemID][1] == (-1,) : Config.Connections[itemID][1] = (i,) - else : Config.Connections[itemID][1] = AddIfDifferent(Config.Connections[itemID][1],i) - elif ConnY == 1 and ConnX == -1: - if Config.Connections[i][3] == (-1,) : Config.Connections[i][3] = (itemID,) - else : Config.Connections[i][3] = AddIfDifferent(Config.Connections[i][3],itemID) - if Config.Connections[itemID][2] == (-1,) : Config.Connections[itemID][2] = (i,) - else : Config.Connections[itemID][2] = AddIfDifferent(Config.Connections[itemID][2],i) - elif ConnY ==2 and ConnX == -1: - if Config.Connections[i][2] == (-1,) : Config.Connections[i][2] = (itemID,) - else : Config.Connections[i][2] = AddIfDifferent(Config.Connections[i][2],itemID) - if Config.Connections[itemID][3] == (-1,) : Config.Connections[itemID][3] = (i,) - else : Config.Connections[itemID][3] = AddIfDifferent(Config.Connections[itemID][3],i) + def Generate(self) : + """ + This method generates the geometrical object with the corresponding mesh once all verifications (CheckInterfaces and AutoParam) + have been accomplished + """ + import GenFunctions, Alarms, Config + self = {'Box11' : lambda : GenFunctions.Box11(self), + 'Box42' : lambda : GenFunctions.Box42(self), + 'BoxAng32' : lambda : GenFunctions.BoxAng32(self), + 'CompBox' : lambda : GenFunctions.CompBox(self), + 'CompBoxF' : lambda : GenFunctions.CompBoxF(self), + 'NonOrtho' : lambda : GenFunctions.NonOrtho(self), + 'QuartCyl' : lambda : GenFunctions.QuartCyl(self) }[self.Type]() - def AutoParam (self): - """ - This method is called only if the 'auto' keyword is used inside the meshing algorithm. It is based on the - connection results per object and tries to find the correct parameters for obtaining a final compatible mesh - between the objects already present and the one being created. If this is not possible, the method gives an error - message. - """ - import Alarms, Config, GenFunctions, CompositeBox - MeshPar = [0,0,0,0] # initialize the mesh parameter value to be used to -1 - [(X0,Y0),(DX,DY)] = self.GeoPar - ObjectsInvolved = [] - for i, Conn in enumerate(Config.Connections[-1]): - if not ( Conn == (-1,) ): # Meaning that there is one or more neighbors on this direction - for ObjID in Conn : - ToLook0 = [2,3,0,1][i] - ToLook1 = [3,2,1,0][i] - CommonSide = CompositeBox.FindCommonSide(Config.ListObj[ObjID].DirBoundaries(ToLook1),self.DirBoundaries(ToLook0)) - #print "Common Side is:", CommonSide - ToLook2 = [1,0,3,2][i] - #print "Full Side is:", CompositeBox.IntLen(Config.ListObj[ObjID].DirBoundaries(ToLook1)) - #print "Full Segments on this direction are:", Config.ListObj[ObjID].DirectionalMeshParams[ToLook2] - RealSegments = round(Config.ListObj[ObjID].DirectionalMeshParams[ToLook2]*CompositeBox.IntLen(CommonSide)/CompositeBox.IntLen(Config.ListObj[ObjID].DirBoundaries(ToLook1))) - #print "RealSegments :", RealSegments - - MeshPar[i] = MeshPar[i] + RealSegments - ObjectsInvolved.append(ObjID+1) - self.DirectionalMeshParams = MeshPar - self.MeshPar[0] = GenFunctions.CompatibilityTest(self) + if Config.debug : Alarms.Message(self.status) # notification on the result of the generation algorithm - if self.MeshPar[0] < 0 : - Alarms.Message(4) - if self.MeshPar[0] == -1 : print ("Problem encountered with object(s) no. "+str(ObjectsInvolved)) - elif self.MeshPar[0] == -2 : print ("This object has no neighbours !!!") - def Boundaries (self): - """ - This method returns the global boundaries of the MacObject. [Xmin,Xmax,Ymin,Ymax] - """ - Xmin = min([self.DirBoundaries(i)[0] for i in [0,1]]) - Xmax = max([self.DirBoundaries(i)[1] for i in [0,1]]) - Ymin = min([self.DirBoundaries(i)[0] for i in [2,3]]) - Ymax = max([self.DirBoundaries(i)[1] for i in [2,3]]) - - return [Xmin,Xmax,Ymin,Ymax] - - def DirBoundaries (self, Direction): - """ - This method returns a single interval giving [Xmin,Xmax] or [Ymin,Ymax] according to the required direction. - This works particularly well for nonorthogonal objects. - Direction : [0,1,2,3] <=> [South, North, West, East] - """ - PtCoor = self.PtCoor - PtCoor.append(self.PtCoor[0]) - if type(Direction) is str : - Dir = { 'South' : lambda : 0, - 'North' : lambda : 1, - 'West' : lambda : 2, - 'East' : lambda : 3,}[Direction]() - else : Dir = int(Direction) - - PtIndex = [0,2,3,1][Dir] - DirIndex = [0,0,1,1][Dir] - - return sorted([PtCoor[PtIndex][DirIndex],PtCoor[PtIndex+1][DirIndex]]) - def DirVectors (self, Direction): - """ - This method returns for a given object, the real vectors which define a given direction - The interest in using this method is for non-orthogonal objects where the sides can be - deviated from the orthogonal basis vectors - """ - if type(Direction) is str : - Dir = { 'South' : lambda : 0, - 'North' : lambda : 1, - 'West' : lambda : 2, - 'East' : lambda : 3,}[Direction]() - else : Dir = int(Direction) - PtCoor = self.PtCoor - PtCoor.append(self.PtCoor[0]) - PtIndex = [0,2,3,1][Dir] - return [PtCoor[PtIndex+1][0]-PtCoor[PtIndex][0],PtCoor[PtIndex+1][1]-PtCoor[PtIndex][1],0.] - - def GetBorder (self, Criterion): - import GenFunctions, Config + def CheckInterfaces(self): + """ + This method searches for neighbours for the object being created and saves them inside the Config.Connections + array. This array contains 4 entries per object corresponding to West, East, South, and North neighbours. + Note that an object may have more than one neighbour for a given direction. + """ + import Alarms, Config + from GenFunctions import AddIfDifferent + from CompositeBox import FindCommonSide - from salome.geom import geomBuilder - geompy = geomBuilder.New( Config.theStudy ) - - if type(Criterion) is str : - Crit = {'South' : lambda : 0, - 'North' : lambda : 1, - 'West' : lambda : 2, - 'East' : lambda : 3,}[Criterion]() - else : Crit = int(Criterion) - - AcceptedObj = [] - if Crit < 4 : - Boundaries = self.Boundaries() - Research = {0 : lambda : [self.DirVectors(0),1,Boundaries[2]], - 1 : lambda : [self.DirVectors(1),1,Boundaries[3]], - 2 : lambda : [self.DirVectors(2),0,Boundaries[0]], - 3 : lambda : [self.DirVectors(3),0,Boundaries[1]], }[Crit]() - - for i,ElemObj in enumerate(self.GeoChildren): - EdgeIDs = geompy.ExtractShapes(ElemObj,6)# List of Edge IDs belonging to ElemObj - for Edge in EdgeIDs: - if GenFunctions.IsParallel(Edge,Research[0]): - if abs( geompy.PointCoordinates(geompy.GetVertexByIndex(Edge,0))[Research[1]] - Research[2] )< 1e-6 or abs( geompy.PointCoordinates(geompy.GetVertexByIndex(Edge,1))[Research[1]] - Research[2] )< 1e-6 : - AcceptedObj.append(Edge) - else : - CenterSrchPar = {'NE' : lambda : [-1., -1.], - 'NW' : lambda : [ 1., -1.], - 'SW' : lambda : [ 1., 1.], - 'SE' : lambda : [-1., 1.], }[self.MeshPar[1]]() - Radius = self.GeoPar[1][1]*float(self.MeshPar[2])/(self.MeshPar[2]+1) - Center = (self.GeoPar[0][0]+CenterSrchPar[0]*self.GeoPar[1][0]/2.,self.GeoPar[0][1]+CenterSrchPar[1]*self.GeoPar[1][1]/2.,0.) - for i,ElemObj in enumerate(self.GeoChildren): - EdgeIDs = geompy.ExtractShapes(ElemObj,6)# List of Edge IDs belonging to ElemObj - for Edge in EdgeIDs: - if GenFunctions.IsOnCircle(Edge,Center,Radius): - AcceptedObj.append(Edge) - return AcceptedObj + Config.Connections.append([(-1,),(-1,),(-1,),(-1,)]) + itemID = len(Config.ListObj) + # In all cases except non ortho, PrincipleBoxes is unitary and contains the box in question + # In the non-ortho case it contains all possible combinations of boxes with 3 vertices + PrincipleBoxes = self.PrincipleBoxes() + for i, TestObj in enumerate(Config.ListObj): + SecondaryBoxes = TestObj.PrincipleBoxes() + ConnX = 0 + ConnY = 0 + for Box0 in PrincipleBoxes: + for Box1 in SecondaryBoxes: + # Along X + CenterDis = abs(Box1[0][0]-Box0[0][0]) + Extension = 0.5*(Box1[1][0]+Box0[1][0]) + if CenterDis - Extension < -1e-7 : + ConnX = -1 + elif CenterDis - Extension < 1e-7 : + if not(FindCommonSide(self.DirBoundaries(2),TestObj.DirBoundaries(3))==[0,0]) and Box1[0][0] < Box0[0][0] : ConnX = 1 + elif not(FindCommonSide(self.DirBoundaries(3),TestObj.DirBoundaries(2))==[0,0]) and Box1[0][0] >= Box0[0][0]: ConnX = 2 + else : ConnX = 0 - def PrincipleBoxes (self): - """ - This function returns all possible combination rectangular shape objects that can contain at least 3 of the principle vertices - constituting the MacObject. This is indispensable for the Non-ortho types and shall return a number of 24 possible combinations - """ - from itertools import combinations - Boxes = [] - if self.Type == 'NonOrtho': - for combi in combinations(range(4),3): - Xmin = min([self.PtCoor[i][0] for i in combi]) - Xmax = max([self.PtCoor[i][0] for i in combi]) - Ymin = min([self.PtCoor[i][1] for i in combi]) - Ymax = max([self.PtCoor[i][1] for i in combi]) - Boxes.append([(0.5*(Xmin+Xmax),0.5*(Ymin+Ymax)),(Xmax-Xmin,Ymax-Ymin)]) - else : - Boxes = [self.GeoPar] - - return Boxes - - + # Along Y + CenterDis = abs(Box1[0][1]-Box0[0][1]) + Extension = 0.5*(Box1[1][1]+Box0[1][1]) + if CenterDis - Extension < -1e-7 : + ConnY = -1 + elif CenterDis - Extension < 1e-7 : + if not(FindCommonSide(self.DirBoundaries(0),TestObj.DirBoundaries(1))==[0,0]) and Box1[0][1] < Box0[0][1] : ConnY = 1 + elif not(FindCommonSide(self.DirBoundaries(1),TestObj.DirBoundaries(0))==[0,0]) and Box1[0][1] >= Box0[0][1]: ConnY = 2 + else : ConnY = 0 + + if not (ConnX*ConnY == 0) : + if max(ConnX,ConnY) == -1 and not('NonOrtho' in [self.Type,TestObj.Type]) : Alarms.Message(3) + else: + if ConnX == 1 and ConnY == -1: + if Config.Connections[i][1] == (-1,) : Config.Connections[i][1] = (itemID,) + else : Config.Connections[i][1] = AddIfDifferent(Config.Connections[i][1],itemID) + if Config.Connections[itemID][0] == (-1,) : Config.Connections[itemID][0] = (i,) + else : Config.Connections[itemID][0] = AddIfDifferent(Config.Connections[itemID][0],i) + elif ConnX == 2 and ConnY == -1: + if Config.Connections[i][0] == (-1,) : Config.Connections[i][0] = (itemID,) + else : Config.Connections[i][0] = AddIfDifferent(Config.Connections[i][0],itemID) + if Config.Connections[itemID][1] == (-1,) : Config.Connections[itemID][1] = (i,) + else : Config.Connections[itemID][1] = AddIfDifferent(Config.Connections[itemID][1],i) + elif ConnY == 1 and ConnX == -1: + if Config.Connections[i][3] == (-1,) : Config.Connections[i][3] = (itemID,) + else : Config.Connections[i][3] = AddIfDifferent(Config.Connections[i][3],itemID) + if Config.Connections[itemID][2] == (-1,) : Config.Connections[itemID][2] = (i,) + else : Config.Connections[itemID][2] = AddIfDifferent(Config.Connections[itemID][2],i) + elif ConnY ==2 and ConnX == -1: + if Config.Connections[i][2] == (-1,) : Config.Connections[i][2] = (itemID,) + else : Config.Connections[i][2] = AddIfDifferent(Config.Connections[i][2],itemID) + if Config.Connections[itemID][3] == (-1,) : Config.Connections[itemID][3] = (i,) + else : Config.Connections[itemID][3] = AddIfDifferent(Config.Connections[itemID][3],i) + + def AutoParam (self): + """ + This method is called only if the 'auto' keyword is used inside the meshing algorithm. It is based on the + connection results per object and tries to find the correct parameters for obtaining a final compatible mesh + between the objects already present and the one being created. If this is not possible, the method gives an error + message. + """ + import Alarms, Config, GenFunctions, CompositeBox + MeshPar = [0,0,0,0] # initialize the mesh parameter value to be used to -1 + [(X0,Y0),(DX,DY)] = self.GeoPar + ObjectsInvolved = [] + for i, Conn in enumerate(Config.Connections[-1]): + if not ( Conn == (-1,) ): # Meaning that there is one or more neighbors on this direction + for ObjID in Conn : + ToLook0 = [2,3,0,1][i] + ToLook1 = [3,2,1,0][i] + CommonSide = CompositeBox.FindCommonSide(Config.ListObj[ObjID].DirBoundaries(ToLook1),self.DirBoundaries(ToLook0)) + #print "Common Side is:", CommonSide + ToLook2 = [1,0,3,2][i] + #print "Full Side is:", CompositeBox.IntLen(Config.ListObj[ObjID].DirBoundaries(ToLook1)) + #print "Full Segments on this direction are:", Config.ListObj[ObjID].DirectionalMeshParams[ToLook2] + RealSegments = round(Config.ListObj[ObjID].DirectionalMeshParams[ToLook2]*CompositeBox.IntLen(CommonSide)/CompositeBox.IntLen(Config.ListObj[ObjID].DirBoundaries(ToLook1))) + #print "RealSegments :", RealSegments + + MeshPar[i] = MeshPar[i] + RealSegments + ObjectsInvolved.append(ObjID+1) + self.DirectionalMeshParams = MeshPar + self.MeshPar[0] = GenFunctions.CompatibilityTest(self) + + if self.MeshPar[0] < 0 : + Alarms.Message(4) + if self.MeshPar[0] == -1 : print(("Problem encountered with object(s) no. "+str(ObjectsInvolved))) + elif self.MeshPar[0] == -2 : print ("This object has no neighbours !!!") + + def Boundaries (self): + """ + This method returns the global boundaries of the MacObject. [Xmin,Xmax,Ymin,Ymax] + """ + Xmin = min([self.DirBoundaries(i)[0] for i in [0,1]]) + Xmax = max([self.DirBoundaries(i)[1] for i in [0,1]]) + Ymin = min([self.DirBoundaries(i)[0] for i in [2,3]]) + Ymax = max([self.DirBoundaries(i)[1] for i in [2,3]]) + + return [Xmin,Xmax,Ymin,Ymax] + + def DirBoundaries (self, Direction): + """ + This method returns a single interval giving [Xmin,Xmax] or [Ymin,Ymax] according to the required direction. + This works particularly well for nonorthogonal objects. + Direction : [0,1,2,3] <=> [South, North, West, East] + """ + PtCoor = self.PtCoor + PtCoor.append(self.PtCoor[0]) + if isinstance(Direction, str) : + Dir = { 'South' : lambda : 0, + 'North' : lambda : 1, + 'West' : lambda : 2, + 'East' : lambda : 3,}[Direction]() + else : Dir = int(Direction) + + PtIndex = [0,2,3,1][Dir] + DirIndex = [0,0,1,1][Dir] + + return sorted([PtCoor[PtIndex][DirIndex],PtCoor[PtIndex+1][DirIndex]]) + def DirVectors (self, Direction): + """ + This method returns for a given object, the real vectors which define a given direction + The interest in using this method is for non-orthogonal objects where the sides can be + deviated from the orthogonal basis vectors + """ + if isinstance(Direction, str) : + Dir = { 'South' : lambda : 0, + 'North' : lambda : 1, + 'West' : lambda : 2, + 'East' : lambda : 3,}[Direction]() + else : Dir = int(Direction) + PtCoor = self.PtCoor + PtCoor.append(self.PtCoor[0]) + PtIndex = [0,2,3,1][Dir] + return [PtCoor[PtIndex+1][0]-PtCoor[PtIndex][0],PtCoor[PtIndex+1][1]-PtCoor[PtIndex][1],0.] + + def GetBorder (self, Criterion): + import GenFunctions, Config + + from salome.geom import geomBuilder - geompy = geomBuilder.New( Config.theStudy ) ++ geompy = geomBuilder.New() + + if isinstance(Criterion, str) : + Crit = {'South' : lambda : 0, + 'North' : lambda : 1, + 'West' : lambda : 2, + 'East' : lambda : 3,}[Criterion]() + else : Crit = int(Criterion) + + AcceptedObj = [] + if Crit < 4 : + Boundaries = self.Boundaries() + Research = {0 : lambda : [self.DirVectors(0),1,Boundaries[2]], + 1 : lambda : [self.DirVectors(1),1,Boundaries[3]], + 2 : lambda : [self.DirVectors(2),0,Boundaries[0]], + 3 : lambda : [self.DirVectors(3),0,Boundaries[1]], }[Crit]() + + for i,ElemObj in enumerate(self.GeoChildren): + EdgeIDs = geompy.ExtractShapes(ElemObj,6)# List of Edge IDs belonging to ElemObj + for Edge in EdgeIDs: + if GenFunctions.IsParallel(Edge,Research[0]): + if abs( geompy.PointCoordinates(geompy.GetVertexByIndex(Edge,0))[Research[1]] - Research[2] )< 1e-6 or abs( geompy.PointCoordinates(geompy.GetVertexByIndex(Edge,1))[Research[1]] - Research[2] )< 1e-6 : + AcceptedObj.append(Edge) + else : + CenterSrchPar = {'NE' : lambda : [-1., -1.], + 'NW' : lambda : [ 1., -1.], + 'SW' : lambda : [ 1., 1.], + 'SE' : lambda : [-1., 1.], }[self.MeshPar[1]]() + Radius = self.GeoPar[1][1]*float(self.MeshPar[2])/(self.MeshPar[2]+1) + Center = (self.GeoPar[0][0]+CenterSrchPar[0]*self.GeoPar[1][0]/2.,self.GeoPar[0][1]+CenterSrchPar[1]*self.GeoPar[1][1]/2.,0.) + for i,ElemObj in enumerate(self.GeoChildren): + EdgeIDs = geompy.ExtractShapes(ElemObj,6)# List of Edge IDs belonging to ElemObj + for Edge in EdgeIDs: + if GenFunctions.IsOnCircle(Edge,Center,Radius): + AcceptedObj.append(Edge) + return AcceptedObj + + def PrincipleBoxes (self): + """ + This function returns all possible combination rectangular shape objects that can contain at least 3 of the principle vertices + constituting the MacObject. This is indispensable for the Non-ortho types and shall return a number of 24 possible combinations + """ + from itertools import combinations + Boxes = [] + if self.Type == 'NonOrtho': + for combi in combinations(list(range(4)),3): + Xmin = min([self.PtCoor[i][0] for i in combi]) + Xmax = max([self.PtCoor[i][0] for i in combi]) + Ymin = min([self.PtCoor[i][1] for i in combi]) + Ymax = max([self.PtCoor[i][1] for i in combi]) + Boxes.append([(0.5*(Xmin+Xmax),0.5*(Ymin+Ymax)),(Xmax-Xmin,Ymax-Ymin)]) + else : + Boxes = [self.GeoPar] + + return Boxes diff --cc src/Tools/MacMesh/MacMesh/PublishGroups.py index 172d632d0,a5d363c14..7b768d84f --- a/src/Tools/MacMesh/MacMesh/PublishGroups.py +++ b/src/Tools/MacMesh/MacMesh/PublishGroups.py @@@ -31,216 -31,217 +31,216 @@@ smesh = smeshBuilder.New( ########################################################################################################## def PublishGroups (): - aFilterManager = smesh.CreateFilterManager() + aFilterManager = smesh.CreateFilterManager() - # Building geometric and mesh compounds and groups ############################################## - if Config.debug : print "Searching for geometric groups and publishing final compound" - + # Building geometric and mesh compounds and groups ############################################## + if Config.debug : print("Searching for geometric groups and publishing final compound") + + TempGEOList = [] + TempMESHList = [] + + for MacroObj in Config.ListObj : + TempGEOList += MacroObj.GeoChildren + TempMESHList += MacroObj.Mesh + + FinalCompound = geompy.MakeCompound(TempGEOList) + geompy.addToStudy (FinalCompound,Config.StudyName) + MeshCompound = smesh.Concatenate(TempMESHList, 1, 1, 1e-5) + MeshCompound.SetName(Config.StudyName) + + GroupGEO = [] + for group in Config.Groups : + + # Geometric groups definition TempGEOList = [] - TempMESHList = [] - - for MacroObj in Config.ListObj : - TempGEOList += MacroObj.GeoChildren - TempMESHList += MacroObj.Mesh - - FinalCompound = geompy.MakeCompound(TempGEOList) - geompy.addToStudy (FinalCompound,Config.StudyName) - MeshCompound = smesh.Concatenate(TempMESHList, 1, 1, 1e-5) - MeshCompound.SetName(Config.StudyName) - - GroupGEO = [] - for group in Config.Groups : - - # Geometric groups definition - TempGEOList = [] - TempNames = [] - for MacroObj in Config.ListObj : - if group in MacroObj.GroupNames : - Occurences = IndexMultiOcc(MacroObj.GroupNames, group) - for Occ in Occurences : - TempGEOList += MacroObj.GetBorder(Occ) - GroupGEO.append(geompy.MakeCompound(TempGEOList)) - geompy.addToStudyInFather(FinalCompound,GroupGEO[-1],'GR_'+group) - - # Mesh groups definition - Criterion = smesh.GetCriterion(SMESH.EDGE, SMESH.FT_BelongToGeom,'=',GroupGEO[-1],Tolerance=1e-06) - #Criterion = smesh.Filter.Criterion(18,39,0,'GR_'+group,'GR_'+group,39,39,1e-06,smesh.EDGE,7) - MeshCompound.MakeGroupByCriterion(group,Criterion) - - StudyBuilder = Config.theStudy.NewBuilder() - for MeshObj in TempMESHList: - SO = Config.theStudy.FindObjectIOR(Config.theStudy.ConvertObjectToIOR(MeshObj)) - if SO is not None: StudyBuilder.RemoveObjectWithChildren(SO) - - return MeshCompound - + TempNames = [] + for MacroObj in Config.ListObj : + if group in MacroObj.GroupNames : + Occurences = IndexMultiOcc(MacroObj.GroupNames, group) + for Occ in Occurences : + TempGEOList += MacroObj.GetBorder(Occ) + GroupGEO.append(geompy.MakeCompound(TempGEOList)) + geompy.addToStudyInFather(FinalCompound,GroupGEO[-1],'GR_'+group) + + # Mesh groups definition + Criterion = smesh.GetCriterion(SMESH.EDGE, SMESH.FT_BelongToGeom,'=',GroupGEO[-1],Tolerance=1e-06) + #Criterion = smesh.Filter.Criterion(18,39,0,'GR_'+group,'GR_'+group,39,39,1e-06,smesh.EDGE,7) + MeshCompound.MakeGroupByCriterion(group,Criterion) + + StudyBuilder = Config.theStudy.NewBuilder() + for MeshObj in TempMESHList: + SO = Config.theStudy.FindObjectIOR(Config.theStudy.ConvertObjectToIOR(MeshObj)) + if SO is not None: StudyBuilder.RemoveObjectWithChildren(SO) + + return MeshCompound + def IndexMultiOcc (Array,Element) : - """ - This function returns the occurrences indices of Element in Array. - As opposed to Array.index(Element) method, this allows determining - multiple entries rather than just the first one! - """ - Output = [] - try : Array.index(Element) - except ValueError : print "No more occurrences" - else : Output.append(Array.index(Element)) - - if not(Output == [-1]) and len(Array) > 1 : - for index, ArrElem in enumerate(Array[Output[0]+1:]) : - if ArrElem is Element : Output.append(index+Output[0]+1) - - return Output - + """ + This function returns the occurrences indices of Element in Array. + As opposed to Array.index(Element) method, this allows determining + multiple entries rather than just the first one! + """ + Output = [] + try : Array.index(Element) + except ValueError : print("No more occurrences") + else : Output.append(Array.index(Element)) + + if not(Output == [-1]) and len(Array) > 1 : + for index, ArrElem in enumerate(Array[Output[0]+1:]) : + if ArrElem is Element : Output.append(index+Output[0]+1) + + return Output + def Publish (ObjToPublish): - for i,GeoObj in enumerate(ObjToPublish) : geompy.addToStudy(GeoObj,"Sub_"+str(i)) - + for i,GeoObj in enumerate(ObjToPublish) : geompy.addToStudy(GeoObj,"Sub_"+str(i)) + def RevolveMesh(MainMesh,**args): - """ - This function premits to revolute and scale a 2D mesh while transforming the edge - groups into face groups. Moreover, the function automatically creates the face groups - corresponding to the symmetry lower and upper faces - Facultatif arguments are : - - Center [X,Y,Z], origin being the default - - Direction [VX,VY,VZ], x-axis being the default - - AngleDeg or AngleRad : ALPHA, 10 degrees being the default - - Scale : BETA, no scaling being default - """ - ################################################################################ - # Reading input arguments and proceeding to defaults if necessary - ################################################################################ - if 'Center' in args : CenterCoor = [float(Coor) for Coor in args['Center']] - else : - print("\nThe coordinates of the center of revolution were not given\nThe origin is used by default.") - CenterCoor = [0.,0.,0.] - - if 'Direction' in args : Direction = [float(Dir) for Dir in args['Direction']] - else : - print("\nThe axis vector of revolution was not given\nThe x-axis is used by default.") - Direction = [1.,0.,0.] - - if 'AngleDeg' in args : Angle = float(args['AngleDeg'])*math.pi/180. - elif 'AngleRad' in args : Angle = float(args['AngleRad']) - else : - print("\nThe revolution angle was not given\nAn angle of 10 degrees is used by default.") - Angle = 10.*math.pi/180. - - if 'Scale' in args : Scale = float(args['Scale']) - else : Scale = 1. - - - # Creating the lower face group LOFAC - LOFAC = MainMesh.CreateEmptyGroup( SMESH.FACE, 'LOFAC' ) - LOFAC.AddFrom(MainMesh.GetMesh()) - - GR_Names = MainMesh.GetGroupNames() - GRs = MainMesh.GetGroups() - Rev3DMeshGroups = MainMesh.RotationSweepObject2D( MainMesh, SMESH.AxisStruct( CenterCoor[0], CenterCoor[1], CenterCoor[2], Direction[0], Direction[1], Direction[2] ), Angle, 1, 1e-05 ,True) - - # Adding an EDGE suffix to the edge groups (to be deleted eventually by the user...) - for GR in GRs: - CurrentName = GR.GetName() - if CurrentName in GR_Names and not(CurrentName=='LOFAC'): # Meaning that this is an old edge group - GR.SetName(CurrentName+'_EDGE') - - # Removing the _rotated prefix from the rotated FACE groups - for GR in Rev3DMeshGroups: - CurrentName = GR.GetName() - if CurrentName.endswith( "_rotated"): - if CurrentName.startswith( 'LOFAC_' ): - GR.SetName('VOL') - else: - GR.SetName(CurrentName[:-8]) - elif CurrentName == 'LOFAC_top': - GR.SetName('HIFAC') - #Index = [ GR_Names[i] in CurrentName for i in range(0,len(GR_Names)) ].index(True) - #GR.SetName(GR_Names[Index]) - - # Creating the upper face group HIFAC - ALLFAC = MainMesh.CreateEmptyGroup( SMESH.FACE, 'ALLFAC' ) - ALLFAC.AddFrom(MainMesh.GetMesh()) - - #HIFAC = MainMesh.GetMesh().CutListOfGroups( [ ALLFAC ], [LOFAC] + [ MeshGroup for MeshGroup in Rev3DMeshGroups if not(MeshGroup.GetName()=='VOL') ], 'HIFAC' ) - #HIFAC = MainMesh.GetMesh().CutListOfGroups( [ ALLFAC ], [LOFAC] + [ MeshGroup for MeshGroup in Rev3DMeshGroups if ( not(MeshGroup.GetName()=='VOL') and MeshGroup.GetType() == SMESH.FACE )], 'HIFAC' ) - - # Scaling down the mesh to meter units - if not(Scale==1.): - MeshEditor = MainMesh.GetMeshEditor() - MeshEditor.Scale( MainMesh.GetMesh(), SMESH.PointStruct( 0, 0, 0 ) ,[ Scale, Scale, Scale ], 0 ) - - + """ + This function permits to revolute and scale a 2D mesh while transforming the edge + groups into face groups. Moreover, the function automatically creates the face groups + corresponding to the symmetry lower and upper faces + Facultatif arguments are : + - Center [X,Y,Z], origin being the default + - Direction [VX,VY,VZ], x-axis being the default + - AngleDeg or AngleRad : ALPHA, 10 degrees being the default + - Scale : BETA, no scaling being default + """ + ################################################################################ + # Reading input arguments and proceeding to defaults if necessary + ################################################################################ + if 'Center' in args : CenterCoor = [float(Coor) for Coor in args['Center']] + else : - print "\nThe coordinates of the center of revolution were not given\nThe origin is used by default." ++ print("\nThe coordinates of the center of revolution were not given\nThe origin is used by default.") + CenterCoor = [0.,0.,0.] + + if 'Direction' in args : Direction = [float(Dir) for Dir in args['Direction']] + else : - print "\nThe axis vector of revolution was not given\nThe x-axis is used by default." ++ print("\nThe axis vector of revolution was not given\nThe x-axis is used by default.") + Direction = [1.,0.,0.] + + if 'AngleDeg' in args : Angle = float(args['AngleDeg'])*math.pi/180. + elif 'AngleRad' in args : Angle = float(args['AngleRad']) + else : - print "\nThe revolution angle was not given\nAn angle of 10 degrees is used by default." ++ print("\nThe revolution angle was not given\nAn angle of 10 degrees is used by default.") + Angle = 10.*math.pi/180. + + if 'Scale' in args : Scale = float(args['Scale']) + else : Scale = 1. + + + # Creating the lower face group LOFAC + LOFAC = MainMesh.CreateEmptyGroup( SMESH.FACE, 'LOFAC' ) + LOFAC.AddFrom(MainMesh.GetMesh()) + + GR_Names = MainMesh.GetGroupNames() + GRs = MainMesh.GetGroups() + Rev3DMeshGroups = MainMesh.RotationSweepObject2D( MainMesh, SMESH.AxisStruct( CenterCoor[0], CenterCoor[1], CenterCoor[2], Direction[0], Direction[1], Direction[2] ), Angle, 1, 1e-05 ,True) + + # Adding an EDGE suffix to the edge groups (to be deleted eventually by the user...) + for GR in GRs: + CurrentName = GR.GetName() + if CurrentName in GR_Names and not(CurrentName=='LOFAC'): # Meaning that this is an old edge group + GR.SetName(CurrentName+'_EDGE') + + # Removing the _rotated prefix from the rotated FACE groups + for GR in Rev3DMeshGroups: + CurrentName = GR.GetName() + if CurrentName.endswith( "_rotated"): + if CurrentName.startswith( 'LOFAC_' ): + GR.SetName('VOL') + else: + GR.SetName(CurrentName[:-8]) + elif CurrentName == 'LOFAC_top': + GR.SetName('HIFAC') + #Index = [ GR_Names[i] in CurrentName for i in range(0,len(GR_Names)) ].index(True) + #GR.SetName(GR_Names[Index]) + + # Creating the upper face group HIFAC + ALLFAC = MainMesh.CreateEmptyGroup( SMESH.FACE, 'ALLFAC' ) + ALLFAC.AddFrom(MainMesh.GetMesh()) + + #HIFAC = MainMesh.GetMesh().CutListOfGroups( [ ALLFAC ], [LOFAC] + [ MeshGroup for MeshGroup in Rev3DMeshGroups if not(MeshGroup.GetName()=='VOL') ], 'HIFAC' ) + #HIFAC = MainMesh.GetMesh().CutListOfGroups( [ ALLFAC ], [LOFAC] + [ MeshGroup for MeshGroup in Rev3DMeshGroups if ( not(MeshGroup.GetName()=='VOL') and MeshGroup.GetType() == SMESH.FACE )], 'HIFAC' ) + + # Scaling down the mesh to meter units + if not(Scale==1.): + MeshEditor = MainMesh.GetMeshEditor() + MeshEditor.Scale( MainMesh.GetMesh(), SMESH.PointStruct( 0, 0, 0 ) ,[ Scale, Scale, Scale ], 0 ) + + def ExtrudeMesh(MainMesh,**args): - """ - This function premits to extrude and scale a 2D mesh while transforming the edge - groups into face groups. Moreover, the function automatically creates the face groups - corresponding to the symmetry lower and upper faces - Facultatif arguments are : - - Direction [VX,VY,VZ], z-axis being default - - Distance : D, default is 1 - - NSteps : the object will be extruded by NSteps*Distance, default is Nsteps = 1 - - Scale : BETA, no scaling being default - """ - ################################################################################ - # Reading input arguments and proceeding to defaults if necessary - ################################################################################ - if 'Distance' in args : Distance = float(args['Distance']) - else : - print("\nThe extrusion distance was not given\nA default value of 1 is used.") - Distance = 1. - - if 'Direction' in args : Direction = NormalizeVector([float(Dir) for Dir in args['Direction']],Distance) - else : - print("\nThe extrusion vector of revolution was not given\nThe z-axis is used by default.") - Direction = NormalizeVector([0.,0.,1.],Distance) - - if 'Scale' in args : Scale = float(args['Scale']) - else : Scale = 1. - - if 'NSteps' in args : NSteps = int(args['NSteps']) - else : NSteps = 1 - - # Creating the lower face group LOFAC - LOFAC = MainMesh.CreateEmptyGroup( SMESH.FACE, 'LOFAC' ) - LOFAC.AddFrom(MainMesh.GetMesh()) - - GR_Names = MainMesh.GetGroupNames() - GRs = MainMesh.GetGroups() - Ext3DMeshGroups = MainMesh.ExtrusionSweepObject2D(MainMesh,SMESH.DirStruct(SMESH.PointStruct(Direction[0],Direction[1],Direction[2])), NSteps, True) - - # Adding an EDGE suffix to the edge groups (to be deleted eventually by the user...) - for GR in GRs: - CurrentName = GR.GetName() - if CurrentName in GR_Names and not(CurrentName=='LOFAC'): # Meaning that this is an old edge group - GR.SetName(CurrentName+'_EDGE') - - # Removing the _extruded suffix from the extruded FACE groups - for GR in Ext3DMeshGroups: - CurrentName = GR.GetName() - if CurrentName.endswith( "_extruded"): - if CurrentName.startswith( 'LOFAC_' ): - GR.SetName('VOL') - else: - GR.SetName(CurrentName[:-9]) - elif CurrentName == 'LOFAC_top': - GR.SetName('HIFAC') - - # Creating the upper face group HIFAC - ALLFAC = MainMesh.CreateEmptyGroup( SMESH.FACE, 'ALLFAC' ) - ALLFAC.AddFrom(MainMesh.GetMesh()) - - #HIFAC = MainMesh.GetMesh().CutListOfGroups( [ ALLFAC ], [LOFAC] + [ MeshGroup for MeshGroup in Ext3DMeshGroups if not(MeshGroup.GetName()=='VOL') ], 'HIFAC' ) - - # Scaling down the mesh to meter units - if not(Scale==1.): - MeshEditor = MainMesh.GetMeshEditor() - MeshEditor.Scale( MainMesh.GetMesh(), SMESH.PointStruct( 0, 0, 0 ) ,[ Scale, Scale, Scale ], 0 ) - - + """ + This function permits to extrude and scale a 2D mesh while transforming the edge + groups into face groups. Moreover, the function automatically creates the face groups + corresponding to the symmetry lower and upper faces + Facultatif arguments are : + - Direction [VX,VY,VZ], z-axis being default + - Distance : D, default is 1 + - NSteps : the object will be extruded by NSteps*Distance, default is Nsteps = 1 + - Scale : BETA, no scaling being default + """ + ################################################################################ + # Reading input arguments and proceeding to defaults if necessary + ################################################################################ + if 'Distance' in args : Distance = float(args['Distance']) + else : - print "\nThe extrusion distance was not given\nA default value of 1 is used." ++ print("\nThe extrusion distance was not given\nA default value of 1 is used.") + Distance = 1. + + if 'Direction' in args : Direction = NormalizeVector([float(Dir) for Dir in args['Direction']],Distance) + else : - print "\nThe extrusion vector of revolution was not given\nThe z-axis is used by default." ++ print("\nThe extrusion vector of revolution was not given\nThe z-axis is used by default.") + Direction = NormalizeVector([0.,0.,1.],Distance) + + if 'Scale' in args : Scale = float(args['Scale']) + else : Scale = 1. + + if 'NSteps' in args : NSteps = int(args['NSteps']) + else : NSteps = 1 + + # Creating the lower face group LOFAC + LOFAC = MainMesh.CreateEmptyGroup( SMESH.FACE, 'LOFAC' ) + LOFAC.AddFrom(MainMesh.GetMesh()) + + GR_Names = MainMesh.GetGroupNames() + GRs = MainMesh.GetGroups() + Ext3DMeshGroups = MainMesh.ExtrusionSweepObject2D(MainMesh,SMESH.DirStruct(SMESH.PointStruct(Direction[0],Direction[1],Direction[2])), NSteps, True) + + # Adding an EDGE suffix to the edge groups (to be deleted eventually by the user...) + for GR in GRs: + CurrentName = GR.GetName() + if CurrentName in GR_Names and not(CurrentName=='LOFAC'): # Meaning that this is an old edge group + GR.SetName(CurrentName+'_EDGE') + + # Removing the _extruded suffix from the extruded FACE groups + for GR in Ext3DMeshGroups: + CurrentName = GR.GetName() + if CurrentName.endswith( "_extruded"): + if CurrentName.startswith( 'LOFAC_' ): + GR.SetName('VOL') + else: + GR.SetName(CurrentName[:-9]) + elif CurrentName == 'LOFAC_top': + GR.SetName('HIFAC') + + # Creating the upper face group HIFAC + ALLFAC = MainMesh.CreateEmptyGroup( SMESH.FACE, 'ALLFAC' ) + ALLFAC.AddFrom(MainMesh.GetMesh()) + + #HIFAC = MainMesh.GetMesh().CutListOfGroups( [ ALLFAC ], [LOFAC] + [ MeshGroup for MeshGroup in Ext3DMeshGroups if not(MeshGroup.GetName()=='VOL') ], 'HIFAC' ) + + # Scaling down the mesh to meter units + if not(Scale==1.): + MeshEditor = MainMesh.GetMeshEditor() + MeshEditor.Scale( MainMesh.GetMesh(), SMESH.PointStruct( 0, 0, 0 ) ,[ Scale, Scale, Scale ], 0 ) + + def NormalizeVector (V,Norm): - """ - This function returns a normalized vector (magnitude = Norm), parallel to the entered one - """ - V = [float(Coor) for Coor in V] - Norm = float(Norm) - MagV = math.sqrt(V[0]*V[0]+V[1]*V[1]+V[2]*V[2]) - return [Coor*Norm/MagV for Coor in V] - + """ + This function returns a normalized vector (magnitude = Norm), parallel to the entered one + """ + V = [float(Coor) for Coor in V] + Norm = float(Norm) + MagV = math.sqrt(V[0]*V[0]+V[1]*V[1]+V[2]*V[2]) + return [Coor*Norm/MagV for Coor in V] diff --cc src/Tools/ZCracksPlug/CMakeLists.txt index cc77ad1a7,2f87a5cf1..9ab6df413 --- a/src/Tools/ZCracksPlug/CMakeLists.txt +++ b/src/Tools/ZCracksPlug/CMakeLists.txt @@@ -41,25 -44,23 +43,31 @@@ SET(_command_SCRIPT zcracksLaunch.py ) - # --- resources --- - - # uic files / to be processed by pyuic - SET(_pyuic_files - zcracks.ui - ) + IF(SALOME_BUILD_GUI) + # uic files / to be processed by pyuic + SET(_pyuic_FILES + zcracks.ui + ) + +# qrc files / to be processed by pyrcc - SET(_pyqrcc_files ++SET(_pyqrc_FILES + images.qrc +) + - # scripts / pyuic wrappings - PYQT_WRAP_UIC(_pyuic_SCRIPTS ${_pyuic_files} OPTIONS "--import-from=Zcracks" "--resource-suffix=_qrc") - PYQT_WRAP_QRC(_pyqrc_SCRIPTS ${_pyqrcc_files}) + # scripts / pyuic wrappings - PYQT_WRAP_UIC(_pyuic_SCRIPTS ${_pyuic_FILES} TARGET_NAME _target_name_pyuic) ++ PYQT_WRAP_UIC(_pyuic_SCRIPTS ${_pyuic_FILES} TARGET_NAME _target_name_pyuic OPTIONS "--import-from=Zcracks" "--resource-suffix=_qrc") ++ PYQT_WRAP_QRC(_pyqrc_SCRIPTS ${_pyqrc_FILES}) + ENDIF(SALOME_BUILD_GUI) # --- rules --- - SALOME_INSTALL_SCRIPTS("${plugin_SCRIPTS}" ${SALOME_INSTALL_PYTHON}/Zcracks) - SALOME_INSTALL_SCRIPTS("${_pyuic_SCRIPTS}" ${SALOME_INSTALL_PYTHON}/Zcracks) - SALOME_INSTALL_SCRIPTS("${_pyqrc_SCRIPTS}" ${SALOME_INSTALL_PYTHON}/Zcracks) - SALOME_INSTALL_SCRIPTS("${command_SCRIPTS}" ${SALOME_INSTALL_BINS}) + SALOME_INSTALL_SCRIPTS("${_plugin_SCRIPTS}" ${SALOME_INSTALL_PYTHON}/Zcracks) + SALOME_INSTALL_SCRIPTS("${_command_SCRIPTS}" ${SALOME_INSTALL_BINS}) + IF(SALOME_BUILD_GUI) + SALOME_INSTALL_SCRIPTS("${_pyuic_SCRIPTS}" ${SALOME_INSTALL_PYTHON}/Zcracks TARGET_NAME _target_name_pyuic_py) ++ SALOME_INSTALL_SCRIPTS("${_pyqrc_SCRIPTS}" ${SALOME_INSTALL_PYTHON}/Zcracks) + # add dependency of compiled py files on uic files in order + # to avoid races problems when compiling in parallel + ADD_DEPENDENCIES(${_target_name_pyuic_py} ${_target_name_pyuic}) + ENDIF(SALOME_BUILD_GUI) + diff --cc src/Tools/ZCracksPlug/casTests/genereCube.py index b26bc63ac,2ab20472e..94ff1c0be --- a/src/Tools/ZCracksPlug/casTests/genereCube.py +++ b/src/Tools/ZCracksPlug/casTests/genereCube.py @@@ -7,10 -7,10 +7,9 @@@ import salome salome.salome_init() --theStudy = salome.myStudy import salome_notebook --notebook = salome_notebook.NoteBook(theStudy) ++notebook = salome_notebook.NoteBook() ### ### GEOM component @@@ -25,7 -25,7 +24,7 @@@ def cube3D(L, N, outFile) N=int(N) from salome.geom import geomBuilder -- geompy = geomBuilder.New(theStudy) ++ geompy = geomBuilder.New() eps=L*1.e-6 @@@ -69,7 -69,7 +68,7 @@@ from salome.smesh import smeshBuilder import SMESH -- smesh = smeshBuilder.New(theStudy) ++ smesh = smeshBuilder.New() Nb_Segments_1 = smesh.CreateHypothesis('NumberOfSegments') Nb_Segments_1.SetNumberOfSegments( N ) Length_From_Edges_1 = smesh.CreateHypothesis('LengthFromEdges') @@@ -109,10 -109,10 +108,10 @@@ aFilter_1.SetMesh(Maillage_1.GetMesh()) FACE_temp = Maillage_1.GroupOnFilter( SMESH.FACE, noms[cont], aFilter_1 ) - Maillage_1.ExportMED( outFile, 0, SMESH.MED_V2_2, 1, None ,1) + Maillage_1.ExportMED(outFile) #if salome.sg.hasDesktop(): - #salome.sg.updateObjBrowser(True) - #salome.sg.updateObjBrowser(1) ++ #salome.sg.updateObjBrowser() @@@ -121,7 -121,7 +120,7 @@@ def cube2D(L, N, outFile) N=int(N) from salome.geom import geomBuilder -- geompy = geomBuilder.New(theStudy) ++ geompy = geomBuilder.New() eps=L*1.e-6 @@@ -156,7 -156,7 +155,7 @@@ from salome.smesh import smeshBuilder import SMESH -- smesh = smeshBuilder.New(theStudy) ++ smesh = smeshBuilder.New() Nb_Segments_1 = smesh.CreateHypothesis('NumberOfSegments') Nb_Segments_1.SetNumberOfSegments( N ) Length_From_Edges_1 = smesh.CreateHypothesis('LengthFromEdges') @@@ -191,7 -191,7 +190,7 @@@ aFilter_1.SetMesh(Maillage_1.GetMesh()) EDGE_temp = Maillage_1.GroupOnFilter( SMESH.EDGE, noms[cont], aFilter_1 ) - Maillage_1.ExportMED( outFile, 0, SMESH.MED_V2_2, 1, None ,1) + Maillage_1.ExportMED(outFile) #if salome.sg.hasDesktop(): - #salome.sg.updateObjBrowser(True) - #salome.sg.updateObjBrowser(1) ++ #salome.sg.updateObjBrowser() diff --cc src/Tools/ZCracksPlug/ellipse.py index 9f599892a,9ffeb8b66..4aa93106e --- a/src/Tools/ZCracksPlug/ellipse.py +++ b/src/Tools/ZCracksPlug/ellipse.py @@@ -9,10 -9,10 +9,9 @@@ import sys, nump import salome salome.salome_init() --theStudy = salome.myStudy import salome_notebook --notebook = salome_notebook.NoteBook(theStudy) ++notebook = salome_notebook.NoteBook() ### ### GEOM component @@@ -45,7 -45,7 +44,7 @@@ def generate(data_demi_grand_axe, data_ Vnormale, Vdirection, Vortho = uF.calcCoordVectors(data_normale, data_direction) Vcentre = numpy.array(data_centre) -- geompy = geomBuilder.New(theStudy) ++ geompy = geomBuilder.New() O = geompy.MakeVertex(0, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0) @@@ -172,7 -172,7 +171,7 @@@ import SMESH, SALOMEDS from salome.smesh import smeshBuilder -- smesh = smeshBuilder.New(theStudy) ++ smesh = smeshBuilder.New() A=numpy.pi/(30.) minAxes=numpy.min([data_demi_grand_axe,data_demi_petit_axe]) @@@ -199,4 -199,4 +198,4 @@@ if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) - salome.sg.updateObjBrowser(1) ++ salome.sg.updateObjBrowser() diff --cc src/Tools/ZCracksPlug/genereCrack.py index 1628cd465,372772b43..ebec86ad4 --- a/src/Tools/ZCracksPlug/genereCrack.py +++ b/src/Tools/ZCracksPlug/genereCrack.py @@@ -212,13 -212,13 +212,12 @@@ def generateCustom(crack, outFile) import salome salome.salome_init() -- theStudy = salome.myStudy import salome_notebook -- notebook = salome_notebook.NoteBook(theStudy) ++ notebook = salome_notebook.NoteBook() import SMESH, SALOMEDS from salome.smesh import smeshBuilder -- smesh = smeshBuilder.New(theStudy) ++ smesh = smeshBuilder.New() ([Maillage_1], status) = smesh.CreateMeshesFromMED(crack['med file']) isCrack=False for group in Maillage_1.GetGroups(): diff --cc src/Tools/ZCracksPlug/main.py index fb75c82e1,4d3384de0..ecc73966b --- a/src/Tools/ZCracksPlug/main.py +++ b/src/Tools/ZCracksPlug/main.py @@@ -431,9 -431,9 +431,8 @@@ class ShipHolderApplication(QGroupBox) else: import SMESH, salome #salome.salome_init() -- theStudy = salome.myStudy from salome.smesh import smeshBuilder -- smesh = smeshBuilder.New(theStudy) ++ smesh = smeshBuilder.New() ([objetSain], status) = smesh.CreateMeshesFromMED(saneFile) diff --cc src/Tools/ZCracksPlug/rectangle.py index f885150eb,2f6933e25..6a6e15f9d --- a/src/Tools/ZCracksPlug/rectangle.py +++ b/src/Tools/ZCracksPlug/rectangle.py @@@ -8,10 -8,10 +8,9 @@@ import sys, nump import salome salome.salome_init() --theStudy = salome.myStudy import salome_notebook --notebook = salome_notebook.NoteBook(theStudy) ++notebook = salome_notebook.NoteBook() ### ### GEOM component @@@ -65,7 -65,7 +64,7 @@@ def generate(data_longueur,data_largeur Vnormale, Vdirection, Vortho = uF.calcCoordVectors(data_normale, data_direction) Vcentre = numpy.array(data_centre) -- geompy = geomBuilder.New(theStudy) ++ geompy = geomBuilder.New() O = geompy.MakeVertex(0, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0) @@@ -211,7 -211,7 +210,7 @@@ import SMESH, SALOMEDS from salome.smesh import smeshBuilder -- smesh = smeshBuilder.New(theStudy) ++ smesh = smeshBuilder.New() Maillage=uF.meshCrack(FACE_FISSURE, minSize, maxSize, chordal, dim) @@@ -223,4 -223,4 +222,4 @@@ if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) - salome.sg.updateObjBrowser(1) ++ salome.sg.updateObjBrowser() diff --cc src/Tools/ZCracksPlug/sphere.py index 04e75bb74,79542b2c5..4ea4ea8cb --- a/src/Tools/ZCracksPlug/sphere.py +++ b/src/Tools/ZCracksPlug/sphere.py @@@ -8,10 -8,10 +8,9 @@@ import sys, nump import salome salome.salome_init() --theStudy = salome.myStudy import salome_notebook --notebook = salome_notebook.NoteBook(theStudy) ++notebook = salome_notebook.NoteBook() ### ### GEOM component @@@ -30,7 -30,7 +29,7 @@@ def generate(data_rayon,data_centre,out #data_rayon = 0.1 #data_centre = [1., 1., 01.] -- geompy = geomBuilder.New(theStudy) ++ geompy = geomBuilder.New() O = geompy.MakeVertex(0, 0, 0) OX = geompy.MakeVectorDXDYDZ(1, 0, 0) @@@ -48,7 -48,7 +47,7 @@@ import SMESH, SALOMEDS from salome.smesh import smeshBuilder -- smesh = smeshBuilder.New(theStudy) ++ smesh = smeshBuilder.New() A=numpy.pi/(20.) chordal, minSize = uF.calcElemSize(A, data_rayon) @@@ -67,4 -67,4 +66,4 @@@ if salome.sg.hasDesktop(): - salome.sg.updateObjBrowser(True) - salome.sg.updateObjBrowser(1) ++ salome.sg.updateObjBrowser() diff --cc src/Tools/ZCracksPlug/utilityFunctions.py index 0acde8671,9571fd8d9..e7aab2a28 --- a/src/Tools/ZCracksPlug/utilityFunctions.py +++ b/src/Tools/ZCracksPlug/utilityFunctions.py @@@ -131,11 -131,11 +131,10 @@@ def meshCrack(geomObject, minSize, maxS import salome salome.salome_init() -- theStudy = salome.myStudy import SMESH, SALOMEDS from salome.smesh import smeshBuilder -- smesh = smeshBuilder.New(theStudy) ++ smesh = smeshBuilder.New() Maillage = smesh.Mesh(geomObject) if dim==3: @@@ -173,9 -173,9 +172,8 @@@ def extendElsets(meshFile, outFile=None import SMESH, salome #salome.salome_init() -- theStudy = salome.myStudy from salome.smesh import smeshBuilder -- smesh = smeshBuilder.New(theStudy) ++ smesh = smeshBuilder.New() ([mesh], status) = smesh.CreateMeshesFromMED(meshFile) diff --cc src/Tools/blocFissure/ihm/CMakeLists.txt index 64e0b3a18,a561ab816..1d24db51d --- a/src/Tools/blocFissure/ihm/CMakeLists.txt +++ b/src/Tools/blocFissure/ihm/CMakeLists.txt @@@ -37,9 -35,8 +35,8 @@@ SET(_pyuic_FILE fissureCoude.ui fissureGenerale.ui ) - # scripts / pyuic wrappings - PYQT_WRAP_UIC(_pyuic_SCRIPTS ${_pyuic_files} OPTIONS "--import-from=blocFissure" "--resource-suffix=_qrc") -PYQT_WRAP_UIC(_pyuic_SCRIPTS ${_pyuic_FILES} TARGET_NAME _target_name_pyuic) ++PYQT_WRAP_UIC(_pyuic_SCRIPTS ${_pyuic_FILES} TARGET_NAME _target_name_pyuic OPTIONS "--import-from=blocFissure" "--resource-suffix=_qrc") # --- rules --- diff --cc src/Tools/blocFissure/materielCasTests/decoupeCylindre.py index b5fe06e21,c43889c94..8e0077695 --- a/src/Tools/blocFissure/materielCasTests/decoupeCylindre.py +++ b/src/Tools/blocFissure/materielCasTests/decoupeCylindre.py @@@ -4,7 -4,7 +4,6 @@@ import sy import salome salome.salome_init() --theStudy = salome.myStudy import salome_notebook notebook = salome_notebook.notebook @@@ -149,8 -149,8 +148,8 @@@ SubMesh_1 = Regular_1D_1.GetSubMesh( SubMesh_2 = Regular_1D_2.GetSubMesh() ## some objects were removed --aStudyBuilder = theStudy.NewBuilder() --SO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR(smeshObj_1)) ++aStudyBuilder = salome.myStudy.NewBuilder() ++SO = salome.myStudy.FindObjectIOR(salome.myStudy.ConvertObjectToIOR(smeshObj_1)) if SO is not None: aStudyBuilder.RemoveObjectWithChildren(SO) ## set object names smesh.SetName(CylindreSain_1.GetMesh(), 'CylindreSain')