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