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