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