1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
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>
30 IMPLEMENT_STANDARD_RTTIEXT(IGESSelect_RebuildGroups,IGESSelect_ModelModifier)
32 IGESSelect_RebuildGroups::IGESSelect_RebuildGroups ()
33 : IGESSelect_ModelModifier (Standard_True) { }
35 void IGESSelect_RebuildGroups::Performing
36 (IFSelect_ContextModif& ctx,
37 const Handle(IGESData_IGESModel)& target,
38 Interface_CopyTool& TC) const
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();
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);
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);
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);
69 if (ent->IsKind(STANDARD_TYPE(IGESBasic_GroupWithoutBackP))) {
70 DeclareAndCast(IGESBasic_GroupWithoutBackP,g,ent);
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);
77 if (ent->IsKind(STANDARD_TYPE(IGESBasic_OrderedGroup))) {
78 DeclareAndCast(IGESBasic_OrderedGroup,g,ent);
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);
85 if (ent->IsKind(STANDARD_TYPE(IGESBasic_OrderedGroupWithoutBackP))) {
86 DeclareAndCast(IGESBasic_OrderedGroupWithoutBackP,g,ent);
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);
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()));
103 Handle(IGESBasic_Group) g = new IGESBasic_Group;
105 target->AddEntity(g);
107 // Q : faut-il transferer le nom silyena un ?
111 Handle(IGESBasic_GroupWithoutBackP) g = new IGESBasic_GroupWithoutBackP;
113 target->AddEntity(g);
117 Handle(IGESBasic_OrderedGroup) g = new IGESBasic_OrderedGroup;
119 target->AddEntity(g);
123 Handle(IGESBasic_OrderedGroupWithoutBackP) g =
124 new IGESBasic_OrderedGroupWithoutBackP;
126 target->AddEntity(g);
134 TCollection_AsciiString IGESSelect_RebuildGroups::Label () const
135 { return TCollection_AsciiString("Rebuild Groups"); }