Warnings on vc14 were eliminated
[occt.git] / src / IGESDraw / IGESDraw_ToolLabelDisplay.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_XYZ.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_ParamCursor.hxx>
28 #include <IGESData_ParamReader.hxx>
29 #include <IGESData_ViewKindEntity.hxx>
30 #include <IGESDimen_HArray1OfLeaderArrow.hxx>
31 #include <IGESDimen_LeaderArrow.hxx>
32 #include <IGESDraw_HArray1OfViewKindEntity.hxx>
33 #include <IGESDraw_LabelDisplay.hxx>
34 #include <IGESDraw_PerspectiveView.hxx>
35 #include <IGESDraw_ToolLabelDisplay.hxx>
36 #include <IGESDraw_View.hxx>
37 #include <Interface_Check.hxx>
38 #include <Interface_CopyTool.hxx>
39 #include <Interface_EntityIterator.hxx>
40 #include <Interface_Macros.hxx>
41 #include <Interface_ShareTool.hxx>
42 #include <Message_Messenger.hxx>
43 #include <Standard_DomainError.hxx>
44 #include <TColgp_HArray1OfXYZ.hxx>
45 #include <TColStd_HArray1OfInteger.hxx>
46
47 IGESDraw_ToolLabelDisplay::IGESDraw_ToolLabelDisplay ()    {  }
48
49
50 void IGESDraw_ToolLabelDisplay::ReadOwnParams
51   (const Handle(IGESDraw_LabelDisplay)& ent,
52    const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
53
54   //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
55   Standard_Integer nbval;
56
57   Handle(IGESDraw_HArray1OfViewKindEntity) views; 
58   Handle(TColgp_HArray1OfXYZ)                   textLocations; 
59   Handle(IGESDimen_HArray1OfLeaderArrow)    leaderEntities; 
60   Handle(TColStd_HArray1OfInteger)       labelLevels;
61   Handle(IGESData_HArray1OfIGESEntity)     displayedEntities; 
62
63   // Reading nbval(No. of Label placements)
64   Standard_Boolean st = PR.ReadInteger(PR.Current(), "No. of Label placements", nbval);
65   if (st && nbval > 0)
66     {
67       views             = new IGESDraw_HArray1OfViewKindEntity(1, nbval);
68       textLocations     = new TColgp_HArray1OfXYZ(1, nbval);
69       leaderEntities    = new IGESDimen_HArray1OfLeaderArrow(1, nbval);
70       labelLevels       = new TColStd_HArray1OfInteger(1, nbval);
71       displayedEntities = new IGESData_HArray1OfIGESEntity(1, nbval);
72       
73       Handle(IGESData_ViewKindEntity) tempView;
74       gp_XYZ                          tempXYZ;
75       Handle(IGESDimen_LeaderArrow)   tempLeaderArrow;
76       Standard_Integer                tempLabel;
77       Handle(IGESData_IGESEntity)     tempDisplayedEntity;
78       
79       for (Standard_Integer i = 1; i <= nbval; i++)
80         {
81           // Reading views(HArray1OfView)
82           //st = PR.ReadEntity (IR, PR.Current(), "Instance of views",
83                                 //STANDARD_TYPE(IGESData_ViewKindEntity), tempView); //szv#4:S4163:12Mar99 moved in if
84           if (PR.ReadEntity (IR, PR.Current(), "Instance of views",
85                              STANDARD_TYPE(IGESData_ViewKindEntity), tempView))
86             views->SetValue(i, tempView);
87           
88           // Reading textLocations(HArray1OfXYZ)
89           //st = PR.ReadXYZ(PR.CurrentList(1, 3), "array textLocations", tempXYZ); //szv#4:S4163:12Mar99 moved in if
90           if (PR.ReadXYZ(PR.CurrentList(1, 3), "array textLocations", tempXYZ))
91             textLocations->SetValue(i, tempXYZ);
92
93           // Reading leaderEntities(HArray1OfLeaderArrow)
94           //st = PR.ReadEntity (IR, PR.Current(), "Instance of LeaderArrow",
95                                 //STANDARD_TYPE(IGESDimen_LeaderArrow), tempLeaderArrow); //szv#4:S4163:12Mar99 moved in if
96           if (PR.ReadEntity (IR, PR.Current(), "Instance of LeaderArrow",
97                              STANDARD_TYPE(IGESDimen_LeaderArrow), tempLeaderArrow))
98             leaderEntities->SetValue(i, tempLeaderArrow);
99           
100           // Reading labelLevels(HArray1OfInteger)
101           //st = PR.ReadInteger(PR.Current(), "array labelLevels", tempLabel); //szv#4:S4163:12Mar99 moved in if
102           if (PR.ReadInteger(PR.Current(), "array labelLevels", tempLabel))
103             labelLevels->SetValue(i, tempLabel);
104           
105           // Reading displayedEntities(HArray1OfIGESEntity)
106           //st = PR.ReadEntity (IR, PR.Current(), "displayedEntities entity",
107                                 //tempDisplayedEntity); //szv#4:S4163:12Mar99 moved in if
108           if (PR.ReadEntity (IR, PR.Current(), "displayedEntities entity", tempDisplayedEntity))
109             displayedEntities->SetValue(i, tempDisplayedEntity);
110         }
111     }
112   else  PR.AddFail("No. of Label placements : Not Positive");
113
114   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
115   ent->Init
116     (views, textLocations, leaderEntities, labelLevels, displayedEntities);
117 }
118
119 void IGESDraw_ToolLabelDisplay::WriteOwnParams
120   (const Handle(IGESDraw_LabelDisplay)& ent, IGESData_IGESWriter& IW)  const
121 {
122   Standard_Integer Up  = ent->NbLabels();
123   IW.Send( Up );
124   for ( Standard_Integer i = 1; i <= Up; i++)
125     {
126       IW.Send( ent->ViewItem(i) );
127       IW.Send( (ent->TextLocation(i)).X() );
128       IW.Send( (ent->TextLocation(i)).Y() );
129       IW.Send( (ent->TextLocation(i)).Z() );
130       IW.Send( ent->LeaderEntity(i) );
131       IW.Send( ent->LabelLevel(i) );
132       IW.Send( ent->DisplayedEntity(i) );
133     }
134 }
135
136 void  IGESDraw_ToolLabelDisplay::OwnShared
137   (const Handle(IGESDraw_LabelDisplay)& ent, Interface_EntityIterator& iter) const
138 {
139   Standard_Integer Up  = ent->NbLabels();
140   for ( Standard_Integer i = 1; i <= Up; i++)
141     {
142       iter.GetOneItem( ent->ViewItem(i) );
143       iter.GetOneItem( ent->LeaderEntity(i) );
144       iter.GetOneItem( ent->DisplayedEntity(i) );
145     }
146 }
147
148 void IGESDraw_ToolLabelDisplay::OwnCopy
149   (const Handle(IGESDraw_LabelDisplay)& another,
150    const Handle(IGESDraw_LabelDisplay)& ent, Interface_CopyTool& TC) const
151 {
152   Standard_Integer                              nbval;
153   Handle(IGESDraw_HArray1OfViewKindEntity) views;
154   Handle(TColgp_HArray1OfXYZ)                   textLocations;
155   Handle(IGESDimen_HArray1OfLeaderArrow)    leaderEntities;
156   Handle(TColStd_HArray1OfInteger)       labelLevels;
157   Handle(IGESData_HArray1OfIGESEntity)     displayedEntities;
158  
159   nbval             = another->NbLabels();
160   views             = new IGESDraw_HArray1OfViewKindEntity(1, nbval);
161   textLocations     = new TColgp_HArray1OfXYZ(1, nbval);
162   leaderEntities    = new IGESDimen_HArray1OfLeaderArrow(1, nbval);
163   labelLevels       = new TColStd_HArray1OfInteger(1, nbval);
164   displayedEntities = new IGESData_HArray1OfIGESEntity(1, nbval);
165  
166   for (Standard_Integer i = 1; i <= nbval; i++)
167     {
168       DeclareAndCast(IGESData_ViewKindEntity, tempView,
169                      TC.Transferred(another->ViewItem(i)));
170       views->SetValue( i, tempView );
171  
172       textLocations->SetValue( i, (another->TextLocation(i)).XYZ() );
173  
174       DeclareAndCast(IGESDimen_LeaderArrow, tempArrow, 
175                      TC.Transferred(another->LeaderEntity(i)));
176       leaderEntities->SetValue( i, tempArrow );
177  
178       labelLevels->SetValue( i, another->LabelLevel(i) );
179  
180       DeclareAndCast(IGESData_IGESEntity, tempEntity, 
181                      TC.Transferred(another->DisplayedEntity(i)));
182       displayedEntities->SetValue( i, tempEntity );
183     }
184
185   ent->Init(views, textLocations, leaderEntities, 
186             labelLevels, displayedEntities);
187 }
188
189 IGESData_DirChecker IGESDraw_ToolLabelDisplay::DirChecker
190   (const Handle(IGESDraw_LabelDisplay)& /*ent*/)  const
191
192   IGESData_DirChecker DC (402, 5);
193   DC.Structure(IGESData_DefVoid);
194   DC.HierarchyStatusIgnored();
195   DC.BlankStatusIgnored();
196   return DC;
197 }
198
199 void IGESDraw_ToolLabelDisplay::OwnCheck
200   (const Handle(IGESDraw_LabelDisplay)& /*ent*/,
201    const Interface_ShareTool& , Handle(Interface_Check)& /*ach*/)  const
202 {
203 }
204
205 void IGESDraw_ToolLabelDisplay::OwnDump
206   (const Handle(IGESDraw_LabelDisplay)& ent, const IGESData_IGESDumper& dumper,
207    const Handle(Message_Messenger)& S, const Standard_Integer level)  const
208 {
209   Standard_Integer sublevel = (level <= 4) ? 0 : 1;
210
211   S << "IGESDraw_LabelDisplay" << endl;
212
213   S << "View Entities       : " << endl
214     << "Text Locations      : " << endl
215     << "Leader Entities     : " << endl
216     << "Label Level Numbers : " << endl
217     << "Displayed Entities  : ";
218   S << "Count = "      << ent->NbLabels() << endl;
219   if (level > 4)  // Level = 4 : no Dump. Level = 5 & 6 : same Dump
220     {
221       Standard_Integer I;
222       Standard_Integer up  = ent->NbLabels();
223       for (I = 1; I <= up; I ++)
224         {
225           S << "[" << I << "]:" << endl;
226           S << "View Entity : ";
227           dumper.Dump (ent->ViewItem(I),S, sublevel);
228           S << endl;
229           S << "Text Location in View : ";
230           IGESData_DumpXYZL(S,level, ent->TextLocation(I), ent->Location());
231           S << "  Leader Entity in View : ";
232           dumper.Dump (ent->LeaderEntity(I),S, sublevel);
233           S << endl;
234           S << "Entity Label Level Number : ";
235           S << ent->LabelLevel(I) << "  ";
236           S << "Displayed Entity : ";
237           dumper.Dump (ent->DisplayedEntity(I),S, sublevel);
238           S << endl;
239         }
240     }
241   S << endl;
242 }