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