0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / IGESDraw / IGESDraw_ToolDrawingWithRotation.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 <gp_Pnt2d.hxx>
20 #include <gp_XY.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>
45
46 IGESDraw_ToolDrawingWithRotation::IGESDraw_ToolDrawingWithRotation ()    {  }
47
48
49 void IGESDraw_ToolDrawingWithRotation::ReadOwnParams
50   (const Handle(IGESDraw_DrawingWithRotation)& ent,
51    const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
52
53   //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
54   Standard_Integer nbval;
55
56   Handle(IGESDraw_HArray1OfViewKindEntity) views;
57   Handle(TColgp_HArray1OfXY)               viewOrigins; 
58   Handle(TColStd_HArray1OfReal)            orientationAngles; 
59   Handle(IGESData_HArray1OfIGESEntity)     annotations; 
60
61   // Reading nbval(Count of Array Views)
62   Standard_Boolean st = PR.ReadInteger(PR.Current(), "count of array views", nbval);
63   if (st && nbval > 0)
64     {
65       views             = new IGESDraw_HArray1OfViewKindEntity(1, nbval);
66       viewOrigins       = new TColgp_HArray1OfXY(1, nbval);
67       orientationAngles = new TColStd_HArray1OfReal(1, nbval);
68
69       Handle(IGESData_ViewKindEntity) tempView;
70       gp_XY tempXY;
71       Standard_Real tempOrient;
72
73       for (Standard_Integer i = 1; i <= nbval; i++)
74         {
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);
81           
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);
86           
87           if (PR.DefinedElseSkip())
88             {
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);
93             }
94           else  orientationAngles->SetValue(i, 0.0); // Default Value
95         }
96     }
97   else if (nbval <= 0)
98     PR.AddFail("Count of view entities : Not Positive");
99
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)) {
103     if ( nbval > 0 )
104       PR.ReadEnts (IR,PR.CurrentList(nbval), "Annotation Entities", annotations); //szv#4:S4163:12Mar99 `st=` not needed
105 /*
106       {
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++)
111           {
112             st = PR.ReadEntity
113               (IR, PR.Current(), "annotation entity", tempAnnotation,Standard_True);
114             if (st) annotations->SetValue(i, tempAnnotation);
115           }
116       }
117 */
118     else if (nbval < 0)
119       PR.AddFail("Count of Annotation entities : Less than zero");
120   }
121
122   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
123   ent->Init (views, viewOrigins, orientationAngles, annotations);
124 }
125
126 void IGESDraw_ToolDrawingWithRotation::WriteOwnParams
127   (const Handle(IGESDraw_DrawingWithRotation)& ent, IGESData_IGESWriter& IW)  const
128
129   Standard_Integer Up  = ent->NbViews();
130   IW.Send( Up );
131   Standard_Integer i; // svv Jan 10 2000 : porting on DEC
132   for ( i = 1; i <= Up; i++)
133     {
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) );
138     }
139
140   Up  = ent->NbAnnotations();
141   IW.Send( Up );
142   for ( i = 1; i <= Up; i++)
143     IW.Send( ent->Annotation(i) );
144 }
145
146 void  IGESDraw_ToolDrawingWithRotation::OwnShared
147   (const Handle(IGESDraw_DrawingWithRotation)& ent, Interface_EntityIterator& iter) const
148 {
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) );
156 }
157
158 void IGESDraw_ToolDrawingWithRotation::OwnCopy
159   (const Handle(IGESDraw_DrawingWithRotation)& another,
160    const Handle(IGESDraw_DrawingWithRotation)& ent, Interface_CopyTool& TC) const
161 {
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;
168  
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);
174  
175   if ( nbanot > 0 )
176     {
177       annotations = new IGESData_HArray1OfIGESEntity(1, nbanot);
178       for (Standard_Integer i = 1; i <= nbanot; i++)
179         {
180           DeclareAndCast(IGESData_IGESEntity, tempAnnotation, 
181                          TC.Transferred(another->Annotation(i)));
182           annotations->SetValue( i, tempAnnotation );
183         }
184     }
185  
186   for (Standard_Integer i = 1; i <= nbval; i++)
187     {
188       DeclareAndCast(IGESData_ViewKindEntity, tempView,
189                      TC.Transferred(another->ViewItem(i)));
190       views->SetValue( i, tempView );
191  
192       viewOrigins->SetValue( i, (another->ViewOrigin(i)).XY() );
193  
194       orientationAngles->SetValue( i, another->OrientationAngle(i) );
195     }
196
197   ent->Init(views, viewOrigins,orientationAngles, annotations);
198 }
199
200 Standard_Boolean IGESDraw_ToolDrawingWithRotation::OwnCorrect
201   (const Handle(IGESDraw_DrawingWithRotation)& ent )  const
202 {
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 --;
210   }
211   if (nbtrue == nb) return Standard_False;
212   Handle(IGESDraw_HArray1OfViewKindEntity)  views;
213   Handle(TColgp_HArray1OfXY)                viewOrigins; 
214   Handle(TColStd_HArray1OfReal)             orientationAngles;
215   if (nbtrue > 0) {
216     views = new IGESDraw_HArray1OfViewKindEntity (1, nbtrue);
217     viewOrigins = new TColgp_HArray1OfXY(1, nbtrue);
218     orientationAngles = new TColStd_HArray1OfReal(1, nbtrue);
219   }
220   nbtrue = 0;
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;
225     nbtrue ++;
226     views->SetValue (nbtrue,val);
227     viewOrigins->SetValue (nbtrue, ent->ViewOrigin(i).XY() );
228     orientationAngles->SetValue (nbtrue,ent->OrientationAngle(i));
229   }
230
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));
236
237   ent->Init(views, viewOrigins,orientationAngles, annotations);
238   return Standard_True;
239 }
240
241 IGESData_DirChecker IGESDraw_ToolDrawingWithRotation::DirChecker
242   (const Handle(IGESDraw_DrawingWithRotation)& /*ent*/)  const
243
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();
253   return DC;
254 }
255
256 void IGESDraw_ToolDrawingWithRotation::OwnCheck
257   (const Handle(IGESDraw_DrawingWithRotation)& ent,
258    const Interface_ShareTool& , Handle(Interface_Check)& ach)  const
259 {
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;
266     if (ianul) {
267       ach->AddWarning ("At least one View is Null");
268       break;
269     }
270   }
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;
276     if (ianul) {
277       ach->AddWarning ("At least one Annotation is Null");
278       break;
279     }
280   }
281 }
282
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
286 {
287   Standard_Integer sublevel = (level <= 4) ? 0 : 1;
288
289   S << "IGESDraw_DrawingWithRotation" << endl;
290
291   S << "View Entities            : " << endl
292     << "Transformed View Origins : " << endl
293     << "Orientation Angles : ";
294   S << "Count = "      << ent->NbViews() << endl;
295
296   if (level > 4)    // Level = 4 : no Dump. Level = 5 & 6 have same Dump
297     {
298       Standard_Integer I;
299       Standard_Integer up  = ent->NbViews();
300       for (I = 1; I <= up; I++)
301         {
302           S << "[" << I << "]:" << endl;
303           S << "View Entity : ";
304           dumper.Dump (ent->ViewItem(I),S, sublevel);
305           S << endl;
306           S << "Transformed View Origin : ";
307           IGESData_DumpXY(S, ent->ViewOrigin(I));
308           S << "  Orientation Angle : " << ent->OrientationAngle(I) << endl;
309         }
310     }
311   S << "Annotation Entities : ";
312   IGESData_DumpEntities(S,dumper ,level,1, ent->NbAnnotations(),ent->Annotation);
313   S << endl;
314 }