summaryrefslogtreecommitdiff
path: root/src/IGESDraw/IGESDraw_ToolViewsVisibleWithAttr.cxx
blob: 2de9053361f868c1cb14049f8f27f764371e002f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
//--------------------------------------------------------------------
//
//  File Name : IGESDraw_ViewsVisibleWithAttr.cxx
//  Date      :
//  Author    : CKY / Contract Toubro-Larsen
//  Copyright : MATRA-DATAVISION 1993
//
//--------------------------------------------------------------------

#include <IGESDraw_ToolViewsVisibleWithAttr.ixx>
#include <IGESData_ParamCursor.hxx>
#include <IGESData_IGESEntity.hxx>
#include <IGESGraph_Color.hxx>
#include <IGESData_LineFontEntity.hxx>
#include <IGESData_ViewKindEntity.hxx>
#include <IGESDraw_HArray1OfViewKindEntity.hxx>
#include <IGESGraph_HArray1OfColor.hxx>
#include <TColStd_HArray1OfInteger.hxx>
#include <IGESData_HArray1OfIGESEntity.hxx>
#include <IGESBasic_HArray1OfLineFontEntity.hxx>
#include <IGESData_Dump.hxx>
#include <Interface_Macros.hxx>
#include <stdio.h>


IGESDraw_ToolViewsVisibleWithAttr::IGESDraw_ToolViewsVisibleWithAttr ()    {  }


