Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/hexablock.git] / src / HEXABLOCK / HexPropagation.hxx
1 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // class : Ensembles de propagation
21
22 #ifndef __PROPAGATION_H
23 #define __PROPAGATION_H
24
25 #include "HexDocument.hxx"
26 #include "HexEdge.hxx"
27 #include "HexXmlWriter.hxx"
28 #include "HexLaw.hxx"
29
30 BEGIN_NAMESPACE_HEXA
31
32 class Propagation 
33 {
34 public:
35    const Edges& getEdges ()        { return prop_edges; }
36    Law*  getLaw ();
37    bool  getWay ()                 { return prop_way; }
38
39    void  setWay (bool sens)        { prop_way = sens; }
40    int   setLaw (Law* loi);
41
42 public:
43     Propagation  ();
44     void saveXml (XmlWriter* xml);
45     void addEdge (Edge* arete);
46     void majLaw  ();
47
48 private:
49     Edges prop_edges;
50     Law*  prop_law;
51     bool  prop_way;
52 };
53 // =========================================================== Constructeur
54 inline Propagation::Propagation ()
55 {
56     prop_law = NULL;
57     prop_way = true;
58 }
59 // =========================================================== getLaw
60 inline Law* Propagation::getLaw ()
61 {
62     return prop_law; 
63 /* **********************************  Modif Abu du 18/10/2010
64     if (prop_law != NULL) 
65        return prop_law; 
66
67     if (prop_edges.size()==0) 
68        return NULL;
69
70     Document* root = prop_edges[0]->dad();
71     return root->getLaw (0);
72    ********************************** */
73 }
74 // =========================================================== setLaw
75 inline int Propagation::setLaw (Law* loi)
76 {
77    prop_law = loi; 
78    majLaw ();
79    return HOK;
80 }
81 // =========================================================== majLaw
82 inline void Propagation::majLaw ()
83 {
84    int nbre = prop_edges.size();
85    for (int nro=0 ; nro < nbre ; nro++)
86         prop_edges[0]->setLaw (prop_law);
87 }
88 // =========================================================== addEdge
89 inline void Propagation::addEdge (Edge* arete)
90 {
91    prop_edges.push_back (arete);
92
93    if (prop_law == NULL)
94        prop_law =  arete->getLaw();
95 }
96 // =========================================================== saveXml
97 inline void Propagation::saveXml (XmlWriter* xml)
98 {
99     char   buffer[12];
100     cpchar booleen [] = { "true", "false" };
101     cpchar law = prop_law == NULL ? "default" : prop_law->getName();
102
103     xml->openMark     ("Propagation");
104     xml->addAttribute ("edge", prop_edges[0]->getName (buffer));
105     xml->addAttribute ("law",  law);
106     xml->addAttribute ("way",  booleen [prop_way]);
107     xml->closeMark ();
108 }
109 END_NAMESPACE_HEXA
110
111 #endif