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 <IGESSelect_RebuildGroups.ixx> |
15 | #include <IGESData_IGESEntity.hxx> |
16 | #include <IGESData_HArray1OfIGESEntity.hxx> |
17 | #include <IGESBasic_Group.hxx> |
18 | #include <IGESBasic_GroupWithoutBackP.hxx> |
19 | #include <IGESBasic_OrderedGroup.hxx> |
20 | #include <IGESBasic_OrderedGroupWithoutBackP.hxx> |
21 | #include <TColStd_Array1OfInteger.hxx> |
22 | #include <Interface_EntityIterator.hxx> |
23 | #include <Interface_Macros.hxx> |
24 | |
25 | |
26 | |
b311480e |
27 | IGESSelect_RebuildGroups::IGESSelect_RebuildGroups () |
7fd59977 |
28 | : IGESSelect_ModelModifier (Standard_True) { } |
29 | |
30 | void IGESSelect_RebuildGroups::Performing |
31 | (IFSelect_ContextModif& ctx, |
32 | const Handle(IGESData_IGESModel)& target, |
33 | Interface_CopyTool& TC) const |
34 | { |
35 | // On reconstruit les groupes qui peuvent l etre |
36 | // Pour chaque groupe de l original, on regarde les composants transferes |
37 | // (evt filtres par <ctx>) |
38 | // Ensuite, silyena plus d une, on refait un nouveau groupe |
39 | DeclareAndCast(IGESData_IGESModel,original,ctx.OriginalModel()); |
40 | Standard_Integer nbo = original->NbEntities(); |
41 | |
42 | // Entites a prendre en compte pour la reconstruction |
43 | // NB : Les groupes deja transferes ne sont bien sur pas reconstruits ! |
44 | TColStd_Array1OfInteger pris(0,nbo); pris.Init(0); |
45 | for (ctx.Start(); ctx.More(); ctx.Next()) { |
46 | pris.SetValue (original->Number(ctx.ValueOriginal()),1); |
47 | } |
48 | |
49 | for (Standard_Integer i = 1; i <= nbo; i ++) { |
50 | Handle(IGESData_IGESEntity) ent = original->Entity(i); |
51 | if (ent->TypeNumber() != 402) continue; |
52 | Standard_Integer casenum = 0; |
53 | Handle(Standard_Transient) newent; |
54 | Interface_EntityIterator newlist; |
55 | if (TC.Search(ent,newent)) continue; // deja passe |
56 | if (ent->IsKind(STANDARD_TYPE(IGESBasic_Group))) { |
57 | DeclareAndCast(IGESBasic_Group,g,ent); |
58 | casenum = 1; |
59 | Standard_Integer nbg = g->NbEntities(); |
60 | for (Standard_Integer ig = 1; ig <= nbg; ig ++) { |
61 | if (TC.Search(g->Value(i),newent)) newlist.GetOneItem(newent); |
62 | } |
63 | } |
64 | if (ent->IsKind(STANDARD_TYPE(IGESBasic_GroupWithoutBackP))) { |
65 | DeclareAndCast(IGESBasic_GroupWithoutBackP,g,ent); |
66 | casenum = 2; |
67 | Standard_Integer nbg = g->NbEntities(); |
68 | for (Standard_Integer ig = 1; ig <= nbg; ig ++) { |
69 | if (TC.Search(g->Value(i),newent)) newlist.GetOneItem(newent); |
70 | } |
71 | } |
72 | if (ent->IsKind(STANDARD_TYPE(IGESBasic_OrderedGroup))) { |
73 | DeclareAndCast(IGESBasic_OrderedGroup,g,ent); |
74 | casenum = 3; |
75 | Standard_Integer nbg = g->NbEntities(); |
76 | for (Standard_Integer ig = 1; ig <= nbg; ig ++) { |
77 | if (TC.Search(g->Value(i),newent)) newlist.GetOneItem(newent); |
78 | } |
79 | } |
80 | if (ent->IsKind(STANDARD_TYPE(IGESBasic_OrderedGroupWithoutBackP))) { |
81 | DeclareAndCast(IGESBasic_OrderedGroupWithoutBackP,g,ent); |
82 | casenum = 4; |
83 | Standard_Integer nbg = g->NbEntities(); |
84 | for (Standard_Integer ig = 1; ig <= nbg; ig ++) { |
85 | if (TC.Search(g->Value(i),newent)) newlist.GetOneItem(newent); |
86 | } |
87 | } |
88 | // A present, reconstruire sil le faut |
89 | if (newlist.NbEntities() <= 1) continue; // 0 ou 1 : rien a refaire |
90 | Handle(IGESData_HArray1OfIGESEntity) tab = |
91 | new IGESData_HArray1OfIGESEntity(1,newlist.NbEntities()); |
92 | Standard_Integer ng = 0; |
93 | for (newlist.Start(); newlist.More(); newlist.Next()) { |
94 | ng ++; tab->SetValue(ng,GetCasted(IGESData_IGESEntity,newlist.Value())); |
95 | } |
96 | switch (casenum) { |
97 | case 1 : { |
98 | Handle(IGESBasic_Group) g = new IGESBasic_Group; |
99 | g->Init(tab); |
100 | target->AddEntity(g); |
101 | |
102 | // Q : faut-il transferer le nom silyena un ? |
103 | } |
104 | break; |
105 | case 2 : { |
106 | Handle(IGESBasic_GroupWithoutBackP) g = new IGESBasic_GroupWithoutBackP; |
107 | g->Init(tab); |
108 | target->AddEntity(g); |
109 | } |
110 | break; |
111 | case 3 : { |
112 | Handle(IGESBasic_OrderedGroup) g = new IGESBasic_OrderedGroup; |
113 | g->Init(tab); |
114 | target->AddEntity(g); |
115 | } |
116 | break; |
117 | case 4 : { |
118 | Handle(IGESBasic_OrderedGroupWithoutBackP) g = |
119 | new IGESBasic_OrderedGroupWithoutBackP; |
120 | g->Init(tab); |
121 | target->AddEntity(g); |
122 | } |
123 | break; |
124 | default : break; |
125 | } |
126 | } |
127 | } |
128 | |
129 | TCollection_AsciiString IGESSelect_RebuildGroups::Label () const |
130 | { return TCollection_AsciiString("Rebuild Groups"); } |