Salome HOME
Copyright update 2020
[modules/yacs.git] / src / engine / OutPort.cxx
1 // Copyright (C) 2006-2020  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 "OutPort.hxx"
21 #include "InPort.hxx"
22 #include "ComposedNode.hxx"
23 #include <algorithm>
24 #include <iostream>
25
26 using namespace YACS::ENGINE;
27 using namespace std;
28
29 OutPort::OutPort(const OutPort& other, Node *newHelder):DataPort(other,newHelder),Port(other,newHelder)
30 {
31 }
32
33 OutPort::OutPort(const std::string& name, Node *node, TypeCode* type):DataPort(name,node,type),Port(node)
34 {
35 }
36
37 OutPort::~OutPort()
38 {
39 }
40
41 void OutPort::checkConsistency(LinkInfo& info) const
42 {
43 }
44
45 void OutPort::getAllRepresented(std::set<OutPort *>& represented) const
46 {
47   represented.insert((OutPort *)this);
48 }
49
50 int OutPort::edGetNumberOfOutLinks() const
51 {
52   return edSetInPort().size();
53 }
54
55 std::vector<DataPort *> OutPort::calculateHistoryOfLinkWith(InPort *end)
56 {
57   if(!isAlreadyLinkedWith(end))
58     throw Exception("ComposedNode::edRemoveLink : unexisting link");
59   vector<DataPort *> ret;
60   ComposedNode* lwstCmnAnctr=ComposedNode::getLowestCommonAncestor(getNode(),end->getNode());
61   list<ComposedNode *> allAscendanceOfNodeStart=getNode()->getAllAscendanceOf(lwstCmnAnctr);
62   list<ComposedNode *> allAscendanceOfNodeEnd=end->getNode()->getAllAscendanceOf(lwstCmnAnctr);
63
64   // --- Part of test if the link from 'start' to 'end' really exist particulary all eventually intermediate ports created
65
66   ComposedNode *iterS=getNode()->getFather();
67   pair<OutPort *,OutPort *> currentPortO(this,this);
68   ret.push_back(currentPortO.first);
69   while(iterS!=lwstCmnAnctr)
70     {
71       iterS->getDelegateOf(currentPortO, end, allAscendanceOfNodeEnd);
72       if(currentPortO.first!=ret.back())
73         ret.push_back(currentPortO.first);
74       iterS=iterS->_father;
75     }
76   iterS=end->getNode()->getFather();
77   InPort *currentPortI=end;
78   int i=0;
79   while(iterS!=lwstCmnAnctr)
80     {
81       vector<DataPort *>::iterator iter2;
82       iterS->getDelegateOf(currentPortI, this, allAscendanceOfNodeStart);
83       if(currentPortI!=ret.back())
84         {
85           i++;
86           ret.push_back(currentPortI);
87         }
88       iterS=iterS->_father;
89     }
90   vector<DataPort *>::iterator iter=ret.end(); iter-=i;
91   reverse(iter,ret.end());
92   return ret;
93 }