b311480e |
1 | // Created by: CKY / Contract Toubro-Larsen |
2 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
7fd59977 |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
7fd59977 |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
16 | //-------------------------------------------------------------------- |
7fd59977 |
17 | //-------------------------------------------------------------------- |
18 | |
7fd59977 |
19 | #include <gp_Pnt2d.hxx> |
42cf5bc1 |
20 | #include <gp_XY.hxx> |
21 | #include <IGESData_DirChecker.hxx> |
22 | #include <IGESData_Dump.hxx> |
23 | #include <IGESData_HArray1OfIGESEntity.hxx> |
24 | #include <IGESData_IGESDumper.hxx> |
25 | #include <IGESData_IGESEntity.hxx> |
26 | #include <IGESData_IGESReaderData.hxx> |
27 | #include <IGESData_IGESWriter.hxx> |
28 | #include <IGESData_ParamCursor.hxx> |
29 | #include <IGESData_ParamReader.hxx> |
7fd59977 |
30 | #include <IGESData_ViewKindEntity.hxx> |
42cf5bc1 |
31 | #include <IGESDraw_Drawing.hxx> |
7fd59977 |
32 | #include <IGESDraw_HArray1OfViewKindEntity.hxx> |
7fd59977 |
33 | #include <IGESDraw_PerspectiveView.hxx> |
42cf5bc1 |
34 | #include <IGESDraw_ToolDrawing.hxx> |
35 | #include <IGESDraw_View.hxx> |
36 | #include <Interface_Check.hxx> |
37 | #include <Interface_CopyTool.hxx> |
38 | #include <Interface_EntityIterator.hxx> |
39 | #include <Interface_Macros.hxx> |
40 | #include <Interface_ShareTool.hxx> |
41 | #include <Message_Messenger.hxx> |
42 | #include <Standard_DomainError.hxx> |
43 | #include <TColgp_HArray1OfXY.hxx> |
7fd59977 |
44 | |
45 | IGESDraw_ToolDrawing::IGESDraw_ToolDrawing () { } |
46 | |
47 | |
48 | void IGESDraw_ToolDrawing::ReadOwnParams |
49 | (const Handle(IGESDraw_Drawing)& ent, |
50 | const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const |
51 | { |
52 | //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down |
53 | Standard_Integer nbval; |
54 | |
55 | Handle(IGESDraw_HArray1OfViewKindEntity) views; |
56 | Handle(TColgp_HArray1OfXY) viewOrigins; |
57 | Handle(IGESData_HArray1OfIGESEntity) annotations; |
58 | |
59 | // Reading nbval(No. of View pointers) |
60 | Standard_Boolean st = PR.ReadInteger(PR.Current(), "Count of array of view entities", nbval); |
61 | if (st && nbval > 0) |
62 | { |
63 | views = new IGESDraw_HArray1OfViewKindEntity(1, nbval); |
64 | viewOrigins = new TColgp_HArray1OfXY(1, nbval); |
65 | |
66 | Handle(IGESData_ViewKindEntity) tempView; |
67 | gp_XY tempXY; |
68 | |
69 | for (Standard_Integer i = 1; i <= nbval; i++) |
70 | { |
71 | // Reading views(HArray1OfView) |
72 | //st = PR.ReadEntity (IR, PR.Current(), "View Entity", |
73 | //STANDARD_TYPE(IGESData_ViewKindEntity), tempView,Standard_True); //szv#4:S4163:12Mar99 moved in if |
74 | if (PR.ReadEntity (IR, PR.Current(), "View Entity", |
75 | STANDARD_TYPE(IGESData_ViewKindEntity), tempView,Standard_True)) |
76 | views->SetValue(i, tempView); |
77 | |
78 | // Reading viewOrigins(HArray1OfXY) |
79 | //st = PR.ReadXY(PR.CurrentList(1, 2), "array viewOrigins", tempXY); //szv#4:S4163:12Mar99 moved in if |
80 | if (PR.ReadXY(PR.CurrentList(1, 2), "array viewOrigins", tempXY)) |
81 | viewOrigins->SetValue(i, tempXY); |
82 | } |
83 | } |
84 | else if (nbval < 0) PR.AddFail("Count of view entities : Less than zero"); |
85 | |
86 | // Reading nbval(No. of Annotation Entities) |
87 | //st = PR.ReadInteger(PR.Current(),"Count of array of Annotation entities", nbval); //szv#4:S4163:12Mar99 moved in if |
88 | if (PR.ReadInteger(PR.Current(),"Count of array of Annotation entities", nbval)) { |
89 | if ( nbval > 0 ) |
90 | PR.ReadEnts (IR,PR.CurrentList(nbval), "Annotation Entities", annotations); //szv#4:S4163:12Mar99 `st=` not needed |
91 | /* |
92 | { |
93 | // Reading annotations(HArray1OfIGESEntity) |
94 | annotations = new IGESData_HArray1OfIGESEntity(1, nbval); |
95 | Handle(IGESData_IGESEntity) tempAnnotation; |
96 | for (Standard_Integer i = 1; i <= nbval; i++) |
97 | { |
98 | st = PR.ReadEntity |
99 | (IR, PR.Current(), "annotation entity", tempAnnotation,Standard_True); |
100 | if (st) annotations->SetValue(i, tempAnnotation); |
101 | } |
102 | } |
103 | */ |
104 | else if (nbval < 0) PR.AddFail |
105 | ("Count of Annotation entities : Less than zero"); |
106 | } |
107 | |
108 | DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent); |
109 | ent->Init(views, viewOrigins, annotations); |
110 | } |
111 | |
112 | void IGESDraw_ToolDrawing::WriteOwnParams |
113 | (const Handle(IGESDraw_Drawing)& ent, IGESData_IGESWriter& IW) const |
114 | { |
115 | Standard_Integer Up = ent->NbViews(); |
116 | IW.Send( Up ); |
117 | Standard_Integer i; // svv Jan 10 2000 : porting on DEC |
118 | for ( i = 1; i <= Up; i++) |
119 | { |
120 | IW.Send( ent->ViewItem(i) ); |
121 | IW.Send( (ent->ViewOrigin(i)).X() ); |
122 | IW.Send( (ent->ViewOrigin(i)).Y() ); |
123 | } |
124 | |
125 | Up = ent->NbAnnotations(); |
126 | IW.Send( Up ); |
127 | for ( i = 1; i <= Up; i++) |
128 | IW.Send( ent->Annotation(i) ); |
129 | } |
130 | |
131 | void IGESDraw_ToolDrawing::OwnShared |
132 | (const Handle(IGESDraw_Drawing)& ent, Interface_EntityIterator& iter) const |
133 | { |
134 | Standard_Integer Up = ent->NbViews(); |
135 | Standard_Integer i; // svv Jan 10 2000 : porting on DEC |
136 | for ( i = 1; i <= Up; i++) |
137 | iter.GetOneItem( ent->ViewItem(i) ); |
138 | |
139 | Up = ent->NbAnnotations(); |
140 | for ( i = 1; i <= Up; i++) |
141 | iter.GetOneItem( ent->Annotation(i) ); |
142 | } |
143 | |
144 | void IGESDraw_ToolDrawing::OwnCopy |
145 | (const Handle(IGESDraw_Drawing)& another, |
146 | const Handle(IGESDraw_Drawing)& ent, Interface_CopyTool& TC) const |
147 | { |
148 | Standard_Integer nbanot; |
149 | Standard_Integer nbval; |
150 | Handle(IGESDraw_HArray1OfViewKindEntity) views; |
151 | Handle(TColgp_HArray1OfXY) viewOrigins; |
152 | Handle(IGESData_HArray1OfIGESEntity) annotations; |
153 | |
154 | nbanot = another->NbAnnotations(); |
155 | nbval = another->NbViews(); |
156 | if (nbval > 0) { |
157 | views = new IGESDraw_HArray1OfViewKindEntity(1, nbval); |
158 | viewOrigins = new TColgp_HArray1OfXY(1, nbval); |
159 | } |
160 | if ( nbanot > 0 ) |
161 | { |
162 | annotations = new IGESData_HArray1OfIGESEntity(1, nbanot); |
163 | for (Standard_Integer i = 1; i <= nbanot; i++) |
164 | { |
165 | DeclareAndCast(IGESData_IGESEntity, tempAnnotation, |
166 | TC.Transferred(another->Annotation(i))); |
167 | annotations->SetValue( i, tempAnnotation ); |
168 | } |
169 | } |
170 | |
171 | for (Standard_Integer i = 1; i <= nbval; i++) |
172 | { |
173 | DeclareAndCast(IGESData_ViewKindEntity, tempView, |
174 | TC.Transferred(another->ViewItem(i)) ); |
175 | views->SetValue( i, tempView ); |
176 | |
177 | viewOrigins->SetValue( i, (another->ViewOrigin(i)).XY() ); |
178 | } |
179 | |
180 | ent->Init(views, viewOrigins, annotations); |
181 | } |
182 | |
183 | Standard_Boolean IGESDraw_ToolDrawing::OwnCorrect |
184 | (const Handle(IGESDraw_Drawing)& ent ) const |
185 | { |
186 | // Vues vides : les supprimer |
187 | Standard_Integer i, nb = ent->NbViews(); |
188 | Standard_Integer nbtrue = nb; |
189 | for (i = 1; i <= nb; i ++) { |
190 | Handle(IGESData_ViewKindEntity) val = ent->ViewItem(i); |
191 | if (val.IsNull()) nbtrue --; |
192 | else if (val->TypeNumber() == 0) nbtrue --; |
193 | } |
194 | if (nbtrue == nb) return Standard_False; |
195 | Handle(IGESDraw_HArray1OfViewKindEntity) views; |
196 | Handle(TColgp_HArray1OfXY) viewOrigins; |
197 | if (nbtrue > 0) { |
198 | views = new IGESDraw_HArray1OfViewKindEntity (1, nbtrue); |
199 | viewOrigins = new TColgp_HArray1OfXY(1, nbtrue); |
200 | } |
201 | nbtrue = 0; |
202 | for (i = 1; i <= nb; i ++) { |
203 | Handle(IGESData_ViewKindEntity) val = ent->ViewItem(i); |
204 | if (val.IsNull()) continue; |
205 | else if (val->TypeNumber() == 0) continue; |
206 | nbtrue ++; |
207 | views->SetValue (nbtrue,val); |
208 | viewOrigins->SetValue(nbtrue, ent->ViewOrigin(i).XY() ); |
209 | } |
210 | |
211 | // Ne pas oublier les annotations ... |
212 | Standard_Integer nbanot = ent->NbAnnotations(); |
213 | Handle(IGESData_HArray1OfIGESEntity) annotations = |
214 | new IGESData_HArray1OfIGESEntity(1, nbanot); |
215 | for (i = 1; i <= nbanot; i ++) annotations->SetValue (i,ent->Annotation(i)); |
216 | |
217 | ent->Init(views, viewOrigins, annotations); |
218 | return Standard_True; |
219 | } |
220 | |
221 | IGESData_DirChecker IGESDraw_ToolDrawing::DirChecker |
222 | (const Handle(IGESDraw_Drawing)& /*ent*/) const |
223 | { |
224 | IGESData_DirChecker DC (404, 0); |
225 | DC.Structure(IGESData_DefVoid); |
226 | DC.LineFont(IGESData_DefVoid); |
227 | DC.LineWeight(IGESData_DefVoid); |
228 | DC.Color(IGESData_DefVoid); |
229 | DC.BlankStatusIgnored(); |
230 | DC.SubordinateStatusRequired(0); |
231 | DC.UseFlagRequired(1); |
232 | DC.HierarchyStatusIgnored(); |
233 | return DC; |
234 | } |
235 | |
236 | void IGESDraw_ToolDrawing::OwnCheck |
237 | (const Handle(IGESDraw_Drawing)& ent, |
238 | const Interface_ShareTool& , Handle(Interface_Check)& ach) const |
239 | { |
240 | Standard_Boolean ianul = Standard_False; |
241 | Standard_Integer i, nb = ent->NbViews(); |
242 | for (i = 1; i <= nb; i ++) { |
243 | Handle(IGESData_ViewKindEntity) tempView = ent->ViewItem(i); |
244 | if (tempView.IsNull()) ianul = Standard_True; |
245 | else if (tempView->TypeNumber() == 0) ianul = Standard_True; |
246 | if (ianul) { |
247 | ach->AddWarning ("At least one View is Null"); |
248 | break; |
249 | } |
250 | } |
251 | nb = ent->NbAnnotations(); |
252 | for (i = 1; i <= nb; i ++) { |
253 | Handle(IGESData_IGESEntity) ann = ent->Annotation(i); |
254 | if (ann.IsNull()) ianul = Standard_True; |
255 | else if (ann->TypeNumber() == 0) ianul = Standard_True; |
256 | if (ianul) { |
257 | ach->AddWarning ("At least one Annotation is Null"); |
258 | break; |
259 | } |
260 | } |
261 | } |
262 | |
263 | void IGESDraw_ToolDrawing::OwnDump |
264 | (const Handle(IGESDraw_Drawing)& ent, const IGESData_IGESDumper& dumper, |
265 | const Handle(Message_Messenger)& S, const Standard_Integer level) const |
266 | { |
267 | Standard_Integer sublevel = (level <= 4) ? 0 : 1; |
268 | |
269 | S << "IGESDraw_Drawing" << endl; |
270 | |
271 | S << "View Entities : " << endl |
272 | << "Transformed View Origins : "; |
273 | S << "Count = " << ent->NbViews(); |
274 | switch (level) |
275 | { |
276 | case 4 : S << " [ ask level > 4 for content ]" << endl; |
277 | break; // Nothing to be dumped here |
278 | case 5 : // Presently level 5 and 6 have the same Dump |
279 | S << endl; |
280 | case 6 : |
281 | { |
282 | Standard_Integer I; |
283 | Standard_Integer up = ent->NbViews(); |
284 | for (I = 1; I <= up; I++) |
285 | { |
286 | S << endl << "[" << I << "] "; |
287 | S << "View Entity : "; |
288 | dumper.Dump (ent->ViewItem(I),S, sublevel); |
289 | S << endl; |
290 | S << "Transformed View Origin : "; |
291 | IGESData_DumpXY(S, ent->ViewOrigin(I)); |
292 | } |
293 | } |
294 | break; |
295 | } |
296 | S << endl << "Annotation Entities : "; |
297 | IGESData_DumpEntities(S,dumper ,level,1, ent->NbAnnotations(),ent->Annotation); |
298 | S << endl; |
299 | } |