void IGESDraw_ToolViewsVisibleWithAttr::ReadOwnParams
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent,
   const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
{
  //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed

  Standard_Integer tempNbBlocks, tempNbEntity;
  Handle(IGESDraw_HArray1OfViewKindEntity) tempViewEntities;
  Handle(IGESGraph_HArray1OfColor) tempColorDefinitions;
  Handle(TColStd_HArray1OfInteger) tempLineFonts;
  Handle(TColStd_HArray1OfInteger) tempColorValues;
  Handle(TColStd_HArray1OfInteger) tempLineWeights;
  Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities;
  Handle(IGESBasic_HArray1OfLineFontEntity) tempLineDefinitions;

  //st = PR.ReadInteger(PR.Current(), "Number Of Blocks", tempNbBlocks); //szv#4:S4163:12Mar99 moved in if
  if (PR.ReadInteger(PR.Current(), "Number Of Blocks", tempNbBlocks)) {
    // Initialise HArray1 only if there is no error reading its Length
    if (tempNbBlocks <= 0)
      PR.AddFail("Number Of Blocks : Not Positive");
    else {
      tempViewEntities     = new IGESDraw_HArray1OfViewKindEntity(1, tempNbBlocks);
      tempLineFonts        = new TColStd_HArray1OfInteger(1, tempNbBlocks);
      tempLineDefinitions  = new IGESBasic_HArray1OfLineFontEntity(1, tempNbBlocks);
      tempColorValues      = new TColStd_HArray1OfInteger(1, tempNbBlocks);
      tempColorDefinitions = new IGESGraph_HArray1OfColor(1, tempNbBlocks);
      tempLineWeights      = new TColStd_HArray1OfInteger(1, tempNbBlocks);
    }
  }

  if (PR.DefinedElseSkip())
    PR.ReadInteger(PR.Current(), "Number of Entities Displayed",
		   tempNbEntity); //szv#4:S4163:12Mar99 `st=` not needed
  else {
    tempNbEntity = 0;
    PR.AddWarning("Number of Entities Displayed : undefined, set to Zero");
  }
  // Initialise HArray1 only if there is no error reading its Length
  if      (tempNbEntity < 0)
    PR.AddFail ("Number Of Entities Displayed : Less than Zero");

  // Read the HArray1 only if its Length was read without any Error
  if (! (tempViewEntities.IsNull())) {
    // Assumption : When tempViewEntities != NULL, all other parallel
    //              arrays are also non-NULL
    Standard_Integer I;
    for (I = 1; I <= tempNbBlocks; I++) {
      Handle(IGESData_ViewKindEntity) tempView;
      Standard_Integer        tempLineFont;
      Handle(IGESData_LineFontEntity) tempEntity1;
      Standard_Integer        tempColorValue;
      Handle(IGESGraph_Color) tempColorDef;
      Standard_Integer        tempLineWeightValue;

      //st = PR.ReadEntity(IR, PR.Current(), "View Entity",
			   //STANDARD_TYPE(IGESData_ViewKindEntity), tempView); //szv#4:S4163:12Mar99 moved in if
      if (PR.ReadEntity(IR, PR.Current(), "View Entity",
			STANDARD_TYPE(IGESData_ViewKindEntity), tempView))
	tempViewEntities->SetValue(I, tempView);

      //st = PR.ReadInteger(PR.Current(), "Line Font Value", tempLineFont); //szv#4:S4163:12Mar99 moved in if
      if (PR.ReadInteger(PR.Current(), "Line Font Value", tempLineFont))
	tempLineFonts->SetValue(I, tempLineFont);

      //st = PR.ReadEntity(IR, PR.Current(), "Line Font Definition",
			   //STANDARD_TYPE(IGESData_LineFontEntity),
			   //tempEntity1, Standard_True); //szv#4:S4163:12Mar99 moved in if
      if (tempLineFont == 0 &&
	  PR.ReadEntity(IR, PR.Current(), "Line Font Definition",
			STANDARD_TYPE(IGESData_LineFontEntity),
			tempEntity1, Standard_True))
	tempLineDefinitions->SetValue(I, tempEntity1);

      Standard_Integer curnum = PR.CurrentNumber();
      //  Reading Color : Value (>0) or Definition (<0 = D.E. Pointer)
      if (PR.DefinedElseSkip())
	PR.ReadInteger( PR.Current(), "Color Value", tempColorValue); //szv#4:S4163:12Mar99 `st=` not needed
      else {
	tempColorValue = 0;
	PR.AddWarning ("Color Value : undefined, set to Zero");
      }
      if (tempColorValue < 0) {
	tempColorValues->SetValue(I, -1);
	tempColorDef = GetCasted(IGESGraph_Color,PR.ParamEntity(IR,curnum));
	if (tempColorDef.IsNull()) PR.AddFail
	  ("A Color Definition Entity is incorrect");
	else  tempColorDefinitions->SetValue(I, tempColorDef);
      }
      else
	tempColorValues->SetValue(I, tempColorValue);

      //st = PR.ReadInteger(PR.Current(), "Line Weight Value",
			    //tempLineWeightValue); //szv#4:S4163:12Mar99 moved in if
      if (PR.ReadInteger(PR.Current(), "Line Weight Value", tempLineWeightValue))
	tempLineWeights->SetValue(I, tempLineWeightValue);
    }
  }

  // Read the HArray1 only if its Length was read without any Error
  if (tempNbEntity > 0) {
    PR.ReadEnts (IR,PR.CurrentList(tempNbEntity),
		 "Displayed Entities",tempDisplayEntities); //szv#4:S4163:12Mar99 `st=` not needed
/*
    tempDisplayEntities = new IGESData_HArray1OfIGESEntity (1, tempNbEntity);
    Standard_Integer I;
    for (I = 1; I <= tempNbEntity; I++) {
      Handle(IGESData_IGESEntity) tempEntity3;
      st = PR.ReadEntity(IR, PR.Current(), "Entity", tempEntity3);
      if (st) tempDisplayEntities->SetValue(I, tempEntity3);
    }
*/
  }

  DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
  ent->Init
    (tempViewEntities, tempLineFonts, tempLineDefinitions,
     tempColorValues, tempColorDefinitions, tempLineWeights,
     tempDisplayEntities);
}

void IGESDraw_ToolViewsVisibleWithAttr::WriteOwnParams
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, IGESData_IGESWriter& IW)  const
{
  Standard_Integer up  = ent->NbViews();
  IW.Send(up);
  IW.Send(ent->NbDisplayedEntities());

  Standard_Integer I;
  for (I = 1; I <= up; I++) {
    IW.Send(ent->ViewItem(I));
    IW.Send(ent->LineFontValue(I));
    IW.Send(ent->FontDefinition(I));  // controlled by LineFontValue, both sent
    if (ent->IsColorDefinition(I))
      IW.Send(ent->ColorDefinition(I),Standard_True);  // negative
    else
      IW.Send(ent->ColorValue(I));
    IW.Send(ent->LineWeightItem(I));
  }
  up  = ent->NbDisplayedEntities();
  for (I = 1; I <= up; I++)
    IW.Send(ent->DisplayedEntity(I));
}

