973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | #include <IFSelect_TransformStandard.ixx> |
15 | #include <IFSelect_Selection.hxx> |
16 | #include <IFSelect_ContextModif.hxx> |
17 | #include <Interface_CheckIterator.hxx> |
18 | #include <TColStd_HArray1OfInteger.hxx> |
19 | #include <Interface_EntityIterator.hxx> |
20 | |
21 | #include <Message_Messenger.hxx> |
22 | #include <Message.hxx> |
23 | #include <Interface_Macros.hxx> |
24 | #include <stdio.h> |
25 | |
26 | |
b311480e |
27 | IFSelect_TransformStandard::IFSelect_TransformStandard () |
7fd59977 |
28 | { thecopy = Standard_True; } |
29 | |
30 | void IFSelect_TransformStandard::SetCopyOption |
31 | (const Standard_Boolean option) |
32 | { thecopy = option; } |
33 | |
34 | Standard_Boolean IFSelect_TransformStandard::CopyOption () const |
35 | { return thecopy; } |
36 | |
37 | void IFSelect_TransformStandard::SetSelection |
38 | (const Handle(IFSelect_Selection)& sel) |
39 | { thesel = sel; } |
40 | |
41 | Handle(IFSelect_Selection) IFSelect_TransformStandard::Selection () const |
42 | { return thesel; } |
43 | |
44 | Standard_Integer IFSelect_TransformStandard::NbModifiers () const |
45 | { return themodifs.Length(); } |
46 | |
47 | Handle(IFSelect_Modifier) IFSelect_TransformStandard::Modifier |
48 | (const Standard_Integer num) const |
49 | { return GetCasted(IFSelect_Modifier,themodifs.Value(num)); } |
50 | |
51 | Standard_Integer IFSelect_TransformStandard::ModifierRank |
52 | (const Handle(IFSelect_Modifier)& modif) const |
53 | { |
54 | for (Standard_Integer i = themodifs.Length(); i >= 1; i --) |
55 | if (modif == themodifs.Value(i)) return i; |
56 | return 0; |
57 | } |
58 | |
59 | Standard_Boolean IFSelect_TransformStandard::AddModifier |
60 | (const Handle(IFSelect_Modifier)& modif, |
61 | const Standard_Integer atnum) |
62 | { |
63 | if (atnum < 0 || atnum > themodifs.Length()) return Standard_False; |
64 | if (atnum == 0) themodifs.Append(modif); |
65 | else themodifs.InsertBefore(atnum,modif); |
66 | return Standard_True; |
67 | } |
68 | |
69 | Standard_Boolean IFSelect_TransformStandard::RemoveModifier |
70 | (const Handle(IFSelect_Modifier)& modif) |
71 | { |
72 | Standard_Integer num = ModifierRank(modif); |
73 | return RemoveModifier(num); |
74 | } |
75 | |
76 | |
77 | Standard_Boolean IFSelect_TransformStandard::RemoveModifier |
78 | (const Standard_Integer num) |
79 | { |
80 | if (num <= 0 || num > themodifs.Length()) return Standard_False; |
81 | themodifs.Remove(num); |
82 | return Standard_True; |
83 | } |
84 | |
85 | // ################################################################# |
86 | // ######## ACTION ######## |
87 | |
88 | Standard_Boolean IFSelect_TransformStandard::Perform |
89 | (const Interface_Graph& G, const Handle(Interface_Protocol)& protocol, |
90 | Interface_CheckIterator& checks, |
91 | Handle(Interface_InterfaceModel)& newmod) |
92 | { |
93 | Interface_CopyTool TC(G.Model(),protocol); |
94 | themap = TC.Control(); |
95 | Copy (G,TC,newmod); |
96 | return ApplyModifiers (G,protocol,TC,checks,newmod); |
97 | } |
98 | |
99 | void IFSelect_TransformStandard::Copy |
100 | (const Interface_Graph& G, Interface_CopyTool& TC, |
101 | Handle(Interface_InterfaceModel)& newmod) const |
102 | { |
103 | if (CopyOption()) StandardCopy (G,TC,newmod); |
104 | else OnTheSpot (G,TC,newmod); |
105 | } |
106 | |
107 | void IFSelect_TransformStandard::StandardCopy |
108 | (const Interface_Graph& G, Interface_CopyTool& TC, |
109 | Handle(Interface_InterfaceModel)& newmod) const |
110 | { |
111 | Handle(Interface_InterfaceModel) original = G.Model(); |
112 | newmod = original->NewEmptyModel(); |
113 | TC.Clear(); |
114 | Standard_Integer nb = G.Size(); |
115 | Handle(TColStd_HArray1OfInteger) remain = |
116 | new TColStd_HArray1OfInteger(0,nb+1); remain->Init(0); |
117 | for (Standard_Integer i = 1; i <= nb; i ++) { |
118 | // if (G.Status(i) == 0) TC.TransferEntity (original->Value(i)); |
119 | TC.TransferEntity (original->Value(i)); |
120 | } |
121 | TC.FillModel(newmod); |
122 | } |
123 | |
124 | void IFSelect_TransformStandard::OnTheSpot |
125 | (const Interface_Graph& G, Interface_CopyTool& TC, |
126 | Handle(Interface_InterfaceModel)& newmod) const |
127 | { |
128 | Standard_Integer nb = G.Size(); |
129 | for (Standard_Integer i = 1; i <= nb; i ++) TC.Bind(G.Entity(i),G.Entity(i)); |
130 | newmod = G.Model(); |
131 | } |
132 | |
133 | |
134 | Standard_Boolean IFSelect_TransformStandard::ApplyModifiers |
135 | (const Interface_Graph& G, const Handle(Interface_Protocol)& protocol, |
136 | Interface_CopyTool& TC, Interface_CheckIterator& checks, |
137 | Handle(Interface_InterfaceModel)& newmod) const |
138 | { |
139 | Handle(Message_Messenger) sout = Message::DefaultMessenger(); |
140 | Standard_Boolean res = Standard_True; |
141 | Standard_Boolean chg = Standard_False; |
142 | Standard_Integer nb = NbModifiers(); |
143 | Handle(Interface_InterfaceModel) original = G.Model(); |
144 | |
145 | for (Standard_Integer i = 1; i <= nb; i ++) { |
146 | Handle(IFSelect_Modifier) unmod = Modifier(i); |
147 | if (unmod->MayChangeGraph()) chg = Standard_True; |
148 | |
149 | // Appliquer ce Modifier (nb : le Dispatch, on s en moque) |
150 | // D abord, la Selection |
151 | IFSelect_ContextModif ctx (G,TC); |
152 | // Ensuite, la Selection |
153 | // S il y en a une ici, elle a priorite. Sinon, chaque Modifier a la sienne |
154 | |
155 | Handle(IFSelect_Selection) sel = thesel; |
156 | if ( sel.IsNull()) sel = unmod->Selection(); |
157 | if (!sel.IsNull()) { |
158 | Interface_EntityIterator entiter = sel->UniqueResult(G); |
159 | ctx.Select (entiter); |
160 | } |
161 | if (ctx.IsForNone()) continue; |
162 | unmod->Perform (ctx,newmod,protocol,TC); |
163 | |
164 | // Report des Erreurs |
165 | // Faut-il les enregistrer dans newmod ? bonne question |
166 | Interface_CheckIterator checklist = ctx.CheckList(); |
167 | if (!checklist.IsEmpty(Standard_False)) { |
168 | checks.Merge(checklist); |
169 | sout<<"IFSelect_TransformStandard : Messages from Modifier n0 "<<i<<" of "<<nb<<endl; |
170 | checklist.Print(sout,newmod,Standard_False); |
171 | } |
172 | if (!checklist.IsEmpty(Standard_True)) { |
173 | sout<<" -- Abandon TransformStandard --"<<endl; |
174 | res = Standard_False; break; |
175 | } |
176 | } |
177 | |
178 | // Modele pas modifie et Graphe pas modifie : le dire |
179 | if (newmod == original && !chg) newmod.Nullify(); |
180 | return res; |
181 | } |
182 | |
183 | Standard_Boolean IFSelect_TransformStandard::Updated |
184 | (const Handle(Standard_Transient)& entfrom, |
185 | Handle(Standard_Transient)& entto) const |
186 | { |
187 | if (themap.IsNull()) return Standard_False; |
188 | return themap->Search(entfrom,entto); |
189 | } |
190 | |
191 | |
192 | TCollection_AsciiString IFSelect_TransformStandard::Label () const |
193 | { |
194 | char lab[30]; |
195 | TCollection_AsciiString labl(""); |
196 | if (CopyOption()) labl.AssignCat("Standard Copy"); |
197 | else labl.AssignCat("On the spot Edition"); |
198 | Standard_Integer nb = NbModifiers(); |
199 | if (nb == 0) sprintf(lab," (no Modifier)"); |
200 | if (nb == 1) sprintf(lab," - %s",Modifier(1)->Label().ToCString()); |
201 | if (nb > 1) sprintf(lab," - %d Modifiers",nb); |
202 | labl.AssignCat(lab); |
203 | return labl; |
204 | } |