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