1 // Created by: CKY / Contract Toubro-Larsen
2 // Copyright (c) 1993-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 //--------------------------------------------------------------------
17 //--------------------------------------------------------------------
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 <Message_Messenger.hxx>
42 #include <Standard_DomainError.hxx>
43 #include <TColStd_HArray1OfInteger.hxx>
46 IGESDraw_ToolViewsVisibleWithAttr::IGESDraw_ToolViewsVisibleWithAttr () { }
49 void IGESDraw_ToolViewsVisibleWithAttr::ReadOwnParams
50 (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent,
51 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
53 //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
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;
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");
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);
79 if (PR.DefinedElseSkip())
80 PR.ReadInteger(PR.Current(), "Number of Entities Displayed",
81 tempNbEntity); //szv#4:S4163:12Mar99 `st=` not needed
84 PR.AddWarning("Number of Entities Displayed : undefined, set to Zero");
86 // Initialise HArray1 only if there is no error reading its Length
88 PR.AddFail ("Number Of Entities Displayed : Less than Zero");
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
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;
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);
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);
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);
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
128 PR.AddWarning ("Color Value : undefined, set to Zero");
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);
138 tempColorValues->SetValue(I, tempColorValue);
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);
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
152 tempDisplayEntities = new IGESData_HArray1OfIGESEntity (1, tempNbEntity);
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);
162 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
164 (tempViewEntities, tempLineFonts, tempLineDefinitions,
165 tempColorValues, tempColorDefinitions, tempLineWeights,
166 tempDisplayEntities);
169 void IGESDraw_ToolViewsVisibleWithAttr::WriteOwnParams
170 (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, IGESData_IGESWriter& IW) const
172 Standard_Integer up = ent->NbViews();
174 IW.Send(ent->NbDisplayedEntities());
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
184 IW.Send(ent->ColorValue(I));
185 IW.Send(ent->LineWeightItem(I));
187 up = ent->NbDisplayedEntities();
188 for (I = 1; I <= up; I++)
189 IW.Send(ent->DisplayedEntity(I));
192 void IGESDraw_ToolViewsVisibleWithAttr::OwnShared
193 (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, Interface_EntityIterator& iter) const
195 Standard_Integer up = ent->NbViews();
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));
204 // Displayed -> Implied
207 void IGESDraw_ToolViewsVisibleWithAttr::OwnImplied
208 (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, Interface_EntityIterator& iter) const
210 Standard_Integer I,up;
211 up = ent->NbDisplayedEntities();
212 for (I = 1; I <= up; I++)
213 iter.GetOneItem(ent->DisplayedEntity(I));
217 void IGESDraw_ToolViewsVisibleWithAttr::OwnCopy
218 (const Handle(IGESDraw_ViewsVisibleWithAttr)& another,
219 const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, Interface_CopyTool& TC) const
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);
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);
247 if (another->IsColorDefinition(I)) {
248 DeclareAndCast(IGESGraph_Color, tempEntity2,
249 TC.Transferred(another->ColorDefinition(I)));
250 tempColorDefinitions->SetValue(I,tempEntity2);
253 Standard_Integer tempColorValue = another->ColorValue(I);
254 tempColorValues->SetValue(I,tempColorValue);
256 Standard_Integer tempLineWeight = another->LineWeightItem(I);
257 tempLineWeights->SetValue(I, tempLineWeight);
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);
266 void IGESDraw_ToolViewsVisibleWithAttr::OwnRenew
267 (const Handle(IGESDraw_ViewsVisibleWithAttr)& another,
268 const Handle(IGESDraw_ViewsVisibleWithAttr)& ent, const Interface_CopyTool& TC) const
270 Interface_EntityIterator newdisp;
271 Standard_Integer I, up;
272 up = another->NbDisplayedEntities();
274 Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities;
275 Handle(IGESData_IGESEntity) anew;
276 for (I = 1; I <= up; I++) {
277 if (TC.Search (another->DisplayedEntity(I),anew)) newdisp.GetOneItem(anew);
280 up = newdisp.NbEntities(); I = 0;
281 if (up > 0) tempDisplayEntities = new IGESData_HArray1OfIGESEntity(1,up);
282 for (newdisp.Start(); newdisp.More(); newdisp.Next()) {
284 DeclareAndCast(IGESData_IGESEntity, tempEntity,newdisp.Value());
285 tempDisplayEntities->SetValue(I, tempEntity);
287 ent->InitImplied (tempDisplayEntities);
291 IGESData_DirChecker IGESDraw_ToolViewsVisibleWithAttr::DirChecker
292 (const Handle(IGESDraw_ViewsVisibleWithAttr)& /*ent*/) const
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();
307 void IGESDraw_ToolViewsVisibleWithAttr::OwnCheck
308 (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent,
309 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
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");
317 Handle(IGESData_ViewKindEntity) entcomp (ent);
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 ++;
326 sprintf(mess,"Mismatch for %d Entities displayed",res);
327 ach->AddFail(mess,"Mismatch for %d Entities displayed");
330 void IGESDraw_ToolViewsVisibleWithAttr::OwnWhenDelete
331 (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent) const
333 Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities;
334 ent->InitImplied (tempDisplayEntities);
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
342 Standard_Integer tempSubLevel = (level <= 4) ? 0 : 1;
344 S << "IGESDraw_ViewsVisibleWithAttr" << endl;
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
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);
361 if (ent->IsFontDefinition(I)) {
362 S << "Line Font Definition : ";
363 dumper.Dump (ent->FontDefinition(I),S, tempSubLevel);
366 else S << "Line Font Value : " << ent->LineFontValue(I) << endl;
368 if (ent->IsColorDefinition(I)) {
369 S << "Color Definition : ";
370 dumper.Dump (ent->ColorDefinition(I),S, tempSubLevel);
373 else S << "Color Value : " << ent->ColorValue(I) << endl;
375 S << "Line Weight : " << ent->LineWeightItem(I) << endl;
378 S << "Displayed Entities : ";
379 IGESData_DumpEntities
380 (S,dumper ,level,1, ent->NbDisplayedEntities(),ent->DisplayedEntity);
384 Standard_Boolean IGESDraw_ToolViewsVisibleWithAttr::OwnCorrect
385 (const Handle(IGESDraw_ViewsVisibleWithAttr)& ent) const
387 // Les entites affichees doivent referencer <ent>. Elles ont priorite.
388 Standard_Boolean res = Standard_False;
389 Standard_Integer nb = ent->NbDisplayedEntities();
390 Handle(IGESData_ViewKindEntity) entcomp (ent);
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;
395 if (!res) return res;
396 Handle(IGESData_HArray1OfIGESEntity) nulDisplayEntities;
397 ent->InitImplied (nulDisplayEntities);