]> SALOME platform Git repositories - modules/yacs.git/blob - src/engine/LinkedBlocPoint.cxx
Salome HOME
6e3ac0aa39dea35639c35d1237f825bded3fd7e4
[modules/yacs.git] / src / engine / LinkedBlocPoint.cxx
1 // Copyright (C) 2015-2022  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, 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 #include "LinkedBlocPoint.hxx"
21 #include "ElementaryPoint.hxx"
22 #include "NotSimpleCasePoint.hxx"
23 #include "ForkBlocPoint.hxx"
24 #include "PointVisitor.hxx"
25 #include "Exception.hxx"
26
27 #ifdef WIN32
28 #include <algorithm>
29 #endif
30
31
32 using namespace YACS::ENGINE;
33
34 LinkedBlocPoint::LinkedBlocPoint(const std::list<AbstractPoint *>& nodes, AbstractPoint *father):BlocPoint(nodes,father)
35 {
36 }
37
38 AbstractPoint *LinkedBlocPoint::deepCopy(AbstractPoint *father) const
39 {
40   LinkedBlocPoint *ret(new LinkedBlocPoint);
41   ret->deepCopyFrom(*this);
42   ret->setFather(father);
43   return ret;
44 }
45
46 Node *LinkedBlocPoint::getFirstNode()
47 {
48   if(_nodes.empty())
49     throw Exception("LinkedBlocPoint::getFirstNode : error no branches !");
50   return _nodes.front()->getFirstNode();
51 }
52
53 Node *LinkedBlocPoint::getLastNode()
54 {
55   if(_nodes.empty())
56     throw Exception("LinkedBlocPoint::getFirstNode : error no branches !");
57   return _nodes.back()->getLastNode();
58 }
59
60 int LinkedBlocPoint::getMaxLevelOfParallelism() const
61 {
62   int ret(0);
63   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
64     ret=std::max(ret,(*it)->getMaxLevelOfParallelism());
65   return ret;
66 }
67
68 void LinkedBlocPoint::getWeightRegardingDPL(ComplexWeight *weight)
69 {
70   ComplexWeight localWeight;
71   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
72   {
73     (*it)->getWeightRegardingDPL(&localWeight);
74     weight->addWeight(&localWeight);
75     localWeight.setToZero();
76   }
77 }
78
79 void LinkedBlocPoint::partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap) const
80 {
81   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++)
82     (*it)->partitionRegardingDPL(pd,zeMap);
83 }
84
85 std::string LinkedBlocPoint::getRepr() const
86 {
87   std::size_t sz(_nodes.size()),ii(0);
88   std::string ret("(");
89   for(std::list<AbstractPoint *>::const_iterator it=_nodes.begin();it!=_nodes.end();it++,ii++)
90     {
91       ret+=(*it)->getRepr();
92       if(ii!=sz-1)
93         ret+="+";
94     }
95   ret+=")";
96   return ret;
97 }
98
99 AbstractPoint *LinkedBlocPoint::expandNonSimpleCaseOn(NotSimpleCasePoint *pathologicalPt, const std::set<Node *>& uncatchedNodes)
100 {
101   if(anyOf(uncatchedNodes))
102     {
103       for(auto& it : _nodes)
104         {
105           AbstractPoint *ret(it->expandNonSimpleCaseOn(pathologicalPt,uncatchedNodes));
106           if(ret!=it)
107             {
108               ret->setFather(this);
109               auto oldIt(it);
110               it = ret;
111               delete oldIt;
112             }
113         }
114       return this;
115     }
116   else
117     {
118       std::list<AbstractPoint *> l;
119       AbstractPoint *p0(this->deepCopy(getFather())),*p1(pathologicalPt->getUnique()->deepCopy(getFather()));
120       l.push_back(p0);
121       l.push_back(p1);
122       AbstractPoint *ret(new ForkBlocPoint(l,getFather()));
123       p0->setFather(ret); p1->setFather(ret);
124       return ret;
125     }
126 }
127
128 void LinkedBlocPoint::accept(PointVisitor *pv)
129 {
130   pv->beginLinkedBlocPoint(this);
131   for(auto it:_nodes)
132     it->accept(pv);
133   pv->endLinkedBlocPoint(this);
134 }
135
136 LinkedBlocPoint::~LinkedBlocPoint()
137 {
138 }