0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / IGESDraw / IGESDraw_ToolViewsVisible.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 <IGESData_DirChecker.hxx>
20 #include <IGESData_Dump.hxx>
21 #include <IGESData_IGESDumper.hxx>
22 #include <IGESData_IGESReaderData.hxx>
23 #include <IGESData_IGESWriter.hxx>
24 #include <IGESData_ParamReader.hxx>
25 #include <IGESDraw_ToolViewsVisible.hxx>
26 #include <IGESDraw_ViewsVisible.hxx>
27 #include <Interface_Check.hxx>
28 #include <Interface_CopyTool.hxx>
29 #include <Interface_EntityIterator.hxx>
30 #include <Interface_Macros.hxx>
31 #include <Interface_ShareTool.hxx>
32
33 #include <stdio.h>
34 IGESDraw_ToolViewsVisible::IGESDraw_ToolViewsVisible ()    {  }
35
36
37 void IGESDraw_ToolViewsVisible::ReadOwnParams
38   (const Handle(IGESDraw_ViewsVisible)& ent,
39    const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
40 {
41   //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
42
43   Standard_Integer tempNbViewsVisible, tempNbDisplayedEntities;
44   Handle(IGESDraw_HArray1OfViewKindEntity) tempViewEntities;
45   Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntity;
46
47   //st = PR.ReadInteger(PR.Current(), "Number Of Views Visible",
48                         //tempNbViewsVisible); //szv#4:S4163:12Mar99 moved in if
49   if (PR.ReadInteger(PR.Current(), "Number Of Views Visible", tempNbViewsVisible)) {
50     // Initialise HArray1 only if there is no error reading its Length
51     if (tempNbViewsVisible <= 0)
52       PR.AddFail("Number Of Views Visible : Not Positive");
53     else  tempViewEntities = new IGESDraw_HArray1OfViewKindEntity (1, tempNbViewsVisible);
54   }
55
56   if (PR.DefinedElseSkip())
57     PR.ReadInteger(PR.Current(), "Number of Entities Displayed",
58                    tempNbDisplayedEntities); //szv#4:S4163:12Mar99 `st=` not needed
59   else {
60     tempNbDisplayedEntities = 0;
61     PR.AddWarning("Number of Entities Displayed : undefined, set to Zero");
62   }
63   // Initialise HArray1 only if there is no error reading its Length
64   if      (tempNbDisplayedEntities < 0)
65     PR.AddFail ("Number Of Entities Displayed : Less than Zero");
66 //  else if (tempNbDisplayedEntities > 0) {
67
68   if (! tempViewEntities.IsNull()) {
69   // Read the HArray1 only if its Length was read without any Error
70     Standard_Integer I;
71     for (I = 1; I <= tempNbViewsVisible; I++) {
72       Handle(IGESData_ViewKindEntity) tempViewEntity1;
73       //st = PR.ReadEntity(IR, PR.Current(), "View Entity",
74                            //STANDARD_TYPE(IGESData_ViewKindEntity), tempViewEntity1); //szv#4:S4163:12Mar99 moved in if
75       if (PR.ReadEntity(IR, PR.Current(), "View Entity",
76                         STANDARD_TYPE(IGESData_ViewKindEntity), tempViewEntity1))
77         tempViewEntities->SetValue(I, tempViewEntity1);
78     }
79   }
80
81   // Read the HArray1 only if its Length was read without any Error
82   if      (tempNbDisplayedEntities > 0) {
83     PR.ReadEnts (IR,PR.CurrentList(tempNbDisplayedEntities),
84                  "Displayed Entities",tempDisplayEntity); //szv#4:S4163:12Mar99 `st=` not needed
85 /*
86     tempDisplayEntity =
87       new IGESData_HArray1OfIGESEntity (1, tempNbDisplayedEntities);
88
89     Handle(IGESData_IGESEntity) tempEntity2;
90     Standard_Integer I;
91     for (I = 1; I <= tempNbDisplayedEntities; I++) {
92       st = PR.ReadEntity(IR, PR.Current(), "Displayed Entity",
93                          tempEntity2);
94       if (st) tempDisplayEntity->SetValue(I, tempEntity2);
95     }
96 */
97   }
98
99   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
100   ent->Init(tempViewEntities, tempDisplayEntity);
101 }
102
103 void IGESDraw_ToolViewsVisible::WriteOwnParams
104   (const Handle(IGESDraw_ViewsVisible)& ent, IGESData_IGESWriter& IW)  const
105 {
106   IW.Send(ent->NbViews());
107   IW.Send(ent->NbDisplayedEntities());
108
109   Standard_Integer I;
110   Standard_Integer up  = ent->NbViews();
111   for (I = 1; I <= up; I++)
112     IW.Send(ent->ViewItem(I));
113   up  = ent->NbDisplayedEntities();
114   for (I = 1; I <= up; I++)
115     IW.Send(ent->DisplayedEntity(I));
116 }
117
118 void  IGESDraw_ToolViewsVisible::OwnShared
119   (const Handle(IGESDraw_ViewsVisible)& ent, Interface_EntityIterator& iter) const
120 {
121   Standard_Integer I,up;
122   up  = ent->NbViews();
123   for (I = 1; I <= up; I++)
124     iter.GetOneItem(ent->ViewItem(I));
125 //  Displayed -> Implied
126 }
127
128 void  IGESDraw_ToolViewsVisible::OwnImplied
129   (const Handle(IGESDraw_ViewsVisible)& ent, Interface_EntityIterator& iter) const
130 {
131   Standard_Integer I,up;
132   up  = ent->NbDisplayedEntities();
133   for (I = 1; I <= up; I++)
134     iter.GetOneItem(ent->DisplayedEntity(I));
135 }
136
137
138 void IGESDraw_ToolViewsVisible::OwnCopy
139   (const Handle(IGESDraw_ViewsVisible)& another,
140    const Handle(IGESDraw_ViewsVisible)& ent, Interface_CopyTool& TC) const
141 {
142   Handle(IGESDraw_HArray1OfViewKindEntity) tempViewEntities =
143     new IGESDraw_HArray1OfViewKindEntity(1, another->NbViews());
144   Standard_Integer I, up;
145   up  = another->NbViews();
146   for (I = 1; I <= up; I++) {
147     DeclareAndCast(IGESData_ViewKindEntity, tempView,
148                    TC.Transferred(another->ViewItem(I)));
149     tempViewEntities->SetValue(I, tempView);
150   }
151 //  Displayed -> Implied : mettre une liste vide par defaut
152   Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities;
153   ent->Init(tempViewEntities, tempDisplayEntities);
154 }
155
156 void IGESDraw_ToolViewsVisible::OwnRenew
157   (const Handle(IGESDraw_ViewsVisible)& another,
158    const Handle(IGESDraw_ViewsVisible)& ent, const Interface_CopyTool& TC) const
159 {
160   Interface_EntityIterator newdisp;
161   Standard_Integer I, up;
162   up  = another->NbDisplayedEntities();
163   if (up == 0) return;
164   Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities;
165   Handle(Standard_Transient) anew;
166   for (I = 1; I <= up; I++) {
167     if (TC.Search (another->DisplayedEntity(I),anew)) newdisp.GetOneItem(anew);
168   }
169
170   up = newdisp.NbEntities();  I = 0;
171   if (up > 0) tempDisplayEntities = new IGESData_HArray1OfIGESEntity(1,up);
172   for (newdisp.Start(); newdisp.More(); newdisp.Next()) {
173     I ++;
174     DeclareAndCast(IGESData_IGESEntity, tempEntity,newdisp.Value());
175     tempDisplayEntities->SetValue(I, tempEntity);
176   }
177   ent->InitImplied (tempDisplayEntities);
178 }
179
180
181 IGESData_DirChecker IGESDraw_ToolViewsVisible::DirChecker
182   (const Handle(IGESDraw_ViewsVisible)& /*ent*/)  const
183 {
184   IGESData_DirChecker DC(402, 3);
185   DC.Structure(IGESData_DefVoid);
186   DC.LineFont(IGESData_DefVoid);
187   DC.LineWeight(IGESData_DefVoid);
188   DC.Color(IGESData_DefVoid);
189   DC.BlankStatusIgnored();
190   DC.SubordinateStatusRequired(0);
191   DC.UseFlagRequired(1);
192   DC.HierarchyStatusIgnored();
193
194   return DC;
195 }
196
197 void IGESDraw_ToolViewsVisible::OwnCheck
198   (const Handle(IGESDraw_ViewsVisible)& ent,
199    const Interface_ShareTool& , Handle(Interface_Check)& ach)  const
200 {
201   Standard_Integer res = 0;
202   Standard_Integer nb = ent->NbDisplayedEntities();
203   const Handle(IGESData_ViewKindEntity)& entcomp = ent;
204   for (Standard_Integer i = 1; i <= nb; i ++) {
205     Handle(IGESData_IGESEntity) displayed = ent->DisplayedEntity(i);
206     if (entcomp != displayed->View()) res ++;
207   }
208   if (!res) return;
209   char mess[80];
210   sprintf(mess,"Mismatch for %d Entities displayed",res);
211   ach->AddFail(mess,"Mismatch for %d Entities displayed");
212 }
213
214 void  IGESDraw_ToolViewsVisible::OwnWhenDelete
215   (const Handle(IGESDraw_ViewsVisible)& ent) const
216 {
217   Handle(IGESData_HArray1OfIGESEntity) tempDisplayEntities;
218   ent->InitImplied (tempDisplayEntities);
219 }
220
221 void IGESDraw_ToolViewsVisible::OwnDump
222   (const Handle(IGESDraw_ViewsVisible)& ent, const IGESData_IGESDumper& dumper,
223    Standard_OStream& S, const Standard_Integer level)  const
224 {
225   S << "IGESDraw_ViewsVisible\n"
226     << "Views Visible : ";
227   IGESData_DumpEntities(S,dumper ,level,1, ent->NbViews(),ent->ViewItem);
228   S << "\n"
229     << "Entities Displayed : ";
230   IGESData_DumpEntities(S,dumper ,level,1, ent->NbDisplayedEntities(),ent->DisplayedEntity);
231   S << std::endl;
232 }
233
234 Standard_Boolean  IGESDraw_ToolViewsVisible::OwnCorrect
235   (const Handle(IGESDraw_ViewsVisible)& ent) const
236 {
237 //  Les entites affichees doivent referencer <ent>. Elles ont priorite.
238   Standard_Boolean res = Standard_False;
239   Standard_Integer nb = ent->NbDisplayedEntities();
240   const Handle(IGESData_ViewKindEntity)& entcomp = ent;
241   for (Standard_Integer i = 1; i <= nb; i ++) {
242     Handle(IGESData_IGESEntity) displayed = ent->DisplayedEntity(i);
243     if (entcomp != displayed->View()) res = Standard_True;
244   }
245   if (!res) return res;
246   Handle(IGESData_HArray1OfIGESEntity) nulDisplayEntities;
247   ent->InitImplied (nulDisplayEntities);
248   return res;
249 }