1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
15 #include <Interface_EntityIterator.hxx>
16 #include <Interface_GeneralLib.hxx>
17 #include <Interface_GeneralModule.hxx>
18 #include <Interface_Graph.hxx>
19 #include <Interface_GTool.hxx>
20 #include <Interface_InterfaceModel.hxx>
21 #include <Interface_IntList.hxx>
22 #include <Interface_Protocol.hxx>
23 #include <Interface_ReportEntity.hxx>
24 #include <Interface_ShareFlags.hxx>
25 #include <Standard_DomainError.hxx>
26 #include <Standard_OutOfRange.hxx>
27 #include <Standard_Transient.hxx>
29 Interface_ShareFlags::Interface_ShareFlags
30 (const Handle(Interface_InterfaceModel)& amodel,
31 const Interface_GeneralLib& lib)
32 : theflags (amodel->NbEntities())
34 Handle(Interface_GTool) gtool; // null
39 Interface_ShareFlags::Interface_ShareFlags
40 (const Handle(Interface_InterfaceModel)& amodel,
41 const Handle(Interface_GTool)& gtool)
42 : theflags (amodel->NbEntities())
45 Evaluate(gtool->Lib(),gtool);
48 Interface_ShareFlags::Interface_ShareFlags
49 (const Handle(Interface_InterfaceModel)& amodel,
50 const Handle(Interface_Protocol)& protocol)
51 : theflags (amodel->NbEntities())
53 Handle(Interface_GTool) gtool; // null
55 Evaluate(Interface_GeneralLib(protocol),gtool);
58 Interface_ShareFlags::Interface_ShareFlags
59 (const Handle(Interface_InterfaceModel)& amodel)
60 : theflags (amodel->NbEntities())
62 Handle(Interface_GTool) gtool = themodel->GTool();
63 gtool->Reservate(amodel->NbEntities());
65 Evaluate (gtool->Lib(),gtool);
68 Interface_ShareFlags::Interface_ShareFlags (const Interface_Graph& agraph)
69 : theflags (agraph.Model()->NbEntities())
71 themodel = agraph.Model();
72 Standard_Integer nb = themodel->NbEntities();
74 theroots = new TColStd_HSequenceOfTransient();
75 for (Standard_Integer i = 1; i <= nb; i ++) {
76 // Resultat obtenu depuis le Graph
77 Handle(Standard_Transient) ent = themodel->Value(i);
78 Handle(TColStd_HSequenceOfTransient) list = agraph.GetSharings(ent);
80 if (!list.IsNull() && list->Length() > 0) theflags.SetTrue(i);
81 else theroots->Append (ent);
86 void Interface_ShareFlags::Evaluate
87 (const Interface_GeneralLib& lib, const Handle(Interface_GTool)& gtool)
89 Standard_Boolean patool = gtool.IsNull();
90 Standard_Integer nb = themodel->NbEntities();
92 theroots = new TColStd_HSequenceOfTransient();
93 Standard_Integer i; // svv Jan11 2000 : porting on DEC
94 for (i = 1; i <= nb; i ++) {
96 // ATTENTION : Si Entite non chargee donc illisible, basculer sur son
97 // "Contenu" equivalent
98 Handle(Standard_Transient) ent = themodel->Value(i);
99 if (themodel->IsRedefinedContent(i)) ent = themodel->ReportEntity(i)->Content();
101 // Resultat obtenu via GeneralLib
102 Interface_EntityIterator iter;
103 Handle(Interface_GeneralModule) module;
106 if (lib.Select(ent,module,CN)) module->FillShared(themodel,CN,ent,iter);
108 if (gtool->Select(ent,module,CN)) module->FillShared(themodel,CN,ent,iter);
111 // Entites partagees par <ent> : reste a noter chacune comme "Shared"
112 for (iter.Start(); iter.More(); iter.Next()) {
113 Standard_Integer num = themodel->Number(iter.Value());
114 theflags.SetTrue(num); // Et Voila
117 for (i = 1; i <= nb; i ++) {
118 if (!theflags.Value(i)) theroots->Append (themodel->Value(i));
123 Handle(Interface_InterfaceModel) Interface_ShareFlags::Model () const
126 Standard_Boolean Interface_ShareFlags::IsShared
127 (const Handle(Standard_Transient)& ent) const
129 Standard_Integer num = themodel->Number(ent);
130 if (num == 0 || num > themodel->NbEntities()) throw Standard_DomainError("Interface ShareFlags : IsShared");
131 return theflags.Value(num);
134 Interface_EntityIterator Interface_ShareFlags::RootEntities () const
136 Interface_EntityIterator iter (theroots);
140 Standard_Integer Interface_ShareFlags::NbRoots () const
141 { return (theroots.IsNull() ? 0 : theroots->Length()); }
143 Handle(Standard_Transient) Interface_ShareFlags::Root
144 (const Standard_Integer num) const
145 { return theroots->Value(num); }