void  IGESDraw_ToolViewsVisibleWithAttr::OwnShared
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, Interface_EntityIterator& iter) const
{
  Standard_Integer up  = ent->NbViews();

  Standard_Integer I;
  for (I = 1; I <= up; I++) {
    iter.GetOneItem(ent->ViewItem(I));
    iter.GetOneItem(ent->FontDefinition(I));
    if ( ent->IsColorDefinition(I) )
      iter.GetOneItem(ent->ColorDefinition(I));
  }
//  Displayed -> Implied
}

void  IGESDraw_ToolViewsVisibleWithAttr::OwnImplied
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, Interface_EntityIterator& iter) const
{
  Standard_Integer I,up;
  up  = ent->NbDisplayedEntities();
  for (I = 1; I <= up; I++)
    iter.GetOneItem(ent->DisplayedEntity(I));
}


void IGESDraw_ToolViewsVisibleWithAttr::OwnCopy
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& another,
   const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, Interface_CopyTool& TC) const
{
  Standard_Integer I;
  Standard_Integer up  = another->NbViews();
  Handle(IGESDraw_HArray1OfViewKindEntity) tempViewEntities =
    new IGESDraw_HArray1OfViewKindEntity(1, up);
  Handle(TColStd_HArray1OfInteger) tempLineFonts =
    new TColStd_HArray1OfInteger(1, up);
  Handle(IGESBasic_HArray1OfLineFontEntity) tempLineDefinitions =
    new IGESBasic_HArray1OfLineFontEntity(1, up);
  Handle(TColStd_HArray1OfInteger) tempColorValues =
    new TColStd_HArray1OfInteger(1, up);
  Handle(IGESGraph_HArray1OfColor) tempColorDefinitions =
    new IGESGraph_HArray1OfColor(1, up);
  Handle(TColStd_HArray1OfInteger) tempLineWeights =
    new TColStd_HArray1OfInteger(1, up);

  for (I = 1; I <= up; I ++) {
    DeclareAndCast(IGESData_ViewKindEntity, tempView,
		   TC.Transferred(another->ViewItem(I)));
    tempViewEntities->SetValue(I,tempView);
    Standard_Integer tempLineFont = another->LineFontValue(I);
    tempLineFonts->SetValue(I,tempLineFont);
    if (another->IsFontDefinition(I)) {
      DeclareAndCast(IGESData_LineFontEntity, tempEntity1,
		     TC.Transferred(another->FontDefinition(I)));
      tempLineDefinitions->SetValue(I,tempEntity1);
    }
    if (another->IsColorDefinition(I)) {
      DeclareAndCast(IGESGraph_Color, tempEntity2,
		     TC.Transferred(another->ColorDefinition(I)));
      tempColorDefinitions->SetValue(I,tempEntity2);
    }
    else {
      Standard_Integer tempColorValue = another->ColorValue(I);
      tempColorValues->SetValue(I,tempColorValue);
    }
    Standard_Integer tempLineWeight = another->LineWeightItem(I);
    tempLineWeights->SetValue(I, tempLineWeight);
  }
//  Displayed -> Implied : mettre une liste vide par defaut
  Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities;
  ent->Init(tempViewEntities, tempLineFonts, tempLineDefinitions,
	    tempColorValues, tempColorDefinitions, tempLineWeights,
	    tempDisplayEntities);
}

void IGESDraw_ToolViewsVisibleWithAttr::OwnRenew
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& another,
   const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, const Interface_CopyTool& TC) const
{
  Interface_EntityIterator newdisp;
  Standard_Integer I, up;
  up  = another->NbDisplayedEntities();
  if (up == 0) return;
  Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities;
  Handle(IGESData_IGESEntity) anew;
  for (I = 1; I <= up; I++) {
    if (TC.Search (another->DisplayedEntity(I),anew)) newdisp.GetOneItem(anew);
  }

  up = newdisp.NbEntities();  I = 0;
  if (up > 0) tempDisplayEntities = new IGESData_HArray1OfIGESEntity(1,up);
  for (newdisp.Start(); newdisp.More(); newdisp.Next()) {
    I ++;
    DeclareAndCast(IGESData_IGESEntity, tempEntity,newdisp.Value());
    tempDisplayEntities->SetValue(I, tempEntity);
  }
  ent->InitImplied (tempDisplayEntities);
}


