0032961: Coding - get rid of unused headers [IGESAppli to IGESToBRep]
[occt.git] / src / IGESGraph / IGESGraph_ToolTextFontDef.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_GTrsf.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <gp_XY.hxx>
22 #include <IGESBasic_HArray1OfHArray1OfInteger.hxx>
23 #include <IGESData_DirChecker.hxx>
24 #include <IGESData_Dump.hxx>
25 #include <IGESData_IGESDumper.hxx>
26 #include <IGESData_IGESReaderData.hxx>
27 #include <IGESData_IGESWriter.hxx>
28 #include <IGESData_ParamReader.hxx>
29 #include <IGESGraph_TextFontDef.hxx>
30 #include <IGESGraph_ToolTextFontDef.hxx>
31 #include <Interface_Check.hxx>
32 #include <Interface_CopyTool.hxx>
33 #include <Interface_EntityIterator.hxx>
34 #include <Interface_ShareTool.hxx>
35 #include <Message_Messenger.hxx>
36 #include <Standard_DomainError.hxx>
37 #include <TColgp_HArray1OfXY.hxx>
38 #include <TCollection_HAsciiString.hxx>
39 #include <TColStd_HArray1OfInteger.hxx>
40
41 IGESGraph_ToolTextFontDef::IGESGraph_ToolTextFontDef ()    {  }
42
43
44 void IGESGraph_ToolTextFontDef::ReadOwnParams
45   (const Handle(IGESGraph_TextFontDef)& ent,
46    const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
47
48   //Standard_Boolean                            st; //szv#4:S4163:12Mar99 moved down
49   Standard_Integer                            nbval;
50
51   Standard_Integer                            fontCode;
52   Handle(TCollection_HAsciiString)            fontName;
53   Standard_Integer                            supersededFont;
54   Handle(IGESGraph_TextFontDef)               supersededEntity;
55   Standard_Integer                            scale;
56   Handle(TColStd_HArray1OfInteger)            aSCIICodes;
57   Handle(TColStd_HArray1OfInteger)            nextCharX, nextCharY;
58   Handle(TColStd_HArray1OfInteger)            penMotions;
59   Handle(IGESBasic_HArray1OfHArray1OfInteger) penFlags;
60   Handle(IGESBasic_HArray1OfHArray1OfInteger) movePenX, movePenY;
61
62   Standard_Integer                            tempCode, tempNextX,tempNextY;
63   Standard_Integer                            tempMotion;
64   Standard_Integer                            tempFlag, tempMoveX,tempMoveY;
65
66   // Reading fontCode(Integer)
67   PR.ReadInteger (PR.Current(), "Font Code", fontCode); //szv#4:S4163:12Mar99 `st=` not needed
68
69   // Reading fontName(String)
70   PR.ReadText (PR.Current(), "Font Name", fontName); //szv#4:S4163:12Mar99 `st=` not needed
71
72   if ( PR.IsParamEntity(PR.CurrentNumber()) )
73     {
74       supersededFont = -1;
75
76       // Reading supersededEntity(TextFontDef)
77       PR.ReadEntity (IR, PR.Current(), "Text Definition Entity",
78                      STANDARD_TYPE(IGESGraph_TextFontDef), supersededEntity); //szv#4:S4163:12Mar99 `st=` not needed
79     }
80   else
81     // Reading supersededFont(Integer)
82     PR.ReadInteger(PR.Current(), "No. of superseded font", supersededFont); //szv#4:S4163:12Mar99 `st=` not needed
83
84   // Reading scale(Integer)
85   PR.ReadInteger(PR.Current(), "Grid units eqvt to one text height", scale); //szv#4:S4163:12Mar99 `st=` not needed
86
87   // Reading nbval(Integer)
88   Standard_Boolean st = PR.ReadInteger(PR.Current(), "No. of characters in this defn", nbval);
89   if (st && nbval > 0)
90     {
91       aSCIICodes = new TColStd_HArray1OfInteger(1, nbval);
92       nextCharX  = new TColStd_HArray1OfInteger(1, nbval);
93       nextCharY  = new TColStd_HArray1OfInteger(1, nbval);
94       penMotions = new TColStd_HArray1OfInteger(1, nbval);
95       penFlags   = new IGESBasic_HArray1OfHArray1OfInteger(1, nbval);
96       movePenX   = new IGESBasic_HArray1OfHArray1OfInteger(1, nbval);
97       movePenY   = new IGESBasic_HArray1OfHArray1OfInteger(1, nbval);
98       
99       for ( Standard_Integer i = 1; i <= nbval; i++ )
100         {
101           // Reading aSCIICodes(HArray1OfInteger)
102           if (PR.ReadInteger(PR.Current(), "array aSCIICodes", tempCode)) //szv#4:S4163:12Mar99 `st=` not needed
103             aSCIICodes->SetValue(i, tempCode);
104           
105           // Reading nextChars(HArray1OfInteger*2)
106           if (PR.ReadInteger(PR.Current(), "array nextChar X", tempNextX)) //szv#4:S4163:12Mar99 `st=` not needed
107             nextCharX->SetValue(i, tempNextX);
108           if (PR.ReadInteger(PR.Current(), "array nextChar Y", tempNextY)) //szv#4:S4163:12Mar99 `st=` not needed
109             nextCharY->SetValue(i, tempNextY);
110           
111           // Reading penMotions(HArray1OfInteger)
112           if (PR.ReadInteger(PR.Current(), "array penMotions", tempMotion)) { //szv#4:S4163:12Mar99 `st=` not needed
113             penMotions->SetValue(i, tempMotion);
114             if (tempMotion > 0) {
115               Handle(TColStd_HArray1OfInteger) intarray, xarray, yarray;
116
117               intarray = new TColStd_HArray1OfInteger(1, tempMotion);
118               xarray   = new TColStd_HArray1OfInteger(1, tempMotion);
119               yarray   = new TColStd_HArray1OfInteger(1, tempMotion);
120               
121               for ( Standard_Integer j = 1; j <= tempMotion; j++ )  {
122                 if (PR.DefinedElseSkip()) {
123                   // Reading penFlags(HArray1OfHArray1OfInteger)
124                   if (PR.ReadInteger(PR.Current(), "array penFlags", tempFlag)) //szv#4:S4163:12Mar99 `st=` not needed
125                     intarray->SetValue(j, tempFlag);
126                 }
127                 else  intarray->SetValue(j, 0); // Default Value
128                   
129                 // Reading movePenTo(HArray1OfHArray1OfInteger*2)
130                 if (PR.ReadInteger(PR.Current(), "array movePenTo X", tempMoveX)) //szv#4:S4163:12Mar99 `st=` not needed
131                   xarray->SetValue(j, tempMoveX);
132                 if (PR.ReadInteger(PR.Current(), "array movePenTo Y", tempMoveY)) //szv#4:S4163:12Mar99 `st=` not needed
133                   yarray->SetValue(j, tempMoveY);
134               }
135               penFlags->SetValue(i, intarray);
136               movePenX->SetValue(i, xarray);
137               movePenY->SetValue(i, yarray);
138
139             }
140             else  PR.AddFail("Count of Pen motions : Not Positive");
141           }
142         }
143     }
144   else  PR.AddFail ("Count of characters in this defn : Not Positive");
145
146   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
147   ent->Init
148     (fontCode, fontName, supersededFont, supersededEntity,
149      scale, aSCIICodes, nextCharX, nextCharY,
150      penMotions, penFlags, movePenX, movePenY);
151 }
152
153 void IGESGraph_ToolTextFontDef::WriteOwnParams
154   (const Handle(IGESGraph_TextFontDef)& ent, IGESData_IGESWriter& IW)  const
155 {
156   Standard_Integer IX,IY;
157   IW.Send( ent->FontCode() );
158   IW.Send( ent->FontName() );
159
160   if ( ent->IsSupersededFontEntity() ) 
161     IW.Send( ent->SupersededFontEntity(), Standard_True );  // negative
162   else
163     IW.Send( ent->SupersededFontCode() );
164
165   IW.Send( ent->Scale() );
166
167   Standard_Integer Up  = ent->NbCharacters();
168   IW.Send( Up );
169   for ( Standard_Integer i = 1; i <= Up; i++)
170     {
171       IW.Send( ent->ASCIICode(i) );
172       ent->NextCharOrigin (i,IX,IY);
173       IW.Send( IX );
174       IW.Send( IY );
175       IW.Send( ent->NbPenMotions(i) );
176       for ( Standard_Integer j = 1; j <= ent->NbPenMotions(i); j ++)
177         {
178           IW.SendBoolean( ent->IsPenUp(i,j) );
179           ent->NextPenPosition (i,j, IX,IY);
180           IW.Send( IX );
181           IW.Send( IY );
182         }
183     }
184
185  
186 void  IGESGraph_ToolTextFontDef::OwnShared
187   (const Handle(IGESGraph_TextFontDef)& ent, Interface_EntityIterator& iter) const
188 {
189   if ( ent->IsSupersededFontEntity() ) 
190     iter.GetOneItem( ent->SupersededFontEntity() );
191 }
192
193 void IGESGraph_ToolTextFontDef::OwnCopy
194   (const Handle(IGESGraph_TextFontDef)& another,
195    const Handle(IGESGraph_TextFontDef)& ent, Interface_CopyTool& TC) const
196 {
197   Standard_Integer                            nbval;
198   Standard_Integer                            fontCode;
199   Handle(TCollection_HAsciiString)            fontName;
200   Standard_Integer                            supersededFont=0;
201   Handle(IGESGraph_TextFontDef)               supersededEntity;
202   Standard_Integer                            scale;
203   Handle(TColStd_HArray1OfInteger)            aSCIICodes, nextCharX,nextCharY;
204   Handle(TColStd_HArray1OfInteger)            penMotions;
205   Handle(IGESBasic_HArray1OfHArray1OfInteger) penFlags,movePenX,movePenY;
206
207   Standard_Integer                            tempMotion;
208   Handle(TColStd_HArray1OfInteger)            intarray,xarray,yarray;
209  
210   nbval       = another->NbCharacters();
211   aSCIICodes  = new TColStd_HArray1OfInteger(1, nbval);
212   nextCharX   = new TColStd_HArray1OfInteger(1, nbval);
213   nextCharY   = new TColStd_HArray1OfInteger(1, nbval);
214   penMotions  = new TColStd_HArray1OfInteger(1, nbval);
215   penFlags    = new IGESBasic_HArray1OfHArray1OfInteger(1, nbval);
216   movePenX    = new IGESBasic_HArray1OfHArray1OfInteger(1, nbval);
217   movePenY    = new IGESBasic_HArray1OfHArray1OfInteger(1, nbval);
218
219   fontCode = another->FontCode();
220   fontName = new TCollection_HAsciiString(another->FontName());
221
222   if ( another->IsSupersededFontEntity() )
223     supersededEntity = 
224       Handle(IGESGraph_TextFontDef)::DownCast (TC.Transferred(another->SupersededFontEntity()));
225   else
226     supersededFont = another->SupersededFontCode();
227
228   scale = another->Scale();
229
230   Standard_Integer j, IX,IY;
231
232   for (Standard_Integer i = 1; i <= nbval; i++)
233     {
234       aSCIICodes->SetValue( i, another->ASCIICode(i) );
235       ent->NextCharOrigin (i,IX,IY);
236       nextCharX->SetValue ( i, IX);
237       nextCharY->SetValue ( i, IY);
238
239       tempMotion = another->NbPenMotions(i);
240       penMotions->SetValue( i, tempMotion );
241
242       intarray = new TColStd_HArray1OfInteger(1, tempMotion);
243       xarray   = new TColStd_HArray1OfInteger(1, tempMotion);
244       yarray   = new TColStd_HArray1OfInteger(1, tempMotion);
245
246       for (j = 1; j <= tempMotion; j++)
247         {
248           if ( another->IsPenUp(i, j) ) intarray->SetValue(j, 1);
249           else                          intarray->SetValue(j, 0);
250
251           another->NextPenPosition(i, j, IX,IY);
252           xarray->SetValue(j, IX);
253           yarray->SetValue(j, IY);
254         }
255       penFlags->SetValue(i, intarray);
256       movePenX->SetValue(i, xarray);
257       movePenY->SetValue(i, yarray);
258     }
259
260   ent->Init(fontCode, fontName, supersededFont, supersededEntity,
261             scale, aSCIICodes, nextCharX, nextCharY, penMotions,
262             penFlags, movePenX, movePenY);
263 }
264
265 IGESData_DirChecker IGESGraph_ToolTextFontDef::DirChecker
266   (const Handle(IGESGraph_TextFontDef)& /*ent*/)  const
267
268   IGESData_DirChecker DC (310, 0);
269   DC.Structure(IGESData_DefVoid);
270   DC.LineFont(IGESData_DefVoid);
271   DC.LineWeight(IGESData_DefVoid);
272   DC.Color(IGESData_DefVoid);
273   DC.BlankStatusIgnored();
274   DC.SubordinateStatusRequired(0);
275   DC.UseFlagRequired(2);
276   DC.HierarchyStatusIgnored();
277   return DC;
278 }
279
280 void IGESGraph_ToolTextFontDef::OwnCheck
281   (const Handle(IGESGraph_TextFontDef)& /*ent*/,
282    const Interface_ShareTool& , Handle(Interface_Check)& /*ach*/)  const
283 {
284 }
285
286 void IGESGraph_ToolTextFontDef::OwnDump
287   (const Handle(IGESGraph_TextFontDef)& ent, const IGESData_IGESDumper& dumper,
288    Standard_OStream& S, const Standard_Integer level)  const
289 {
290   Standard_Integer sublevel = (level <= 4) ? 0 : 1;
291   Standard_Integer nbchars  = ent->NbCharacters();
292
293   S << "IGESGraph_TextFontDef\n"
294     << "Font Code : " << ent->FontCode() << "\n"
295     << "Font Name : ";
296   IGESData_DumpString(S,ent->FontName());
297   S << "\n";
298   if ( ent->IsSupersededFontEntity() ) {
299     S << "Text Definition Entity : ";
300     dumper.Dump(ent->SupersededFontEntity(),S, sublevel);
301   }
302   else  S << "Superseding Font Number : " << ent->SupersededFontCode();
303   S << "\n"
304     << "No. of Grid Units eqvt to 1 Text Height : " << ent->Scale() << "\n"
305     << "ASCII Codes                              :\n"
306     << "Grid Locations of next character origins :\n"
307     << "Pen Motions                              :\n"
308     << "Pen Positions                            :\n"
309     << "Grid Locations the pen moves to          : "
310     << "Count = "      << nbchars << "\n";
311   IGESData_DumpVals(S,-level,1,nbchars,ent->ASCIICode);
312   S << "\n";
313   if (level > 4 )
314     {
315       Handle(TColgp_HArray1OfXY) arrXY;
316       Standard_Integer I, J, nbmotions;
317       for (I = 1; I <= nbchars; I++)
318         {
319           Standard_Integer IX,IY;
320           S << "[" << I << "]: "
321             << "ASCII Code : " << ent->ASCIICode(I) << "\n"
322             << "Grid Location of next character's origin : ";
323           ent->NextCharOrigin(I,IX,IY);
324           S << "X=" << IX << " Y=" << IY;
325           nbmotions = ent->NbPenMotions(I);
326           S << "  No. of Pen Motions : " << nbmotions;
327           if (level <= 5) S << " [ ask level > 5 for Details ]\n";
328           else {
329             S << "\n";
330             for (J = 1; J <= nbmotions; J++)
331               {
332                 S << "Pen up(1) / down(0) flag : " << (Standard_Integer)ent->IsPenUp(I,J)
333                   << " Next Pen Position : ";
334                 ent->NextPenPosition(I,J, IX,IY);
335                 S << " X="<<IX<<" Y="<<IY << "\n";
336               }
337           }
338         }
339     }
340   S << std::endl;
341 }