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 <gp_Pnt2d.hxx>
21 #include <IGESData_DirChecker.hxx>
22 #include <IGESData_Dump.hxx>
23 #include <IGESData_HArray1OfIGESEntity.hxx>
24 #include <IGESData_IGESDumper.hxx>
25 #include <IGESData_IGESEntity.hxx>
26 #include <IGESData_IGESReaderData.hxx>
27 #include <IGESData_IGESWriter.hxx>
28 #include <IGESData_ParamCursor.hxx>
29 #include <IGESData_ParamReader.hxx>
30 #include <IGESData_ViewKindEntity.hxx>
31 #include <IGESDraw_Drawing.hxx>
32 #include <IGESDraw_HArray1OfViewKindEntity.hxx>
33 #include <IGESDraw_PerspectiveView.hxx>
34 #include <IGESDraw_ToolDrawing.hxx>
35 #include <IGESDraw_View.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 <TColgp_HArray1OfXY.hxx>
45 IGESDraw_ToolDrawing::IGESDraw_ToolDrawing () { }
48 void IGESDraw_ToolDrawing::ReadOwnParams
49 (const Handle(IGESDraw_Drawing)& ent,
50 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
52 //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
53 Standard_Integer nbval;
55 Handle(IGESDraw_HArray1OfViewKindEntity) views;
56 Handle(TColgp_HArray1OfXY) viewOrigins;
57 Handle(IGESData_HArray1OfIGESEntity) annotations;
59 // Reading nbval(No. of View pointers)
60 Standard_Boolean st = PR.ReadInteger(PR.Current(), "Count of array of view entities", nbval);
63 views = new IGESDraw_HArray1OfViewKindEntity(1, nbval);
64 viewOrigins = new TColgp_HArray1OfXY(1, nbval);
66 Handle(IGESData_ViewKindEntity) tempView;
69 for (Standard_Integer i = 1; i <= nbval; i++)
71 // Reading views(HArray1OfView)
72 //st = PR.ReadEntity (IR, PR.Current(), "View Entity",
73 //STANDARD_TYPE(IGESData_ViewKindEntity), tempView,Standard_True); //szv#4:S4163:12Mar99 moved in if
74 if (PR.ReadEntity (IR, PR.Current(), "View Entity",
75 STANDARD_TYPE(IGESData_ViewKindEntity), tempView,Standard_True))
76 views->SetValue(i, tempView);
78 // Reading viewOrigins(HArray1OfXY)
79 //st = PR.ReadXY(PR.CurrentList(1, 2), "array viewOrigins", tempXY); //szv#4:S4163:12Mar99 moved in if
80 if (PR.ReadXY(PR.CurrentList(1, 2), "array viewOrigins", tempXY))
81 viewOrigins->SetValue(i, tempXY);
84 else if (nbval < 0) PR.AddFail("Count of view entities : Less than zero");
86 // Reading nbval(No. of Annotation Entities)
87 //st = PR.ReadInteger(PR.Current(),"Count of array of Annotation entities", nbval); //szv#4:S4163:12Mar99 moved in if
88 if (PR.ReadInteger(PR.Current(),"Count of array of Annotation entities", nbval)) {
90 PR.ReadEnts (IR,PR.CurrentList(nbval), "Annotation Entities", annotations); //szv#4:S4163:12Mar99 `st=` not needed
93 // Reading annotations(HArray1OfIGESEntity)
94 annotations = new IGESData_HArray1OfIGESEntity(1, nbval);
95 Handle(IGESData_IGESEntity) tempAnnotation;
96 for (Standard_Integer i = 1; i <= nbval; i++)
99 (IR, PR.Current(), "annotation entity", tempAnnotation,Standard_True);
100 if (st) annotations->SetValue(i, tempAnnotation);
104 else if (nbval < 0) PR.AddFail
105 ("Count of Annotation entities : Less than zero");
108 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
109 ent->Init(views, viewOrigins, annotations);
112 void IGESDraw_ToolDrawing::WriteOwnParams
113 (const Handle(IGESDraw_Drawing)& ent, IGESData_IGESWriter& IW) const
115 Standard_Integer Up = ent->NbViews();
117 Standard_Integer i; // svv Jan 10 2000 : porting on DEC
118 for ( i = 1; i <= Up; i++)
120 IW.Send( ent->ViewItem(i) );
121 IW.Send( (ent->ViewOrigin(i)).X() );
122 IW.Send( (ent->ViewOrigin(i)).Y() );
125 Up = ent->NbAnnotations();
127 for ( i = 1; i <= Up; i++)
128 IW.Send( ent->Annotation(i) );
131 void IGESDraw_ToolDrawing::OwnShared
132 (const Handle(IGESDraw_Drawing)& ent, Interface_EntityIterator& iter) const
134 Standard_Integer Up = ent->NbViews();
135 Standard_Integer i; // svv Jan 10 2000 : porting on DEC
136 for ( i = 1; i <= Up; i++)
137 iter.GetOneItem( ent->ViewItem(i) );
139 Up = ent->NbAnnotations();
140 for ( i = 1; i <= Up; i++)
141 iter.GetOneItem( ent->Annotation(i) );
144 void IGESDraw_ToolDrawing::OwnCopy
145 (const Handle(IGESDraw_Drawing)& another,
146 const Handle(IGESDraw_Drawing)& ent, Interface_CopyTool& TC) const
148 Standard_Integer nbanot;
149 Standard_Integer nbval;
150 Handle(IGESDraw_HArray1OfViewKindEntity) views;
151 Handle(TColgp_HArray1OfXY) viewOrigins;
152 Handle(IGESData_HArray1OfIGESEntity) annotations;
154 nbanot = another->NbAnnotations();
155 nbval = another->NbViews();
157 views = new IGESDraw_HArray1OfViewKindEntity(1, nbval);
158 viewOrigins = new TColgp_HArray1OfXY(1, nbval);
162 annotations = new IGESData_HArray1OfIGESEntity(1, nbanot);
163 for (Standard_Integer i = 1; i <= nbanot; i++)
165 DeclareAndCast(IGESData_IGESEntity, tempAnnotation,
166 TC.Transferred(another->Annotation(i)));
167 annotations->SetValue( i, tempAnnotation );
171 for (Standard_Integer i = 1; i <= nbval; i++)
173 DeclareAndCast(IGESData_ViewKindEntity, tempView,
174 TC.Transferred(another->ViewItem(i)) );
175 views->SetValue( i, tempView );
177 viewOrigins->SetValue( i, (another->ViewOrigin(i)).XY() );
180 ent->Init(views, viewOrigins, annotations);
183 Standard_Boolean IGESDraw_ToolDrawing::OwnCorrect
184 (const Handle(IGESDraw_Drawing)& ent ) const
186 // Vues vides : les supprimer
187 Standard_Integer i, nb = ent->NbViews();
188 Standard_Integer nbtrue = nb;
189 for (i = 1; i <= nb; i ++) {
190 Handle(IGESData_ViewKindEntity) val = ent->ViewItem(i);
191 if (val.IsNull()) nbtrue --;
192 else if (val->TypeNumber() == 0) nbtrue --;
194 if (nbtrue == nb) return Standard_False;
195 Handle(IGESDraw_HArray1OfViewKindEntity) views;
196 Handle(TColgp_HArray1OfXY) viewOrigins;
198 views = new IGESDraw_HArray1OfViewKindEntity (1, nbtrue);
199 viewOrigins = new TColgp_HArray1OfXY(1, nbtrue);
202 for (i = 1; i <= nb; i ++) {
203 Handle(IGESData_ViewKindEntity) val = ent->ViewItem(i);
204 if (val.IsNull()) continue;
205 else if (val->TypeNumber() == 0) continue;
207 views->SetValue (nbtrue,val);
208 viewOrigins->SetValue(nbtrue, ent->ViewOrigin(i).XY() );
211 // Ne pas oublier les annotations ...
212 Standard_Integer nbanot = ent->NbAnnotations();
213 Handle(IGESData_HArray1OfIGESEntity) annotations =
214 new IGESData_HArray1OfIGESEntity(1, nbanot);
215 for (i = 1; i <= nbanot; i ++) annotations->SetValue (i,ent->Annotation(i));
217 ent->Init(views, viewOrigins, annotations);
218 return Standard_True;
221 IGESData_DirChecker IGESDraw_ToolDrawing::DirChecker
222 (const Handle(IGESDraw_Drawing)& /*ent*/) const
224 IGESData_DirChecker DC (404, 0);
225 DC.Structure(IGESData_DefVoid);
226 DC.LineFont(IGESData_DefVoid);
227 DC.LineWeight(IGESData_DefVoid);
228 DC.Color(IGESData_DefVoid);
229 DC.BlankStatusIgnored();
230 DC.SubordinateStatusRequired(0);
231 DC.UseFlagRequired(1);
232 DC.HierarchyStatusIgnored();
236 void IGESDraw_ToolDrawing::OwnCheck
237 (const Handle(IGESDraw_Drawing)& ent,
238 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
240 Standard_Boolean ianul = Standard_False;
241 Standard_Integer i, nb = ent->NbViews();
242 for (i = 1; i <= nb; i ++) {
243 Handle(IGESData_ViewKindEntity) tempView = ent->ViewItem(i);
244 if (tempView.IsNull()) ianul = Standard_True;
245 else if (tempView->TypeNumber() == 0) ianul = Standard_True;
247 ach->AddWarning ("At least one View is Null");
251 nb = ent->NbAnnotations();
252 for (i = 1; i <= nb; i ++) {
253 Handle(IGESData_IGESEntity) ann = ent->Annotation(i);
254 if (ann.IsNull()) ianul = Standard_True;
255 else if (ann->TypeNumber() == 0) ianul = Standard_True;
257 ach->AddWarning ("At least one Annotation is Null");
263 void IGESDraw_ToolDrawing::OwnDump
264 (const Handle(IGESDraw_Drawing)& ent, const IGESData_IGESDumper& dumper,
265 Standard_OStream& S, const Standard_Integer level) const
267 Standard_Integer sublevel = (level <= 4) ? 0 : 1;
269 S << "IGESDraw_Drawing\n"
270 << "View Entities :\n"
271 << "Transformed View Origins : "
272 << "Count = " << ent->NbViews();
275 case 4 : S << " [ ask level > 4 for content ]\n";
276 break; // Nothing to be dumped here
277 case 5 : // Presently level 5 and 6 have the same Dump
283 Standard_Integer up = ent->NbViews();
284 for (I = 1; I <= up; I++)
286 S << "\n[" << I << "] "
288 dumper.Dump (ent->ViewItem(I),S, sublevel);
290 << "Transformed View Origin : ";
291 IGESData_DumpXY(S, ent->ViewOrigin(I));
296 S << "\nAnnotation Entities : ";
297 IGESData_DumpEntities(S,dumper ,level,1, ent->NbAnnotations(),ent->Annotation);