IGESData_DirChecker IGESDraw_ToolViewsVisibleWithAttr::DirChecker
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& /*ent*/)  const
{
  IGESData_DirChecker DC(402, 4);
  DC.Structure(IGESData_DefVoid);
  DC.LineFont(IGESData_DefVoid);
  DC.LineWeight(IGESData_DefVoid);
  DC.Color(IGESData_DefVoid);
  DC.BlankStatusIgnored();
  DC.SubordinateStatusRequired(0);
  DC.UseFlagRequired(1);
  DC.HierarchyStatusIgnored();

  return DC;
}

void IGESDraw_ToolViewsVisibleWithAttr::OwnCheck
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent,
   const Interface_ShareTool& , Handle(Interface_Check)& ach)  const
{
  Standard_Integer nb = ent->NbViews();
  Standard_Integer i; //svv Jan 10 2000 : porting on DEC
  for (i = 1; i <= nb; i ++) {
    if (ent->LineFontValue(i) != 0 && ent->IsFontDefinition(i)) ach->AddFail
      ("At least one Line Font Definition Mismatch (both Value and Entity");
  }
  Handle(IGESData_ViewKindEntity) entcomp = ent;
  Standard_Integer res = 0;
  nb = ent->NbDisplayedEntities();
  for (i = 1; i <= nb; i ++) {
    Handle(IGESData_IGESEntity) displayed = ent->DisplayedEntity(i);
    if (entcomp != displayed->View()) res ++;
  }
  if (!res) return;
  char mess[80];
  sprintf(mess,"Mismatch for %d Entities displayed",res);
  ach->AddFail(mess,"Mismatch for %d Entities displayed");
}

void IGESDraw_ToolViewsVisibleWithAttr::OwnWhenDelete
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent) const
{
  Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities;
  ent->InitImplied (tempDisplayEntities);
}


void IGESDraw_ToolViewsVisibleWithAttr::OwnDump
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, const IGESData_IGESDumper& dumper,
  const Handle(Message_Messenger)& S, const Standard_Integer level)  const
{
  Standard_Integer tempSubLevel = (level <= 4) ? 0 : 1;

  S << "IGESDraw_ViewsVisibleWithAttr" << endl;

  S << "View Entities            : " << endl
    << "Line Font Values         : " << endl
    << "Line Font Definitions    : " << endl
    << "Color Number/Definitions : " << endl
    << "Line Weights             : " << endl;
  S << "Count of View Blocks : "     << ent->NbViews() << endl;
  if (level > 4) {   // Level = 4 : nothing to Dump. Level = 5 & 6 : same Dump
    Standard_Integer I;
    Standard_Integer upper  = ent->NbViews();
    for (I = 1; I <= upper; I++) {
      S << "[" << I << "]: " << endl;
      S << "View Entity : ";
      dumper.Dump (ent->ViewItem(I),S, tempSubLevel);
      S << endl;

      if (ent->IsFontDefinition(I)) {
	S << "Line Font Definition  : ";
	dumper.Dump (ent->FontDefinition(I),S, tempSubLevel);
	S << endl;
      }
      else S << "Line Font Value       : " << ent->LineFontValue(I) << endl;

      if (ent->IsColorDefinition(I)) {
	S << "Color Definition : ";
	dumper.Dump (ent->ColorDefinition(I),S, tempSubLevel);
	S << endl;
      }
      else S << "Color Value      : " << ent->ColorValue(I) << endl;

      S      << "Line Weight      : " << ent->LineWeightItem(I) << endl;
    }
  }
  S << "Displayed Entities : ";
  IGESData_DumpEntities
    (S,dumper ,level,1, ent->NbDisplayedEntities(),ent->DisplayedEntity);
  S << endl;
}

Standard_Boolean  IGESDraw_ToolViewsVisibleWithAttr::OwnCorrect
  (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent) const
{
//  Les entites affichees doivent referencer <ent>. Elles ont priorite.
  Standard_Boolean res = Standard_False;
  Standard_Integer nb = ent->NbDisplayedEntities();
  Handle(IGESData_ViewKindEntity) entcomp = ent;
  for (Standard_Integer i = 1; i <= nb; i ++) {
    Handle(IGESData_IGESEntity) displayed = ent->DisplayedEntity(i);
    if (entcomp != displayed->View()) res = Standard_True;
  }
  if (!res) return res;
  Handle(IGESData_HArray1OfIGESEntity) nulDisplayEntities;
  ent->InitImplied (nulDisplayEntities);
  return res;
}