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