Salome HOME
Movement of examples to CVS EXAMPLES SAMPLES_SRC.
[modules/smesh.git] / src / StdMeshers / StdMeshers_StartEndLength.cxx
1 //  SMESH StdMeshers_StartEndLength : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  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. 
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : StdMeshers_StartEndLength.cxx
25 //  Module : SMESH
26 //  $Header$
27
28 using namespace std;
29
30 #include "StdMeshers_StartEndLength.hxx"
31 #include "utilities.h"
32
33
34 //=============================================================================
35 /*!
36  *  
37  */
38 //=============================================================================
39
40 StdMeshers_StartEndLength::StdMeshers_StartEndLength(int         hypId,
41                                                      int         studyId,
42                                                      SMESH_Gen * gen)
43      :SMESH_Hypothesis(hypId, studyId, gen)
44 {
45   _begLength = 1.;
46   _endLength = 1.;
47   _name = "StartEndLength";
48   _param_algo_dim = 1; // is used by SMESH_Regular_1D
49 }
50
51 //=============================================================================
52 /*!
53  *  
54  */
55 //=============================================================================
56
57 StdMeshers_StartEndLength::~StdMeshers_StartEndLength()
58 {
59 }
60
61 //=============================================================================
62 /*!
63  *  
64  */
65 //=============================================================================
66
67 void StdMeshers_StartEndLength::SetLength(double length, bool isStartLength)
68      throw(SALOME_Exception)
69 {
70   if ( (isStartLength ? _begLength : _endLength) != length ) {
71     if (length <= 0)
72       throw SALOME_Exception(LOCALIZED("length must be positive"));
73     if ( isStartLength )
74       _begLength = length;
75     else
76       _endLength = length;
77
78     NotifySubMeshesHypothesisModification();
79   }
80 }
81
82 //=============================================================================
83 /*!
84  *  
85  */
86 //=============================================================================
87
88 double StdMeshers_StartEndLength::GetLength(bool isStartLength) const
89 {
90   return isStartLength ? _begLength : _endLength;
91 }
92
93 //=============================================================================
94 /*!
95  *  
96  */
97 //=============================================================================
98
99 ostream & StdMeshers_StartEndLength::SaveTo(ostream & save)
100 {
101   save << _begLength << " " <<_endLength;
102   return save;
103 }
104
105 //=============================================================================
106 /*!
107  *  
108  */
109 //=============================================================================
110
111 istream & StdMeshers_StartEndLength::LoadFrom(istream & load)
112 {
113   bool isOK = true;
114   isOK = (load >> _begLength);
115   if (!isOK)
116     load.clear(ios::badbit | load.rdstate());
117   isOK = (load >> _endLength);
118   if (!isOK)
119     load.clear(ios::badbit | load.rdstate());
120   return load;
121 }
122
123 //=============================================================================
124 /*!
125  *  
126  */
127 //=============================================================================
128
129 ostream & operator <<(ostream & save, StdMeshers_StartEndLength & hyp)
130 {
131   return hyp.SaveTo( save );
132 }
133
134 //=============================================================================
135 /*!
136  *  
137  */
138 //=============================================================================
139
140 istream & operator >>(istream & load, StdMeshers_StartEndLength & hyp)
141 {
142   return hyp.LoadFrom( load );
143 }