1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
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>
25 #include <Message_Messenger.hxx>
26 #include <Message.hxx>
27 #include <Interface_Macros.hxx>
31 IFSelect_TransformStandard::IFSelect_TransformStandard ()
32 { thecopy = Standard_True; }
34 void IFSelect_TransformStandard::SetCopyOption
35 (const Standard_Boolean option)
38 Standard_Boolean IFSelect_TransformStandard::CopyOption () const
41 void IFSelect_TransformStandard::SetSelection
42 (const Handle(IFSelect_Selection)& sel)
45 Handle(IFSelect_Selection) IFSelect_TransformStandard::Selection () const
48 Standard_Integer IFSelect_TransformStandard::NbModifiers () const
49 { return themodifs.Length(); }
51 Handle(IFSelect_Modifier) IFSelect_TransformStandard::Modifier
52 (const Standard_Integer num) const
53 { return GetCasted(IFSelect_Modifier,themodifs.Value(num)); }
55 Standard_Integer IFSelect_TransformStandard::ModifierRank
56 (const Handle(IFSelect_Modifier)& modif) const
58 for (Standard_Integer i = themodifs.Length(); i >= 1; i --)
59 if (modif == themodifs.Value(i)) return i;
63 Standard_Boolean IFSelect_TransformStandard::AddModifier
64 (const Handle(IFSelect_Modifier)& modif,
65 const Standard_Integer atnum)
67 if (atnum < 0 || atnum > themodifs.Length()) return Standard_False;
68 if (atnum == 0) themodifs.Append(modif);
69 else themodifs.InsertBefore(atnum,modif);
73 Standard_Boolean IFSelect_TransformStandard::RemoveModifier
74 (const Handle(IFSelect_Modifier)& modif)
76 Standard_Integer num = ModifierRank(modif);
77 return RemoveModifier(num);
81 Standard_Boolean IFSelect_TransformStandard::RemoveModifier
82 (const Standard_Integer num)
84 if (num <= 0 || num > themodifs.Length()) return Standard_False;
85 themodifs.Remove(num);
89 // #################################################################
90 // ######## ACTION ########
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)
97 Interface_CopyTool TC(G.Model(),protocol);
98 themap = TC.Control();
100 return ApplyModifiers (G,protocol,TC,checks,newmod);
103 void IFSelect_TransformStandard::Copy
104 (const Interface_Graph& G, Interface_CopyTool& TC,
105 Handle(Interface_InterfaceModel)& newmod) const
107 if (CopyOption()) StandardCopy (G,TC,newmod);
108 else OnTheSpot (G,TC,newmod);
111 void IFSelect_TransformStandard::StandardCopy
112 (const Interface_Graph& G, Interface_CopyTool& TC,
113 Handle(Interface_InterfaceModel)& newmod) const
115 Handle(Interface_InterfaceModel) original = G.Model();
116 newmod = original->NewEmptyModel();
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));
125 TC.FillModel(newmod);
128 void IFSelect_TransformStandard::OnTheSpot
129 (const Interface_Graph& G, Interface_CopyTool& TC,
130 Handle(Interface_InterfaceModel)& newmod) const
132 Standard_Integer nb = G.Size();
133 for (Standard_Integer i = 1; i <= nb; i ++) TC.Bind(G.Entity(i),G.Entity(i));
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
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();
149 for (Standard_Integer i = 1; i <= nb; i ++) {
150 Handle(IFSelect_Modifier) unmod = Modifier(i);
151 if (unmod->MayChangeGraph()) chg = Standard_True;
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
159 Handle(IFSelect_Selection) sel = thesel;
160 if ( sel.IsNull()) sel = unmod->Selection();
162 Interface_EntityIterator entiter = sel->UniqueResult(G);
163 ctx.Select (entiter);
165 if (ctx.IsForNone()) continue;
166 unmod->Perform (ctx,newmod,protocol,TC);
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);
176 if (!checklist.IsEmpty(Standard_True)) {
177 sout<<" -- Abandon TransformStandard --"<<endl;
178 res = Standard_False; break;
182 // Modele pas modifie et Graphe pas modifie : le dire
183 if (newmod == original && !chg) newmod.Nullify();
187 Standard_Boolean IFSelect_TransformStandard::Updated
188 (const Handle(Standard_Transient)& entfrom,
189 Handle(Standard_Transient)& entto) const
191 if (themap.IsNull()) return Standard_False;
192 return themap->Search(entfrom,entto);
196 TCollection_AsciiString IFSelect_TransformStandard::Label () const
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);