Warnings on vc14 were eliminated
[occt.git] / src / Transfer / Transfer_TransferOutput.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 //szv#4 S4163
15
16 #include <Interface_EntityIterator.hxx>
17 #include <Interface_Graph.hxx>
18 #include <Interface_InterfaceModel.hxx>
19 #include <Interface_Protocol.hxx>
20 #include <Interface_ShareFlags.hxx>
21 #include <Standard_NoSuchObject.hxx>
22 #include <Standard_Transient.hxx>
23 #include <Transfer_ActorOfTransientProcess.hxx>
24 #include <Transfer_Binder.hxx>
25 #include <Transfer_TransferFailure.hxx>
26 #include <Transfer_TransferOutput.hxx>
27 #include <Transfer_TransientProcess.hxx>
28
29 Transfer_TransferOutput::Transfer_TransferOutput (const Handle(Transfer_ActorOfTransientProcess)& actor,
30                                                   const Handle(Interface_InterfaceModel)& amodel)
31 {
32   theproc  = new Transfer_TransientProcess (amodel->NbEntities());
33   theproc->SetActor(actor);
34   themodel = amodel;
35 //  thescope = Standard_False;
36 //  theundef = Transfer_UndefIgnore;
37 }
38
39 Transfer_TransferOutput::Transfer_TransferOutput (const Handle(Transfer_TransientProcess)& proc,
40                                                   const Handle(Interface_InterfaceModel)& amodel)
41 {
42   theproc  = proc;
43   themodel = amodel;
44 //  thescope = Standard_False; //szv#4:S4163:12Mar99 initialization needed
45 //  theundef = Transfer_UndefIgnore;
46 }
47
48 //Standard_Boolean&  Transfer_TransferOutput::ScopeMode ()
49 //{  return  thescope;  }
50
51 Handle(Interface_InterfaceModel)  Transfer_TransferOutput::Model () const
52 {  return themodel;  }
53
54 Handle(Transfer_TransientProcess)  Transfer_TransferOutput::TransientProcess () const
55 {  return theproc;  }
56
57 void  Transfer_TransferOutput::Transfer (const Handle(Standard_Transient)& obj)
58 {
59   if (themodel->Number(obj) == 0) throw Transfer_TransferFailure("TransferOutput : Transfer, entities do not come from same initial model");
60 //  Standard_Integer scope = 0;
61 //  if (thescope) scope = theproc->NewScope (obj);
62
63   //:1 modified by ABV 5 Nov 97
64   //:1  if (!theproc->Transfer(obj)) return;    // auparavant, traitement Undefined
65 //  Standard_Boolean ok = 
66   theproc->Transfer ( obj );  
67 //  if (scope > 0) theproc->EndScope (scope);
68 //  if ( ! ok ) return;                               
69
70 /*  switch (theundef) {
71     case Transfer_UndefIgnore  : return;
72     case Transfer_UndefFailure : throw Transfer_TransferFailure("TransferOutput : Transfer Undefined as Failure");
73     case Transfer_UndefContent : break; // on ne sait pas traiter ...
74     case Transfer_UndefUser    : break; // idem
75   }
76 */
77 }
78
79
80 //  Resultats :
81 //   Pour transferer tout simplement toutes les racines d'un modele d'interface
82 //   Chacune est notee "Root" dans le Process final
83
84 void Transfer_TransferOutput::TransferRoots ()
85 {  TransferRoots(Interface_Protocol::Active());  }
86
87 void Transfer_TransferOutput::TransferRoots (const Handle(Interface_Protocol)& protocol)
88 {
89   theproc->SetRootManagement (Standard_False);
90   Interface_ShareFlags tool(themodel,protocol);
91   Interface_EntityIterator list = tool.RootEntities();
92   for (list.Start(); list.More(); list.Next()) {
93     Handle(Standard_Transient) ent = list.Value();
94 //    Standard_Integer scope = 0;
95 //    if (thescope) scope = theproc->NewScope (ent);
96     if (theproc->Transfer(ent)) theproc->SetRoot(ent);
97 //    if (scope > 0) theproc->EndScope (scope);
98   }
99 }
100
101 void Transfer_TransferOutput::TransferRoots (const Interface_Graph& G)
102 {
103   theproc->SetRootManagement (Standard_False);
104   Interface_ShareFlags tool(G);
105   theproc->SetModel (G.Model());
106   Interface_EntityIterator list = tool.RootEntities();
107   for (list.Start(); list.More(); list.Next()) {
108     Handle(Standard_Transient) ent = list.Value();
109 //    Standard_Integer scope = 0;
110 //    if (thescope) scope = theproc->NewScope (ent);
111     if (theproc->Transfer(ent)) theproc->SetRoot(ent);
112 //    if (scope > 0) theproc->EndScope (scope);
113   }
114 }
115
116
117 Interface_EntityIterator  Transfer_TransferOutput::ListForStatus (const Standard_Boolean normal,
118                                                                   const Standard_Boolean roots) const
119 {
120   Interface_EntityIterator list;
121   Standard_Integer max = (roots ? theproc->NbRoots() : theproc->NbMapped());
122   for (Standard_Integer i = 1; i <= max; i ++) {
123     const Handle(Transfer_Binder)& binder =
124       (roots ? theproc->RootItem(i) : theproc->MapItem(i));
125     if (binder.IsNull()) continue;
126     Transfer_StatusExec statex = binder->StatusExec();
127     Standard_Boolean ok =
128       (statex == Transfer_StatusInitial || statex == Transfer_StatusDone);
129     if (ok == normal) list.AddItem
130       ( (roots ? theproc->Root(i) : theproc->Mapped(i)) );
131   }
132   return list;
133 }
134
135 Handle(Interface_InterfaceModel)  Transfer_TransferOutput::ModelForStatus
136   (const Handle(Interface_Protocol)& protocol,
137    const Standard_Boolean normal, const Standard_Boolean roots) const
138 {
139   Handle(Interface_InterfaceModel) newmod;
140   if (themodel.IsNull()) return newmod;
141   newmod = themodel->NewEmptyModel();
142   Interface_EntityIterator list = ListForStatus (normal, roots);
143   for (list.Start(); list.More(); list.Next())
144     newmod->AddWithRefs (list.Value(),protocol);
145   return newmod;
146 }