Salome HOME
b0378617140b50f40ee4e185278086f7be172936
[modules/hexablock.git] / src / HEXABLOCK / HexPropagation.hxx
1 // Copyright (C) 2009-2023  CEA, EDF
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, or (at your option) any later version.
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 "HexEltBase.hxx"
26
27 #include "HexDocument.hxx"
28 #include "HexEdge.hxx"
29 #include "HexXmlWriter.hxx"
30 #include "HexLaw.hxx"
31 #include "HexGlobale.hxx"
32
33 BEGIN_NAMESPACE_HEXA
34
35 class HexaExport Propagation : public EltBase 
36 {
37 public:
38    const Edges& getEdges ()        { return prop_edges; }
39    Law*  getLaw ();
40    bool  getWay ()                 { return prop_way; }
41
42    void  setWay (bool sens)        { prop_way = sens; }
43    int   setLaw (Law* loi);
44
45 public:
46     Propagation  (Document*  doc);
47     void saveXml (XmlWriter* xml);
48     void addEdge (Edge* arete);
49     void majLaw  ();
50
51 private:
52     Edges prop_edges;
53     Law*  prop_law;
54     bool  prop_way;
55 };
56 // =========================================================== Constructeur
57 inline Propagation::Propagation (Document* doc)
58                   : EltBase (doc, EL_PROPAGATION)
59 {
60     prop_law = NULL;
61     prop_way = true;
62 }
63 // =========================================================== getLaw
64 inline Law* Propagation::getLaw ()
65 {
66     return prop_law; 
67 /* **********************************  Modif Abu du 18/10/2010
68     if (prop_law != NULL) 
69        return prop_law; 
70
71     if (prop_edges.size()==0) 
72        return NULL;
73
74     Document* root = prop_edges[0]->dad();
75     return root->getLaw (0);
76    ********************************** */
77 }
78 // =========================================================== setLaw
79 inline int Propagation::setLaw (Law* loi)
80 {
81    prop_law = loi; 
82    majLaw ();
83
84    DumpStart  ("setLaw", loi);
85    DumpEnd;
86    return HOK;
87 }
88 // =========================================================== majLaw
89 inline void Propagation::majLaw ()
90 {
91    int nbre = prop_edges.size();
92    for (int nro=0 ; nro < nbre ; nro++)
93         prop_edges[0]->setLaw (prop_law);
94 }
95 // =========================================================== addEdge
96 inline void Propagation::addEdge (Edge* arete)
97 {
98    prop_edges.push_back (arete);
99
100    if (prop_law == NULL)
101        prop_law =  arete->getLaw();
102 }
103 // =========================================================== saveXml
104 inline void Propagation::saveXml (XmlWriter* xml)
105 {
106     char   buffer[12];
107     cpchar booleen [] = { "true", "false" };
108     cpchar law = prop_law == NULL ? "default" : prop_law->getName();
109
110     xml->openMark     ("Propagation");
111     xml->addAttribute ("edge", prop_edges[0]->getName (buffer));
112     xml->addAttribute ("law",  law);
113     xml->addAttribute ("way",  booleen [prop_way]);
114     xml->closeMark ();
115 }
116 END_NAMESPACE_HEXA
117
118 #endif