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