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_GeneralModule.hxx>
17 #include <Interface_Graph.hxx>
18 #include <Interface_GTool.hxx>
19 #include <Interface_InterfaceModel.hxx>
20 #include <Interface_Protocol.hxx>
21 #include <Interface_ReportEntity.hxx>
22 #include <Interface_ShareFlags.hxx>
23 #include <Standard_DomainError.hxx>
24 #include <Standard_Transient.hxx>
26 Interface_ShareFlags::Interface_ShareFlags
27 (const Handle(Interface_InterfaceModel)& amodel,
28 const Interface_GeneralLib& lib)
29 : theflags (amodel->NbEntities())
31 Handle(Interface_GTool) gtool; // null
36 Interface_ShareFlags::Interface_ShareFlags
37 (const Handle(Interface_InterfaceModel)& amodel,
38 const Handle(Interface_GTool)& gtool)
39 : theflags (amodel->NbEntities())
42 Evaluate(gtool->Lib(),gtool);
45 Interface_ShareFlags::Interface_ShareFlags
46 (const Handle(Interface_InterfaceModel)& amodel,
47 const Handle(Interface_Protocol)& protocol)
48 : theflags (amodel->NbEntities())
50 Handle(Interface_GTool) gtool; // null
52 Evaluate(Interface_GeneralLib(protocol),gtool);
55 Interface_ShareFlags::Interface_ShareFlags
56 (const Handle(Interface_InterfaceModel)& amodel)
57 : theflags (amodel->NbEntities())
59 Handle(Interface_GTool) gtool = themodel->GTool();
60 gtool->Reservate(amodel->NbEntities());
62 Evaluate (gtool->Lib(),gtool);
65 Interface_ShareFlags::Interface_ShareFlags (const Interface_Graph& agraph)
66 : theflags (agraph.Model()->NbEntities())
68 themodel = agraph.Model();
69 Standard_Integer nb = themodel->NbEntities();
71 theroots = new TColStd_HSequenceOfTransient();
72 for (Standard_Integer i = 1; i <= nb; i ++) {
73 // Resultat obtenu depuis le Graph
74 Handle(Standard_Transient) ent = themodel->Value(i);
75 Handle(TColStd_HSequenceOfTransient) list = agraph.GetSharings(ent);
77 if (!list.IsNull() && list->Length() > 0) theflags.SetTrue(i);
78 else theroots->Append (ent);
83 void Interface_ShareFlags::Evaluate
84 (const Interface_GeneralLib& lib, const Handle(Interface_GTool)& gtool)
86 Standard_Boolean patool = gtool.IsNull();
87 Standard_Integer nb = themodel->NbEntities();
89 theroots = new TColStd_HSequenceOfTransient();
90 Standard_Integer i; // svv Jan11 2000 : porting on DEC
91 for (i = 1; i <= nb; i ++) {
93 // ATTENTION : Si Entite non chargee donc illisible, basculer sur son
94 // "Contenu" equivalent
95 Handle(Standard_Transient) ent = themodel->Value(i);
96 if (themodel->IsRedefinedContent(i)) ent = themodel->ReportEntity(i)->Content();
98 // Resultat obtenu via GeneralLib
99 Interface_EntityIterator iter;
100 Handle(Interface_GeneralModule) module;
103 if (lib.Select(ent,module,CN)) module->FillShared(themodel,CN,ent,iter);
105 if (gtool->Select(ent,module,CN)) module->FillShared(themodel,CN,ent,iter);
108 // Entites partagees par <ent> : reste a noter chacune comme "Shared"
109 for (iter.Start(); iter.More(); iter.Next()) {
110 Standard_Integer num = themodel->Number(iter.Value());
111 theflags.SetTrue(num); // Et Voila
114 for (i = 1; i <= nb; i ++) {
115 if (!theflags.Value(i)) theroots->Append (themodel->Value(i));
120 Handle(Interface_InterfaceModel) Interface_ShareFlags::Model () const
123 Standard_Boolean Interface_ShareFlags::IsShared
124 (const Handle(Standard_Transient)& ent) const
126 Standard_Integer num = themodel->Number(ent);
127 if (num == 0 || num > themodel->NbEntities()) throw Standard_DomainError("Interface ShareFlags : IsShared");
128 return theflags.Value(num);
131 Interface_EntityIterator Interface_ShareFlags::RootEntities () const
133 Interface_EntityIterator iter (theroots);
137 Standard_Integer Interface_ShareFlags::NbRoots () const
138 { return (theroots.IsNull() ? 0 : theroots->Length()); }
140 Handle(Standard_Transient) Interface_ShareFlags::Root
141 (const Standard_Integer num) const
142 { return theroots->Value(num); }