0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IGESSelect / IGESSelect_RebuildDrawings.cxx
CommitLineData
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
42cf5bc1 14
15#include <gp_Pnt2d.hxx>
42cf5bc1 16#include <IFSelect_ContextModif.hxx>
7fd59977 17#include <IFSelect_PacketList.hxx>
42cf5bc1 18#include <IGESData_IGESModel.hxx>
7fd59977 19#include <IGESDraw_Drawing.hxx>
20#include <IGESDraw_DrawingWithRotation.hxx>
21#include <IGESDraw_HArray1OfViewKindEntity.hxx>
42cf5bc1 22#include <IGESSelect_RebuildDrawings.hxx>
23#include <IGESSelect_ViewSorter.hxx>
24#include <Interface_CopyTool.hxx>
7fd59977 25#include <Interface_EntityIterator.hxx>
7fd59977 26#include <Interface_Macros.hxx>
42cf5bc1 27#include <Standard_Type.hxx>
28#include <TColgp_HArray1OfXY.hxx>
29#include <TCollection_AsciiString.hxx>
30#include <TColStd_Array1OfInteger.hxx>
31#include <TColStd_HArray1OfReal.hxx>
7fd59977 32
92efcf78 33IMPLEMENT_STANDARD_RTTIEXT(IGESSelect_RebuildDrawings,IGESSelect_ModelModifier)
34
7fd59977 35#define PourDrawing 404
36
37
b311480e 38IGESSelect_RebuildDrawings::IGESSelect_RebuildDrawings ()
7fd59977 39 : IGESSelect_ModelModifier (Standard_True) { }
40
41
42 void IGESSelect_RebuildDrawings::Performing
43 (IFSelect_ContextModif& ctx,
44 const Handle(IGESData_IGESModel)& target,
45 Interface_CopyTool& TC) const
46{
47// On reconstruit les drawings qui peuvent l etre
48// Pour chaque drawing de l original, on regarde les composants transferes
49// (evt filtres par <ctx>). Pour cela, on s aide d un ViewSorter
50// Pour chaque drawing dont au moins un element a ete transfere :
51// - On passe le Drawing lui-meme, avec ses views, mais pas ses annotations
52// (c-a-d on le reconstruit)
53// - On reconnecte les views aux entites (cf Directory Part)
54
55 DeclareAndCast(IGESData_IGESModel,original,ctx.OriginalModel());
56 Standard_Integer nbo = original->NbEntities();
57 TColStd_Array1OfInteger pris(0,nbo); pris.Init(0);
58
59// Entites a prendre en compte pour la reconstruction
60// NB : Les drawings deja transferes ne sont bien sur pas reconstruits !
61 Handle(IGESSelect_ViewSorter) sorter = new IGESSelect_ViewSorter;
62 sorter->SetModel(original);
63 sorter->Add(original);
64 for (ctx.Start(); ctx.More(); ctx.Next()) {
65 pris.SetValue (original->Number(ctx.ValueOriginal()),1);
66 }
67 sorter->SortDrawings(ctx.OriginalGraph());
68 Handle(IFSelect_PacketList) sets = sorter->Sets(Standard_True);
69// Regarder, pour chaque paquet, si au moins un element a ete copie
70 Standard_Integer nbs = sets->NbPackets();
71 for (Standard_Integer is = 1; is <= nbs; is ++) {
72 Interface_EntityIterator setl = sets->Entities(is);
73 Interface_EntityIterator newset;
74 for (setl.Start(); setl.More(); setl.Next()) {
75 Handle(Standard_Transient) newent;
76 if (TC.Search(setl.Value(),newent)) newset.AddItem(newent);
77 }
78 if (newset.NbEntities() == 0) continue;
79// On en tient un : le transferer (le reconstruire)
80 Handle(IGESData_IGESEntity) item = sorter->SetItem(is,Standard_True);
81 if (item->TypeNumber() != PourDrawing) continue;
82 if (item->IsKind(STANDARD_TYPE(IGESDraw_Drawing))) {
83 DeclareAndCast(IGESDraw_Drawing,draw,item);
84 Standard_Integer nbv = draw->NbViews();
85 Handle(IGESDraw_HArray1OfViewKindEntity) views;
86 if (nbv > 0) views = new IGESDraw_HArray1OfViewKindEntity (1,nbv);
87// Passer ses vues : toutes
88// Aussi les positions des vues
89 Handle(TColgp_HArray1OfXY) origs;
90 if (nbv > 0) origs = new TColgp_HArray1OfXY (1,nbv);
91 for (Standard_Integer iv = 1; iv <= nbv; iv ++) {
92 DeclareAndCast(IGESData_ViewKindEntity,aview,
93 TC.Transferred(draw->ViewItem(iv)));
94 views->SetValue(iv,aview);
95 target->AddEntity(aview);
96 origs->SetValue(iv,draw->ViewOrigin(iv).XY());
97 }
98// Frame : passer ce qui a ete transfere
99 Handle(IGESData_HArray1OfIGESEntity) frame;
100 Standard_Integer nba = draw->NbAnnotations();
101 Interface_EntityIterator framelist;
102 Standard_Integer ia; // svv Jan11 2000 : porting on DEC
103 for (ia = 1; ia <= nba; ia ++) {
104 Handle(Standard_Transient) annot;
105 if (TC.Search(draw->Annotation(ia),annot)) framelist.GetOneItem(annot);
106 }
107 nba = framelist.NbEntities(); ia = 0;
108 if (nba > 0) frame = new IGESData_HArray1OfIGESEntity (1,nba);
109 for (framelist.Start(); framelist.More(); framelist.Next()) {
110 ia ++; frame->SetValue(ia,GetCasted(IGESData_IGESEntity,framelist.Value()));
111 }
112// Cayest, fabriquer le nouveau Drawing et l ajouter
113 Handle(IGESDraw_Drawing) newdraw = new IGESDraw_Drawing;
114 newdraw->Init (views,origs,frame);
115// Reste le nom, + autres ? drawing unit, ...
116
117// Drawing With Rotation : quasiment identique
118 } else if (item->IsKind(STANDARD_TYPE(IGESDraw_DrawingWithRotation))) {
119 DeclareAndCast(IGESDraw_DrawingWithRotation,draw,item);
120 Standard_Integer nbv = draw->NbViews();
121 Handle(IGESDraw_HArray1OfViewKindEntity) views;
122 if (nbv > 0) views = new IGESDraw_HArray1OfViewKindEntity (1,nbv);
123// Passer ses vues : toutes
124// Aussi les positions des vues .. et les rotations
125 Handle(TColgp_HArray1OfXY) origs;
126 if (nbv > 0) origs = new TColgp_HArray1OfXY (1,nbv);
127 Handle(TColStd_HArray1OfReal) rots;
128 if (nbv > 0) { rots = new TColStd_HArray1OfReal (1,nbv); rots->Init(0.0); }
129
130 for (Standard_Integer iv = 1; iv <= nbv; iv ++) {
131 DeclareAndCast(IGESData_ViewKindEntity,aview,
132 TC.Transferred(draw->ViewItem(iv)));
133 views->SetValue(iv,aview);
134 target->AddEntity(aview);
135 rots->SetValue(iv,draw->OrientationAngle(iv));
136 origs->SetValue(iv,draw->ViewOrigin(iv).XY());
137 }
138// Frame : passer ce qui a ete transfere
139 Handle(IGESData_HArray1OfIGESEntity) frame;
140 Standard_Integer nba = draw->NbAnnotations();
141 Interface_EntityIterator framelist;
142 Standard_Integer ia; // svv Jan11 2000 : porting on DEC
143 for (ia = 1; ia <= nba; ia ++) {
144 Handle(Standard_Transient) annot;
145 if (TC.Search(draw->Annotation(ia),annot)) framelist.GetOneItem(annot);
146 }
147 nba = framelist.NbEntities(); ia = 0;
148 if (nba > 0) frame = new IGESData_HArray1OfIGESEntity (1,nba);
149 for (framelist.Start(); framelist.More(); framelist.Next()) {
150 ia ++; frame->SetValue(ia,GetCasted(IGESData_IGESEntity,framelist.Value()));
151 }
152// Cayest, fabriquer le nouveau DrawingWithRotation et l ajouter
153 Handle(IGESDraw_DrawingWithRotation) newdraw = new IGESDraw_DrawingWithRotation;
154 newdraw->Init (views,origs,rots,frame);
155// Reste le nom, + autres ? drawing unit, ...
156 }
157
158// Il faut encore mettre a jour les Views notees en Directory Part
159// Pour cela, considerer <setl>, pour chaque terme, regarder View()
160// si View() transfere, mettre a jour ...
161 for (setl.Start(); setl.More(); setl.Next()) {
162 DeclareAndCast(IGESData_IGESEntity,ent,setl.Value());
aa00364d 163 Handle(IGESData_ViewKindEntity) vieworig = ent->View();
7fd59977 164 if (vieworig.IsNull()) continue;
aa00364d 165 Handle(Standard_Transient) aView;
166 if (!TC.Search(vieworig,aView)) continue;
167 Handle(IGESData_ViewKindEntity) viewnew =
168 Handle(IGESData_ViewKindEntity)::DownCast (aView);
169 if (! viewnew.IsNull())
170 ent->InitView(viewnew);
7fd59977 171 }
172 }
173
174}
175
176 TCollection_AsciiString IGESSelect_RebuildDrawings::Label () const
177{ return TCollection_AsciiString("Rebuild Drawings (with empty views)"); }