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