Salome HOME
2d1e10c165906c40776ccded4f72a2fcf5e6eb45
[modules/smesh.git] / src / SMESH / SMESH_Hypothesis.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH : implementaion of SMESH idl descriptions
24 //  File   : SMESH_Hypothesis.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //
28 #include "SMESH_Hypothesis.hxx"
29
30 #include "SMESHDS_Mesh.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_Mesh.hxx"
33 #include "SMESH_subMesh.hxx"
34
35 #include "utilities.h"
36
37 using namespace std;
38
39 //=============================================================================
40 /*!
41  * 
42  */
43 //=============================================================================
44
45 SMESH_Hypothesis::SMESH_Hypothesis(int hypId,
46                                    int studyId,
47                                    SMESH_Gen* gen) : SMESHDS_Hypothesis(hypId)
48 {
49   _gen            = gen;
50   _studyId        = studyId;
51   _type           = PARAM_ALGO;
52   _shapeType      = 0;  // to be set by algo with TopAbs_Enum
53   _param_algo_dim = -1; // to be set by algo parameter
54   StudyContextStruct* myStudyContext = gen->GetStudyContext(_studyId);
55   myStudyContext->mapHypothesis[hypId] = this;
56 }
57
58 //=============================================================================
59 /*!
60  * 
61  */
62 //=============================================================================
63
64 SMESH_Hypothesis::~SMESH_Hypothesis()
65 {
66   StudyContextStruct* myStudyContext = _gen->GetStudyContext(_studyId);
67   myStudyContext->mapHypothesis[_hypId] = 0;
68 }
69
70 //=============================================================================
71 /*!
72  * 
73  */
74 //=============================================================================
75
76 int SMESH_Hypothesis::GetDim() const
77 {
78   int dim = 0;
79   switch (_type)
80     {
81     case ALGO_1D: dim = 1; break;
82     case ALGO_2D: dim = 2; break;
83     case ALGO_3D: dim = 3; break;
84     case ALGO_0D: dim = 0; break;
85     case PARAM_ALGO:
86       dim = ( _param_algo_dim < 0 ) ? -_param_algo_dim : _param_algo_dim; break;
87     }
88   return dim;
89 }
90
91 //=============================================================================
92 /*!
93  *  
94  */
95 //=============================================================================
96
97 int SMESH_Hypothesis::GetShapeType() const
98 {
99   return _shapeType;
100 }
101
102 //=============================================================================
103 /*!
104  * 
105  */
106 //=============================================================================
107
108 int SMESH_Hypothesis::GetStudyId() const
109 {
110   return _studyId;
111 }
112
113 //=============================================================================
114 /*!
115  * 
116  */
117 //=============================================================================
118
119 void SMESH_Hypothesis::NotifySubMeshesHypothesisModification()
120 {
121   // for all meshes in study
122
123   StudyContextStruct* myStudyContext = _gen->GetStudyContext(_studyId);
124   map<int, SMESH_Mesh*>::iterator itm;
125   for (itm = myStudyContext->mapMesh.begin();
126        itm != myStudyContext->mapMesh.end();
127        itm++)
128   {
129     SMESH_Mesh* mesh = (*itm).second;
130     mesh->NotifySubMeshesHypothesisModification( this );
131   }
132 }
133
134 //=============================================================================
135 /*!
136  *
137  */
138 //=============================================================================
139
140 const char* SMESH_Hypothesis::GetLibName() const
141 {
142   return _libName.c_str();
143 }
144
145 //=============================================================================
146 /*!
147  * 
148  */
149 //=============================================================================
150
151 void SMESH_Hypothesis::SetLibName(const char* theLibName)
152 {
153   _libName = string(theLibName);
154 }
155
156 //=======================================================================
157 //function : GetMeshByPersistentID
158 //purpose  : Find a mesh with given persistent ID
159 //=======================================================================
160
161 SMESH_Mesh* SMESH_Hypothesis::GetMeshByPersistentID(int id)
162 {
163   StudyContextStruct* myStudyContext = _gen->GetStudyContext(_studyId);
164   map<int, SMESH_Mesh*>::iterator itm = myStudyContext->mapMesh.begin();
165   for ( ; itm != myStudyContext->mapMesh.end(); itm++)
166   {
167     SMESH_Mesh* mesh = (*itm).second;
168     if ( mesh->GetMeshDS()->GetPersistentId() == id )
169       return mesh;
170   }
171   return 0;
172 }