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_DrawingWithRotation.hxx>
32 #include <IGESDraw_HArray1OfViewKindEntity.hxx>
33 #include <IGESDraw_PerspectiveView.hxx>
34 #include <IGESDraw_ToolDrawingWithRotation.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>
44 #include <TColStd_HArray1OfReal.hxx>
46 IGESDraw_ToolDrawingWithRotation::IGESDraw_ToolDrawingWithRotation () { }
49 void IGESDraw_ToolDrawingWithRotation::ReadOwnParams
50 (const Handle(IGESDraw_DrawingWithRotation)& ent,
51 const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
53 //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
54 Standard_Integer nbval;
56 Handle(IGESDraw_HArray1OfViewKindEntity) views;
57 Handle(TColgp_HArray1OfXY) viewOrigins;
58 Handle(TColStd_HArray1OfReal) orientationAngles;
59 Handle(IGESData_HArray1OfIGESEntity) annotations;
61 // Reading nbval(Count of Array Views)
62 Standard_Boolean st = PR.ReadInteger(PR.Current(), "count of array views", nbval);
65 views = new IGESDraw_HArray1OfViewKindEntity(1, nbval);
66 viewOrigins = new TColgp_HArray1OfXY(1, nbval);
67 orientationAngles = new TColStd_HArray1OfReal(1, nbval);
69 Handle(IGESData_ViewKindEntity) tempView;
71 Standard_Real tempOrient;
73 for (Standard_Integer i = 1; i <= nbval; i++)
75 // Reading views(HArray1OfView)
76 //st = PR.ReadEntity (IR, PR.Current(), "Instance of views",
77 //STANDARD_TYPE(IGESData_ViewKindEntity), tempView,Standard_True); //szv#4:S4163:12Mar99 moved in if
78 if (PR.ReadEntity (IR, PR.Current(), "Instance of views",
79 STANDARD_TYPE(IGESData_ViewKindEntity), tempView,Standard_True))
80 views->SetValue(i, tempView);
82 // Reading viewOrigins(HArray1OfXY)
83 //st = PR.ReadXY(PR.CurrentList(1, 2), "array viewOrigins", tempXY); //szv#4:S4163:12Mar99 moved in if
84 if (PR.ReadXY(PR.CurrentList(1, 2), "array viewOrigins", tempXY))
85 viewOrigins->SetValue(i, tempXY);
87 if (PR.DefinedElseSkip())
89 // Reading orientationAngles(HArray1OfReal)
90 //st = PR.ReadReal(PR.Current(), "array viewOrigins", tempOrient); //szv#4:S4163:12Mar99 moved in if
91 if (PR.ReadReal(PR.Current(), "array viewOrigins", tempOrient))
92 orientationAngles->SetValue(i, tempOrient);
94 else orientationAngles->SetValue(i, 0.0); // Default Value
98 PR.AddFail("Count of view entities : Not Positive");
100 // Reading nbval(No. of Annotation Entities)
101 //st = PR.ReadInteger(PR.Current(), "Count of array of Annotation entities", nbval); //szv#4:S4163:12Mar99 moved in if
102 if (PR.ReadInteger(PR.Current(), "Count of array of Annotation entities", nbval)) {
104 PR.ReadEnts (IR,PR.CurrentList(nbval), "Annotation Entities", annotations); //szv#4:S4163:12Mar99 `st=` not needed
107 // Reading annotations(HArray1OfIGESEntity)
108 annotations = new IGESData_HArray1OfIGESEntity(1, nbval);
109 Handle(IGESData_IGESEntity) tempAnnotation;
110 for (Standard_Integer i = 1; i <= nbval; i++)
113 (IR, PR.Current(), "annotation entity", tempAnnotation,Standard_True);
114 if (st) annotations->SetValue(i, tempAnnotation);
119 PR.AddFail("Count of Annotation entities : Less than zero");
122 DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
123 ent->Init (views, viewOrigins, orientationAngles, annotations);
126 void IGESDraw_ToolDrawingWithRotation::WriteOwnParams
127 (const Handle(IGESDraw_DrawingWithRotation)& ent, IGESData_IGESWriter& IW) const
129 Standard_Integer Up = ent->NbViews();
131 Standard_Integer i; // svv Jan 10 2000 : porting on DEC
132 for ( i = 1; i <= Up; i++)
134 IW.Send( ent->ViewItem(i) );
135 IW.Send( (ent->ViewOrigin(i)).X() );
136 IW.Send( (ent->ViewOrigin(i)).Y() );
137 IW.Send( ent->OrientationAngle(i) );
140 Up = ent->NbAnnotations();
142 for ( i = 1; i <= Up; i++)
143 IW.Send( ent->Annotation(i) );
146 void IGESDraw_ToolDrawingWithRotation::OwnShared
147 (const Handle(IGESDraw_DrawingWithRotation)& ent, Interface_EntityIterator& iter) const
149 Standard_Integer Up = ent->NbViews();
150 Standard_Integer i; // svv Jan 10 2000 : porting on DEC
151 for ( i = 1; i <= Up; i++)
152 iter.GetOneItem( ent->ViewItem(i) );
153 Up = ent->NbAnnotations();
154 for ( i = 1; i <= Up; i++)
155 iter.GetOneItem( ent->Annotation(i) );
158 void IGESDraw_ToolDrawingWithRotation::OwnCopy
159 (const Handle(IGESDraw_DrawingWithRotation)& another,
160 const Handle(IGESDraw_DrawingWithRotation)& ent, Interface_CopyTool& TC) const
162 Standard_Integer nbanot;
163 Standard_Integer nbval;
164 Handle(IGESDraw_HArray1OfViewKindEntity) views;
165 Handle(TColgp_HArray1OfXY) viewOrigins;
166 Handle(TColStd_HArray1OfReal) orientationAngles;
167 Handle(IGESData_HArray1OfIGESEntity) annotations;
169 nbanot = another->NbAnnotations();
170 nbval = another->NbViews();
171 views = new IGESDraw_HArray1OfViewKindEntity(1, nbval);
172 viewOrigins = new TColgp_HArray1OfXY(1, nbval);
173 orientationAngles = new TColStd_HArray1OfReal(1, nbval);
177 annotations = new IGESData_HArray1OfIGESEntity(1, nbanot);
178 for (Standard_Integer i = 1; i <= nbanot; i++)
180 DeclareAndCast(IGESData_IGESEntity, tempAnnotation,
181 TC.Transferred(another->Annotation(i)));
182 annotations->SetValue( i, tempAnnotation );
186 for (Standard_Integer i = 1; i <= nbval; i++)
188 DeclareAndCast(IGESData_ViewKindEntity, tempView,
189 TC.Transferred(another->ViewItem(i)));
190 views->SetValue( i, tempView );
192 viewOrigins->SetValue( i, (another->ViewOrigin(i)).XY() );
194 orientationAngles->SetValue( i, another->OrientationAngle(i) );
197 ent->Init(views, viewOrigins,orientationAngles, annotations);
200 Standard_Boolean IGESDraw_ToolDrawingWithRotation::OwnCorrect
201 (const Handle(IGESDraw_DrawingWithRotation)& ent ) const
203 // Vues vides : les supprimer
204 Standard_Integer i, nb = ent->NbViews();
205 Standard_Integer nbtrue = nb;
206 for (i = 1; i <= nb; i ++) {
207 Handle(IGESData_ViewKindEntity) val = ent->ViewItem(i);
208 if (val.IsNull()) nbtrue --;
209 else if (val->TypeNumber() == 0) nbtrue --;
211 if (nbtrue == nb) return Standard_False;
212 Handle(IGESDraw_HArray1OfViewKindEntity) views;
213 Handle(TColgp_HArray1OfXY) viewOrigins;
214 Handle(TColStd_HArray1OfReal) orientationAngles;
216 views = new IGESDraw_HArray1OfViewKindEntity (1, nbtrue);
217 viewOrigins = new TColgp_HArray1OfXY(1, nbtrue);
218 orientationAngles = new TColStd_HArray1OfReal(1, nbtrue);
221 for (i = 1; i <= nb; i ++) {
222 Handle(IGESData_ViewKindEntity) val = ent->ViewItem(i);
223 if (val.IsNull()) continue;
224 else if (val->TypeNumber() == 0) continue;
226 views->SetValue (nbtrue,val);
227 viewOrigins->SetValue (nbtrue, ent->ViewOrigin(i).XY() );
228 orientationAngles->SetValue (nbtrue,ent->OrientationAngle(i));
231 // Ne pas oublier les annotations ...
232 Standard_Integer nbanot = ent->NbAnnotations();
233 Handle(IGESData_HArray1OfIGESEntity) annotations =
234 new IGESData_HArray1OfIGESEntity(1, nbanot);
235 for (i = 1; i <= nbanot; i ++) annotations->SetValue (i,ent->Annotation(i));
237 ent->Init(views, viewOrigins,orientationAngles, annotations);
238 return Standard_True;
241 IGESData_DirChecker IGESDraw_ToolDrawingWithRotation::DirChecker
242 (const Handle(IGESDraw_DrawingWithRotation)& /*ent*/) const
244 IGESData_DirChecker DC (404, 1);
245 DC.Structure(IGESData_DefVoid);
246 DC.LineFont(IGESData_DefVoid);
247 DC.LineWeight(IGESData_DefVoid);
248 DC.Color(IGESData_DefVoid);
249 DC.BlankStatusIgnored();
250 DC.SubordinateStatusRequired(0);
251 DC.UseFlagRequired(1);
252 DC.HierarchyStatusIgnored();
256 void IGESDraw_ToolDrawingWithRotation::OwnCheck
257 (const Handle(IGESDraw_DrawingWithRotation)& ent,
258 const Interface_ShareTool& , Handle(Interface_Check)& ach) const
260 Standard_Boolean ianul = Standard_False;
261 Standard_Integer i, nb = ent->NbViews();
262 for (i = 1; i <= nb; i ++) {
263 Handle(IGESData_ViewKindEntity) tempView = ent->ViewItem(i);
264 if (tempView.IsNull()) ianul = Standard_True;
265 else if (tempView->TypeNumber() == 0) ianul = Standard_True;
267 ach->AddWarning ("At least one View is Null");
271 nb = ent->NbAnnotations();
272 for (i = 1; i <= nb; i ++) {
273 Handle(IGESData_IGESEntity) ann = ent->Annotation(i);
274 if (ann.IsNull()) ianul = Standard_True;
275 else if (ann->TypeNumber() == 0) ianul = Standard_True;
277 ach->AddWarning ("At least one Annotation is Null");
283 void IGESDraw_ToolDrawingWithRotation::OwnDump
284 (const Handle(IGESDraw_DrawingWithRotation)& ent, const IGESData_IGESDumper& dumper,
285 const Handle(Message_Messenger)& S, const Standard_Integer level) const
287 Standard_Integer sublevel = (level <= 4) ? 0 : 1;
289 S << "IGESDraw_DrawingWithRotation" << endl;
291 S << "View Entities : " << endl
292 << "Transformed View Origins : " << endl
293 << "Orientation Angles : ";
294 S << "Count = " << ent->NbViews() << endl;
296 if (level > 4) // Level = 4 : no Dump. Level = 5 & 6 have same Dump
299 Standard_Integer up = ent->NbViews();
300 for (I = 1; I <= up; I++)
302 S << "[" << I << "]:" << endl;
303 S << "View Entity : ";
304 dumper.Dump (ent->ViewItem(I),S, sublevel);
306 S << "Transformed View Origin : ";
307 IGESData_DumpXY(S, ent->ViewOrigin(I));
308 S << " Orientation Angle : " << ent->OrientationAngle(I) << endl;
311 S << "Annotation Entities : ";
312 IGESData_DumpEntities(S,dumper ,level,1, ent->NbAnnotations(),ent->Annotation);