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 | |
42cf5bc1 |
19 | #include <IGESBasic_HArray1OfLineFontEntity.hxx> |
20 | #include <IGESData_DirChecker.hxx> |
21 | #include <IGESData_Dump.hxx> |
22 | #include <IGESData_HArray1OfIGESEntity.hxx> |
23 | #include <IGESData_IGESDumper.hxx> |
7fd59977 |
24 | #include <IGESData_IGESEntity.hxx> |
42cf5bc1 |
25 | #include <IGESData_IGESReaderData.hxx> |
26 | #include <IGESData_IGESWriter.hxx> |
7fd59977 |
27 | #include <IGESData_LineFontEntity.hxx> |
42cf5bc1 |
28 | #include <IGESData_ParamCursor.hxx> |
29 | #include <IGESData_ParamReader.hxx> |
7fd59977 |
30 | #include <IGESData_ViewKindEntity.hxx> |
31 | #include <IGESDraw_HArray1OfViewKindEntity.hxx> |
42cf5bc1 |
32 | #include <IGESDraw_ToolViewsVisibleWithAttr.hxx> |
33 | #include <IGESDraw_ViewsVisibleWithAttr.hxx> |
34 | #include <IGESGraph_Color.hxx> |
7fd59977 |
35 | #include <IGESGraph_HArray1OfColor.hxx> |
42cf5bc1 |
36 | #include <Interface_Check.hxx> |
37 | #include <Interface_CopyTool.hxx> |
38 | #include <Interface_EntityIterator.hxx> |
7fd59977 |
39 | #include <Interface_Macros.hxx> |
42cf5bc1 |
40 | #include <Interface_ShareTool.hxx> |
41 | #include <Message_Messenger.hxx> |
42 | #include <Standard_DomainError.hxx> |
43 | #include <TColStd_HArray1OfInteger.hxx> |
7fd59977 |
44 | |
42cf5bc1 |
45 | #include <stdio.h> |
7fd59977 |
46 | IGESDraw_ToolViewsVisibleWithAttr::IGESDraw_ToolViewsVisibleWithAttr () { } |
47 | |
48 | |
49 | void IGESDraw_ToolViewsVisibleWithAttr::ReadOwnParams |
50 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, |
51 | const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const |
52 | { |
53 | //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed |
54 | |
55 | Standard_Integer tempNbBlocks, tempNbEntity; |
56 | Handle(IGESDraw_HArray1OfViewKindEntity) tempViewEntities; |
57 | Handle(IGESGraph_HArray1OfColor) tempColorDefinitions; |
58 | Handle(TColStd_HArray1OfInteger) tempLineFonts; |
59 | Handle(TColStd_HArray1OfInteger) tempColorValues; |
60 | Handle(TColStd_HArray1OfInteger) tempLineWeights; |
61 | Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities; |
62 | Handle(IGESBasic_HArray1OfLineFontEntity) tempLineDefinitions; |
63 | |
64 | //st = PR.ReadInteger(PR.Current(), "Number Of Blocks", tempNbBlocks); //szv#4:S4163:12Mar99 moved in if |
65 | if (PR.ReadInteger(PR.Current(), "Number Of Blocks", tempNbBlocks)) { |
66 | // Initialise HArray1 only if there is no error reading its Length |
67 | if (tempNbBlocks <= 0) |
68 | PR.AddFail("Number Of Blocks : Not Positive"); |
69 | else { |
70 | tempViewEntities = new IGESDraw_HArray1OfViewKindEntity(1, tempNbBlocks); |
71 | tempLineFonts = new TColStd_HArray1OfInteger(1, tempNbBlocks); |
72 | tempLineDefinitions = new IGESBasic_HArray1OfLineFontEntity(1, tempNbBlocks); |
73 | tempColorValues = new TColStd_HArray1OfInteger(1, tempNbBlocks); |
74 | tempColorDefinitions = new IGESGraph_HArray1OfColor(1, tempNbBlocks); |
75 | tempLineWeights = new TColStd_HArray1OfInteger(1, tempNbBlocks); |
76 | } |
77 | } |
78 | |
79 | if (PR.DefinedElseSkip()) |
80 | PR.ReadInteger(PR.Current(), "Number of Entities Displayed", |
81 | tempNbEntity); //szv#4:S4163:12Mar99 `st=` not needed |
82 | else { |
83 | tempNbEntity = 0; |
84 | PR.AddWarning("Number of Entities Displayed : undefined, set to Zero"); |
85 | } |
86 | // Initialise HArray1 only if there is no error reading its Length |
87 | if (tempNbEntity < 0) |
88 | PR.AddFail ("Number Of Entities Displayed : Less than Zero"); |
89 | |
90 | // Read the HArray1 only if its Length was read without any Error |
91 | if (! (tempViewEntities.IsNull())) { |
92 | // Assumption : When tempViewEntities != NULL, all other parallel |
93 | // arrays are also non-NULL |
94 | Standard_Integer I; |
95 | for (I = 1; I <= tempNbBlocks; I++) { |
96 | Handle(IGESData_ViewKindEntity) tempView; |
97 | Standard_Integer tempLineFont; |
98 | Handle(IGESData_LineFontEntity) tempEntity1; |
99 | Standard_Integer tempColorValue; |
100 | Handle(IGESGraph_Color) tempColorDef; |
101 | Standard_Integer tempLineWeightValue; |
102 | |
103 | //st = PR.ReadEntity(IR, PR.Current(), "View Entity", |
104 | //STANDARD_TYPE(IGESData_ViewKindEntity), tempView); //szv#4:S4163:12Mar99 moved in if |
105 | if (PR.ReadEntity(IR, PR.Current(), "View Entity", |
106 | STANDARD_TYPE(IGESData_ViewKindEntity), tempView)) |
107 | tempViewEntities->SetValue(I, tempView); |
108 | |
109 | //st = PR.ReadInteger(PR.Current(), "Line Font Value", tempLineFont); //szv#4:S4163:12Mar99 moved in if |
110 | if (PR.ReadInteger(PR.Current(), "Line Font Value", tempLineFont)) |
111 | tempLineFonts->SetValue(I, tempLineFont); |
112 | |
113 | //st = PR.ReadEntity(IR, PR.Current(), "Line Font Definition", |
114 | //STANDARD_TYPE(IGESData_LineFontEntity), |
115 | //tempEntity1, Standard_True); //szv#4:S4163:12Mar99 moved in if |
116 | if (tempLineFont == 0 && |
117 | PR.ReadEntity(IR, PR.Current(), "Line Font Definition", |
118 | STANDARD_TYPE(IGESData_LineFontEntity), |
119 | tempEntity1, Standard_True)) |
120 | tempLineDefinitions->SetValue(I, tempEntity1); |
121 | |
122 | Standard_Integer curnum = PR.CurrentNumber(); |
123 | // Reading Color : Value (>0) or Definition (<0 = D.E. Pointer) |
124 | if (PR.DefinedElseSkip()) |
125 | PR.ReadInteger( PR.Current(), "Color Value", tempColorValue); //szv#4:S4163:12Mar99 `st=` not needed |
126 | else { |
127 | tempColorValue = 0; |
128 | PR.AddWarning ("Color Value : undefined, set to Zero"); |
129 | } |
130 | if (tempColorValue < 0) { |
131 | tempColorValues->SetValue(I, -1); |
132 | tempColorDef = GetCasted(IGESGraph_Color,PR.ParamEntity(IR,curnum)); |
133 | if (tempColorDef.IsNull()) PR.AddFail |
134 | ("A Color Definition Entity is incorrect"); |
135 | else tempColorDefinitions->SetValue(I, tempColorDef); |
136 | } |
137 | else |
138 | tempColorValues->SetValue(I, tempColorValue); |
139 | |
140 | //st = PR.ReadInteger(PR.Current(), "Line Weight Value", |
141 | //tempLineWeightValue); //szv#4:S4163:12Mar99 moved in if |
142 | if (PR.ReadInteger(PR.Current(), "Line Weight Value", tempLineWeightValue)) |
143 | tempLineWeights->SetValue(I, tempLineWeightValue); |
144 | } |
145 | } |
146 | |
147 | // Read the HArray1 only if its Length was read without any Error |
148 | if (tempNbEntity > 0) { |
149 | PR.ReadEnts (IR,PR.CurrentList(tempNbEntity), |
150 | "Displayed Entities",tempDisplayEntities); //szv#4:S4163:12Mar99 `st=` not needed |
151 | /* |
152 | tempDisplayEntities = new IGESData_HArray1OfIGESEntity (1, tempNbEntity); |
153 | Standard_Integer I; |
154 | for (I = 1; I <= tempNbEntity; I++) { |
155 | Handle(IGESData_IGESEntity) tempEntity3; |
156 | st = PR.ReadEntity(IR, PR.Current(), "Entity", tempEntity3); |
157 | if (st) tempDisplayEntities->SetValue(I, tempEntity3); |
158 | } |
159 | */ |
160 | } |
161 | |
162 | DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent); |
163 | ent->Init |
164 | (tempViewEntities, tempLineFonts, tempLineDefinitions, |
165 | tempColorValues, tempColorDefinitions, tempLineWeights, |
166 | tempDisplayEntities); |
167 | } |
168 | |
169 | void IGESDraw_ToolViewsVisibleWithAttr::WriteOwnParams |
170 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, IGESData_IGESWriter& IW) const |
171 | { |
172 | Standard_Integer up = ent->NbViews(); |
173 | IW.Send(up); |
174 | IW.Send(ent->NbDisplayedEntities()); |
175 | |
176 | Standard_Integer I; |
177 | for (I = 1; I <= up; I++) { |
178 | IW.Send(ent->ViewItem(I)); |
179 | IW.Send(ent->LineFontValue(I)); |
180 | IW.Send(ent->FontDefinition(I)); // controlled by LineFontValue, both sent |
181 | if (ent->IsColorDefinition(I)) |
182 | IW.Send(ent->ColorDefinition(I),Standard_True); // negative |
183 | else |
184 | IW.Send(ent->ColorValue(I)); |
185 | IW.Send(ent->LineWeightItem(I)); |
186 | } |
187 | up = ent->NbDisplayedEntities(); |
188 | for (I = 1; I <= up; I++) |
189 | IW.Send(ent->DisplayedEntity(I)); |
190 | } |
191 | |
192 | void IGESDraw_ToolViewsVisibleWithAttr::OwnShared |
193 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, Interface_EntityIterator& iter) const |
194 | { |
195 | Standard_Integer up = ent->NbViews(); |
196 | |
197 | Standard_Integer I; |
198 | for (I = 1; I <= up; I++) { |
199 | iter.GetOneItem(ent->ViewItem(I)); |
200 | iter.GetOneItem(ent->FontDefinition(I)); |
201 | if ( ent->IsColorDefinition(I) ) |
202 | iter.GetOneItem(ent->ColorDefinition(I)); |
203 | } |
204 | // Displayed -> Implied |
205 | } |
206 | |
207 | void IGESDraw_ToolViewsVisibleWithAttr::OwnImplied |
208 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, Interface_EntityIterator& iter) const |
209 | { |
210 | Standard_Integer I,up; |
211 | up = ent->NbDisplayedEntities(); |
212 | for (I = 1; I <= up; I++) |
213 | iter.GetOneItem(ent->DisplayedEntity(I)); |
214 | } |
215 | |
216 | |
217 | void IGESDraw_ToolViewsVisibleWithAttr::OwnCopy |
218 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& another, |
219 | const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, Interface_CopyTool& TC) const |
220 | { |
221 | Standard_Integer I; |
222 | Standard_Integer up = another->NbViews(); |
223 | Handle(IGESDraw_HArray1OfViewKindEntity) tempViewEntities = |
224 | new IGESDraw_HArray1OfViewKindEntity(1, up); |
225 | Handle(TColStd_HArray1OfInteger) tempLineFonts = |
226 | new TColStd_HArray1OfInteger(1, up); |
227 | Handle(IGESBasic_HArray1OfLineFontEntity) tempLineDefinitions = |
228 | new IGESBasic_HArray1OfLineFontEntity(1, up); |
229 | Handle(TColStd_HArray1OfInteger) tempColorValues = |
230 | new TColStd_HArray1OfInteger(1, up); |
231 | Handle(IGESGraph_HArray1OfColor) tempColorDefinitions = |
232 | new IGESGraph_HArray1OfColor(1, up); |
233 | Handle(TColStd_HArray1OfInteger) tempLineWeights = |
234 | new TColStd_HArray1OfInteger(1, up); |
235 | |
236 | for (I = 1; I <= up; I ++) { |
237 | DeclareAndCast(IGESData_ViewKindEntity, tempView, |
238 | TC.Transferred(another->ViewItem(I))); |
239 | tempViewEntities->SetValue(I,tempView); |
240 | Standard_Integer tempLineFont = another->LineFontValue(I); |
241 | tempLineFonts->SetValue(I,tempLineFont); |
242 | if (another->IsFontDefinition(I)) { |
243 | DeclareAndCast(IGESData_LineFontEntity, tempEntity1, |
244 | TC.Transferred(another->FontDefinition(I))); |
245 | tempLineDefinitions->SetValue(I,tempEntity1); |
246 | } |
247 | if (another->IsColorDefinition(I)) { |
248 | DeclareAndCast(IGESGraph_Color, tempEntity2, |
249 | TC.Transferred(another->ColorDefinition(I))); |
250 | tempColorDefinitions->SetValue(I,tempEntity2); |
251 | } |
252 | else { |
253 | Standard_Integer tempColorValue = another->ColorValue(I); |
254 | tempColorValues->SetValue(I,tempColorValue); |
255 | } |
256 | Standard_Integer tempLineWeight = another->LineWeightItem(I); |
257 | tempLineWeights->SetValue(I, tempLineWeight); |
258 | } |
259 | // Displayed -> Implied : mettre une liste vide par defaut |
260 | Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities; |
261 | ent->Init(tempViewEntities, tempLineFonts, tempLineDefinitions, |
262 | tempColorValues, tempColorDefinitions, tempLineWeights, |
263 | tempDisplayEntities); |
264 | } |
265 | |
266 | void IGESDraw_ToolViewsVisibleWithAttr::OwnRenew |
267 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& another, |
268 | const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, const Interface_CopyTool& TC) const |
269 | { |
270 | Interface_EntityIterator newdisp; |
271 | Standard_Integer I, up; |
272 | up = another->NbDisplayedEntities(); |
273 | if (up == 0) return; |
274 | Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities; |
aa00364d |
275 | Handle(Standard_Transient) anew; |
7fd59977 |
276 | for (I = 1; I <= up; I++) { |
277 | if (TC.Search (another->DisplayedEntity(I),anew)) newdisp.GetOneItem(anew); |
278 | } |
279 | |
280 | up = newdisp.NbEntities(); I = 0; |
281 | if (up > 0) tempDisplayEntities = new IGESData_HArray1OfIGESEntity(1,up); |
282 | for (newdisp.Start(); newdisp.More(); newdisp.Next()) { |
283 | I ++; |
284 | DeclareAndCast(IGESData_IGESEntity, tempEntity,newdisp.Value()); |
285 | tempDisplayEntities->SetValue(I, tempEntity); |
286 | } |
287 | ent->InitImplied (tempDisplayEntities); |
288 | } |
289 | |
290 | |
291 | IGESData_DirChecker IGESDraw_ToolViewsVisibleWithAttr::DirChecker |
292 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& /*ent*/) const |
293 | { |
294 | IGESData_DirChecker DC(402, 4); |
295 | DC.Structure(IGESData_DefVoid); |
296 | DC.LineFont(IGESData_DefVoid); |
297 | DC.LineWeight(IGESData_DefVoid); |
298 | DC.Color(IGESData_DefVoid); |
299 | DC.BlankStatusIgnored(); |
300 | DC.SubordinateStatusRequired(0); |
301 | DC.UseFlagRequired(1); |
302 | DC.HierarchyStatusIgnored(); |
303 | |
304 | return DC; |
305 | } |
306 | |
307 | void IGESDraw_ToolViewsVisibleWithAttr::OwnCheck |
308 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, |
309 | const Interface_ShareTool& , Handle(Interface_Check)& ach) const |
310 | { |
311 | Standard_Integer nb = ent->NbViews(); |
312 | Standard_Integer i; //svv Jan 10 2000 : porting on DEC |
313 | for (i = 1; i <= nb; i ++) { |
314 | if (ent->LineFontValue(i) != 0 && ent->IsFontDefinition(i)) ach->AddFail |
315 | ("At least one Line Font Definition Mismatch (both Value and Entity"); |
316 | } |
5b111128 |
317 | Handle(IGESData_ViewKindEntity) entcomp (ent); |
7fd59977 |
318 | Standard_Integer res = 0; |
319 | nb = ent->NbDisplayedEntities(); |
320 | for (i = 1; i <= nb; i ++) { |
321 | Handle(IGESData_IGESEntity) displayed = ent->DisplayedEntity(i); |
322 | if (entcomp != displayed->View()) res ++; |
323 | } |
324 | if (!res) return; |
325 | char mess[80]; |
326 | sprintf(mess,"Mismatch for %d Entities displayed",res); |
327 | ach->AddFail(mess,"Mismatch for %d Entities displayed"); |
328 | } |
329 | |
330 | void IGESDraw_ToolViewsVisibleWithAttr::OwnWhenDelete |
331 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent) const |
332 | { |
333 | Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities; |
334 | ent->InitImplied (tempDisplayEntities); |
335 | } |
336 | |
337 | |
338 | void IGESDraw_ToolViewsVisibleWithAttr::OwnDump |
339 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, const IGESData_IGESDumper& dumper, |
340 | const Handle(Message_Messenger)& S, const Standard_Integer level) const |
341 | { |
342 | Standard_Integer tempSubLevel = (level <= 4) ? 0 : 1; |
343 | |
344 | S << "IGESDraw_ViewsVisibleWithAttr" << endl; |
345 | |
346 | S << "View Entities : " << endl |
347 | << "Line Font Values : " << endl |
348 | << "Line Font Definitions : " << endl |
349 | << "Color Number/Definitions : " << endl |
350 | << "Line Weights : " << endl; |
351 | S << "Count of View Blocks : " << ent->NbViews() << endl; |
352 | if (level > 4) { // Level = 4 : nothing to Dump. Level = 5 & 6 : same Dump |
353 | Standard_Integer I; |
354 | Standard_Integer upper = ent->NbViews(); |
355 | for (I = 1; I <= upper; I++) { |
356 | S << "[" << I << "]: " << endl; |
357 | S << "View Entity : "; |
358 | dumper.Dump (ent->ViewItem(I),S, tempSubLevel); |
359 | S << endl; |
360 | |
361 | if (ent->IsFontDefinition(I)) { |
362 | S << "Line Font Definition : "; |
363 | dumper.Dump (ent->FontDefinition(I),S, tempSubLevel); |
364 | S << endl; |
365 | } |
366 | else S << "Line Font Value : " << ent->LineFontValue(I) << endl; |
367 | |
368 | if (ent->IsColorDefinition(I)) { |
369 | S << "Color Definition : "; |
370 | dumper.Dump (ent->ColorDefinition(I),S, tempSubLevel); |
371 | S << endl; |
372 | } |
373 | else S << "Color Value : " << ent->ColorValue(I) << endl; |
374 | |
375 | S << "Line Weight : " << ent->LineWeightItem(I) << endl; |
376 | } |
377 | } |
378 | S << "Displayed Entities : "; |
379 | IGESData_DumpEntities |
380 | (S,dumper ,level,1, ent->NbDisplayedEntities(),ent->DisplayedEntity); |
381 | S << endl; |
382 | } |
383 | |
384 | Standard_Boolean IGESDraw_ToolViewsVisibleWithAttr::OwnCorrect |
385 | (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent) const |
386 | { |
387 | // Les entites affichees doivent referencer <ent>. Elles ont priorite. |
388 | Standard_Boolean res = Standard_False; |
389 | Standard_Integer nb = ent->NbDisplayedEntities(); |
5b111128 |
390 | Handle(IGESData_ViewKindEntity) entcomp (ent); |
7fd59977 |
391 | for (Standard_Integer i = 1; i <= nb; i ++) { |
392 | Handle(IGESData_IGESEntity) displayed = ent->DisplayedEntity(i); |
393 | if (entcomp != displayed->View()) res = Standard_True; |
394 | } |
395 | if (!res) return res; |
396 | Handle(IGESData_HArray1OfIGESEntity) nulDisplayEntities; |
397 | ent->InitImplied (nulDisplayEntities); |
398 | return res; |
399 | } |