1 // Copyright (C) 2015-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "AbstractPoint.hxx"
21 #include "LinkedBlocPoint.hxx"
22 #include "ForkBlocPoint.hxx"
23 #include "SetOfPoints.hxx"
26 using namespace YACS::ENGINE;
28 AbstractPoint::~AbstractPoint()
32 AbstractPoint *AbstractPoint::getGodFather()
37 return _father->getGodFather();
40 bool AbstractPoint::isBegin()
42 Node *beg(getFirstNode());
43 InGate *ing(beg->getInGate());
44 return ing->getBackLinks().empty();
47 bool AbstractPoint::isLast()
49 Node *endd(getLastNode());
50 OutGate *oug(endd->getOutGate());
51 return oug->edSetInGate().empty();
54 bool AbstractPoint::isSimplyLinkedBeforeAfter(BlocPoint *sop)
56 Node *beg(getFirstNode()),*endd(getLastNode());
57 return isSimplyLinkedBefore(sop,beg) && isSimplyLinkedAfter(sop,endd);
60 bool AbstractPoint::isSimplyLinkedAfterNullBefore(BlocPoint *sop)
62 Node *beg(getFirstNode()),*endd(getLastNode());
63 return IsNoLinksBefore(beg) && isSimplyLinkedAfter(sop,endd);
66 bool AbstractPoint::isSimplyLinkedBeforeNullAfter(BlocPoint *sop)
68 Node *beg(getFirstNode()),*endd(getLastNode());
69 return IsNoLinksAfter(endd) && isSimplyLinkedBefore(sop,beg);
73 * precondition : isSimplyLinkedBeforeAfter must return true on \a this.
75 LinkedBlocPoint *AbstractPoint::tryAsLink(BlocPoint *sop)
77 Node *bb(getFirstNode()),*ee(getLastNode());
78 std::list<AbstractPoint *> l; l.push_back(this);
79 AbstractPoint *cur2(0);
81 cur2=sop->getNodeB4(bb);
84 Node *cur3(cur2->getFirstNode());
85 if(cur2->isSimplyLinkedBeforeAfter(sop))
88 cur2=sop->getNodeB4(cur3);
91 else if(IsGatherB4Ext(cur3) && isSimplyLinkedAfter(sop,cur2->getLastNode()))
100 cur2=sop->getNodeAfter(ee);
103 Node *cur3(cur2->getLastNode());
104 if(cur2->isSimplyLinkedBeforeAfter(sop))
107 cur2=sop->getNodeAfter(cur3);
110 else if(IsScatterAfterExt(cur3) && isSimplyLinkedBefore(sop,cur2->getFirstNode()))
120 return new LinkedBlocPoint(l,getFather());
127 * precondition : isSimplyLinkedBeforeAfter must return true on \a this.
129 ForkBlocPoint *AbstractPoint::tryAsFork(BlocPoint *sop)
131 Node *bb(GetNodeB4(getFirstNode())),*ee(GetNodeAfter(getLastNode()));
132 AbstractPoint *bb2(sop->findPointWithNode(bb)),*ee2(sop->findPointWithNode(ee));
134 const std::list<AbstractPoint *>& lp(sop->getListOfPoints());
135 std::list<AbstractPoint *> l; l.push_back(this);
136 for(std::list<AbstractPoint *>::const_iterator it=lp.begin();it!=lp.end();it++)
140 Node *curFirst((*it)->getFirstNode()),*curEnd((*it)->getLastNode());
141 if(!IsSimplyLinkedBeforeExt(curFirst) || !IsSimplyLinkedAfterExt(curEnd))
143 Node *curbb(GetNodeB4(curFirst)),*curee(GetNodeAfter(curEnd));
144 AbstractPoint *bb3(sop->findPointWithNode(curbb)),*ee3(sop->findPointWithNode(curee));
145 if(bb2==bb3 && ee2==ee3)
150 return new ForkBlocPoint(l,getFather());
156 ForkBlocPoint *AbstractPoint::tryAsForkBis(BlocPoint *sop)
158 Node *bb(GetNodeB4(getFirstNode())),*ee(GetNodeAfter(getLastNode()));
159 AbstractPoint *ee2(sop->findPointWithNode(ee));
161 const std::list<AbstractPoint *>& lp(sop->getListOfPoints());
162 std::list<AbstractPoint *> l; l.push_back(this);
163 for(std::list<AbstractPoint *>::const_iterator it=lp.begin();it!=lp.end();it++)
167 Node *curFirst((*it)->getFirstNode()),*curEnd((*it)->getLastNode());
168 if(!IsNoLinksBefore(curFirst) || !IsSimplyLinkedAfterExt(curEnd))
170 Node *curee(GetNodeAfter(curEnd));
171 AbstractPoint *ee3(sop->findPointWithNode(curee));
177 return new ForkBlocPoint(l,getFather());
183 ForkBlocPoint *AbstractPoint::tryAsForkTer(BlocPoint *sop)
185 Node *bb(GetNodeB4(getFirstNode())),*ee(GetNodeAfter(getLastNode()));
186 AbstractPoint *bb2(sop->findPointWithNode(bb));
188 const std::list<AbstractPoint *>& lp(sop->getListOfPoints());
189 std::list<AbstractPoint *> l; l.push_back(this);
190 for(std::list<AbstractPoint *>::const_iterator it=lp.begin();it!=lp.end();it++)
194 Node *curFirst((*it)->getFirstNode()),*curEnd((*it)->getLastNode());
195 if(!IsSimplyLinkedBeforeExt(curFirst) || !IsNoLinksAfter(curEnd))
197 Node *curbb(GetNodeB4(curFirst));
198 AbstractPoint *bb3(sop->findPointWithNode(curbb));
204 return new ForkBlocPoint(l,getFather());
210 bool AbstractPoint::IsGatherB4Ext(Node *node)
212 InGate *ing(node->getInGate());
213 return ing->getBackLinks().size()!=1;
216 bool AbstractPoint::isSimplyLinkedAfter(BlocPoint *sop, Node *node)
218 OutGate *oug(node->getOutGate());
219 std::list<InGate *> ings(oug->edSetInGate());
224 AbstractPoint *dummy=0;
225 return IsCommonDirectSonOf(sop,ings,dummy);
228 bool AbstractPoint::IsSimplyLinkedAfterExt(Node *node)
230 OutGate *oug(node->getOutGate());
231 return oug->edSetInGate().size()<=1;
234 bool AbstractPoint::IsScatterAfterExt(Node *node)
236 OutGate *oug(node->getOutGate());
237 return oug->edSetInGate().size()!=1;
240 bool AbstractPoint::isSimplyLinkedBefore(BlocPoint *sop, Node *node)
242 InGate *ing(node->getInGate());
243 std::list<OutGate *> outgs(ing->getBackLinks());
248 AbstractPoint *dummy=0;
249 return IsCommonDirectSonOf(sop,outgs,dummy);
252 bool AbstractPoint::IsSimplyLinkedBeforeExt(Node *node)
254 InGate *ing(node->getInGate());
255 return ing->getBackLinks().size()<=1;
258 bool AbstractPoint::IsNoLinksBefore(Node *node)
260 InGate *ing(node->getInGate());
261 return ing->getBackLinks().size()==0;
264 bool AbstractPoint::IsNoLinksAfter(Node *node)
266 OutGate *oug(node->getOutGate());
267 return oug->edSetInGate().size()==0;
270 Node *AbstractPoint::GetNodeB4(Node *node)
272 InGate *ing(node->getInGate());
273 std::list<OutGate *> bl(ing->getBackLinks());
275 throw Exception("AbstractPoint::GetNodeB4 : precond not OK !");
278 return bl.front()->getNode();
281 Node *AbstractPoint::GetNodeAfter(Node *node)
283 OutGate *oug(node->getOutGate());
284 std::list<InGate *> fl(oug->edSetInGate());
286 throw Exception("AbstractPoint::GetNodeAfter : precond not OK !");
289 return (*fl.begin())->getNode();
292 AbstractPoint *AbstractPoint::GetDirectSonOf(AbstractPoint *refFather, AbstractPoint *sonOrLittleSon)
294 AbstractPoint *curFath(sonOrLittleSon->getFather()),*cur(sonOrLittleSon);
295 while(curFath && curFath!=refFather)
298 curFath=cur->getFather();
301 throw YACS::Exception("AbstractPoint::GetDirectSonOf : not in the same family !");
305 bool AbstractPoint::IsCommonDirectSonOf(AbstractPoint *refFather, const std::list<OutGate *>& outgs, AbstractPoint *&ret)
308 throw YACS::Exception("AbstractPoint::GetCommonDirectSonOf1 : not enough !");
309 std::list<OutGate *>::const_iterator it(outgs.begin());
310 OutGate *ref(*(it++));
311 AbstractPoint *ref2(GetDirectSonOf(refFather,refFather->findPointWithNode(ref->getNode())));
312 for(;it!=outgs.end();it++)
314 if(!ref2->contains((*it)->getNode()))
321 bool AbstractPoint::IsCommonDirectSonOf(AbstractPoint *refFather, const std::list<InGate *>& ings, AbstractPoint *&ret)
324 throw YACS::Exception("AbstractPoint::GetCommonDirectSonOf2 : not enough !");
325 std::list<InGate *>::const_iterator it(ings.begin());
326 InGate *ref(*(it++));
327 AbstractPoint *ref2(GetDirectSonOf(refFather,refFather->findPointWithNode(ref->getNode())));
328 for(;it!=ings.end();it++)
330 if(!ref2->contains((*it)->getNode()))