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