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