0024428: Implementation of LGPL license
[occt.git] / src / IGESAppli / IGESAppli_ToolFlow.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
8 // under the terms of the GNU Lesser General Public 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 <IGESAppli_ToolFlow.ixx>
20 #include <IGESData_ParamCursor.hxx>
21 #include <IGESGraph_TextDisplayTemplate.hxx>
22 #include <TCollection_HAsciiString.hxx>
23 #include <IGESData_IGESEntity.hxx>
24 #include <IGESDraw_ConnectPoint.hxx>
25 #include <IGESDraw_HArray1OfConnectPoint.hxx>
26 #include <Interface_HArray1OfHAsciiString.hxx>
27 #include <IGESGraph_HArray1OfTextDisplayTemplate.hxx>
28 #include <IGESData_HArray1OfIGESEntity.hxx>
29 #include <IGESData_Dump.hxx>
30 #include <Interface_Macros.hxx>
31
32
33 IGESAppli_ToolFlow::IGESAppli_ToolFlow ()    {  }
34
35
36 void  IGESAppli_ToolFlow::ReadOwnParams
37   (const Handle(IGESAppli_Flow)& ent,
38    const Handle(IGESData_IGESReaderData)& IR, IGESData_ParamReader& PR) const
39 {
40   //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
41   Standard_Integer tempNbContextFlags;
42   Standard_Integer tempTypeOfFlow;
43   Standard_Integer tempFunctionFlag;
44   Standard_Integer i, nf,nc,nj,nn,nt,np;
45   Handle(IGESData_HArray1OfIGESEntity) tempFlowAssocs;
46   Handle(IGESDraw_HArray1OfConnectPoint) tempConnectPoints;
47   Handle(IGESData_HArray1OfIGESEntity) tempJoins;
48   Handle(Interface_HArray1OfHAsciiString) tempFlowNames;
49   Handle(IGESGraph_HArray1OfTextDisplayTemplate) tempTextDisplayTemplates;
50   Handle(IGESData_HArray1OfIGESEntity) tempContFlowAssocs;
51
52   //szv#4:S4163:12Mar99 `st=` not needed
53   if (PR.DefinedElseSkip())
54     PR.ReadInteger(PR.Current(), "Number of Context Flags", tempNbContextFlags);
55   else
56     tempNbContextFlags = 2;
57
58   //szv#4:S4163:12Mar99 moved in if
59   if (!PR.ReadInteger(PR.Current(), "Number of Flow Associativities", nf)) nf = 0;
60   if (nf > 0)  tempFlowAssocs     =  new IGESData_HArray1OfIGESEntity(1, nf);
61   else  PR.AddFail ("Number of Flow Associativities: Not Positive");
62
63   if (!PR.ReadInteger(PR.Current(), "Number of Connect Points", nc)) nc = 0;
64   if (nc > 0)  tempConnectPoints  = new IGESDraw_HArray1OfConnectPoint(1, nc);
65   else  PR.AddFail("Number of Connect Points: Not Positive");
66
67   if (!PR.ReadInteger(PR.Current(), "Number of Joins", nj)) nj = 0;
68   if (nj > 0)  tempJoins          = new IGESData_HArray1OfIGESEntity(1, nj);
69   else  PR.AddFail("Number of Joins: Not Positive");
70
71   if (!PR.ReadInteger(PR.Current(), "Number of Flow Names", nn)) nn = 0;
72   if (nn > 0)  tempFlowNames      = new Interface_HArray1OfHAsciiString(1, nn);
73   else  PR.AddFail("Number of Flow Names: Not Positive");
74
75   if (!PR.ReadInteger(PR.Current(), "Number of Text Displays", nt)) nt = 0;
76   if (nt > 0)  tempTextDisplayTemplates =
77     new IGESGraph_HArray1OfTextDisplayTemplate(1, nt);
78   else PR.AddFail("Number of Text Displays: Not Positive");
79
80   if (!PR.ReadInteger(PR.Current(), "Number of Continuation Flows", np)) np = 0;
81   if (np > 0)  tempContFlowAssocs = new IGESData_HArray1OfIGESEntity(1, np);
82   else PR.AddFail("Number of Continuation Flows Not Positive");
83
84   if (PR.DefinedElseSkip())
85     PR.ReadInteger(PR.Current(), "Type of Flow", tempTypeOfFlow);
86   else
87     tempTypeOfFlow = 0;
88
89   if (PR.DefinedElseSkip())
90     PR.ReadInteger(PR.Current(), "Function Flag", tempFunctionFlag);
91   else
92     tempFunctionFlag = 0;
93
94   for ( i = 1; i <= nf; i++ ) {
95     Handle(IGESData_IGESEntity) tempEntity;
96     if (PR.ReadEntity(IR, PR.Current(), "Flow Associativity", tempEntity))
97       tempFlowAssocs->SetValue(i, tempEntity);
98   }
99
100   for ( i = 1; i <= nc; i++ ) {
101     Handle(IGESDraw_ConnectPoint) tempEntity;
102     if (PR.ReadEntity(IR, PR.Current(), "Connect Point", STANDARD_TYPE(IGESDraw_ConnectPoint), tempEntity))
103       tempConnectPoints->SetValue(i, tempEntity);
104   }
105
106   for ( i = 1; i <= nj; i++ ) {
107     Handle(IGESData_IGESEntity) tempEntity;
108     if (PR.ReadEntity(IR, PR.Current(), "Join", tempEntity))
109       tempJoins->SetValue(i, tempEntity);
110   }
111
112   for ( i = 1; i <= nn; i++ ) {
113     Handle(TCollection_HAsciiString) tempString;
114     if (PR.ReadText(PR.Current(), "Flow Name", tempString))
115       tempFlowNames->SetValue(i, tempString);
116   }
117
118   for ( i = 1; i <= nt; i++ ) {
119     Handle(IGESGraph_TextDisplayTemplate) tempEntity;
120     if (PR.ReadEntity(IR, PR.Current(), "Text Display Template",
121                       STANDARD_TYPE(IGESGraph_TextDisplayTemplate), tempEntity))
122       tempTextDisplayTemplates->SetValue(i, tempEntity);
123   }
124
125   for ( i = 1; i <= np; i++ ) {
126     Handle(IGESData_IGESEntity) tempEntity;
127     if (PR.ReadEntity(IR, PR.Current(), "Continuation Flow Associativities", tempEntity))
128       tempContFlowAssocs->SetValue(i, tempEntity);
129   }
130
131   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
132   ent->Init(tempNbContextFlags, tempTypeOfFlow, tempFunctionFlag,
133             tempFlowAssocs, tempConnectPoints, tempJoins, tempFlowNames,
134             tempTextDisplayTemplates, tempContFlowAssocs);
135 }
136
137 void  IGESAppli_ToolFlow::WriteOwnParams
138   (const Handle(IGESAppli_Flow)& ent, IGESData_IGESWriter& IW) const
139 {
140   Standard_Integer i, num;
141   IW.Send(ent->NbContextFlags());
142   IW.Send(ent->NbFlowAssociativities());
143   IW.Send(ent->NbConnectPoints());
144   IW.Send(ent->NbJoins());
145   IW.Send(ent->NbFlowNames());
146   IW.Send(ent->NbTextDisplayTemplates());
147   IW.Send(ent->NbContFlowAssociativities());
148   IW.Send(ent->TypeOfFlow());
149   IW.Send(ent->FunctionFlag());
150   for ( num = ent->NbFlowAssociativities(), i = 1; i <= num; i++ )
151     IW.Send(ent->FlowAssociativity(i));
152   for ( num = ent->NbConnectPoints(), i = 1; i <= num; i++ )
153     IW.Send(ent->ConnectPoint(i));
154   for ( num = ent->NbJoins(), i = 1; i <= num; i++ )
155     IW.Send(ent->Join(i));
156   for ( num = ent->NbFlowNames(), i = 1; i <= num; i++ )
157     IW.Send(ent->FlowName(i));
158   for ( num = ent->NbTextDisplayTemplates(), i = 1; i <= num; i++ )
159     IW.Send(ent->TextDisplayTemplate(i));
160   for ( num = ent->NbContFlowAssociativities(), i = 1; i <= num; i++ )
161     IW.Send(ent->ContFlowAssociativity(i));
162 }
163
164 void  IGESAppli_ToolFlow::OwnShared
165   (const Handle(IGESAppli_Flow)& ent, Interface_EntityIterator& iter) const
166 {
167   Standard_Integer i, num;
168   for ( num = ent->NbFlowAssociativities(), i = 1; i <= num; i++ )
169     iter.GetOneItem(ent->FlowAssociativity(i));
170   for ( num = ent->NbConnectPoints(), i = 1; i <= num; i++ )
171     iter.GetOneItem(ent->ConnectPoint(i));
172   for ( num = ent->NbJoins(), i = 1; i <= num; i++ )
173     iter.GetOneItem(ent->Join(i));
174   for ( num = ent->NbTextDisplayTemplates(), i = 1; i <= num; i++ )
175     iter.GetOneItem(ent->TextDisplayTemplate(i));
176   for ( num = ent->NbContFlowAssociativities(), i = 1; i <= num; i++ )
177     iter.GetOneItem(ent->ContFlowAssociativity(i));
178 }
179
180 void  IGESAppli_ToolFlow::OwnCopy
181   (const Handle(IGESAppli_Flow)& another,
182    const Handle(IGESAppli_Flow)& ent, Interface_CopyTool& TC) const
183 {
184   Standard_Integer tempNbContextFlags = another->NbContextFlags();
185   Standard_Integer tempTypeOfFlow = another->TypeOfFlow();
186   Standard_Integer tempFunctionFlag = another->FunctionFlag();
187   Standard_Integer i, num;
188
189   num = another->NbFlowAssociativities();
190   Handle(IGESData_HArray1OfIGESEntity) tempFlowAssocs;
191   if (num > 0) tempFlowAssocs    = new IGESData_HArray1OfIGESEntity(1, num);
192   for ( i = 1; i <= num; i++ )
193     {
194       DeclareAndCast(IGESData_IGESEntity, new_item,
195                      TC.Transferred(another->FlowAssociativity(i)));
196       tempFlowAssocs->SetValue(i, new_item);
197     }
198
199   num = another->NbConnectPoints();
200   Handle(IGESDraw_HArray1OfConnectPoint) tempConnectPoints;
201   if (num > 0) tempConnectPoints = new IGESDraw_HArray1OfConnectPoint(1, num);
202   for ( i = 1; i <= num; i++ )
203     {
204       DeclareAndCast(IGESDraw_ConnectPoint, new_item,
205                      TC.Transferred(another->ConnectPoint(i)));
206       tempConnectPoints->SetValue(i, new_item);
207     }
208
209   num = another->NbJoins();
210   Handle(IGESData_HArray1OfIGESEntity) tempJoins;
211   if (num > 0) tempJoins         = new IGESData_HArray1OfIGESEntity(1, num);
212   for ( i = 1; i <= num; i++ )
213     {
214       DeclareAndCast(IGESData_IGESEntity, new_item,
215                      TC.Transferred(another->Join(i)));
216       tempJoins->SetValue(i, new_item);
217     }
218
219   num = another->NbFlowNames();
220   Handle(Interface_HArray1OfHAsciiString) tempFlowNames;
221   if (num > 0) tempFlowNames     = new Interface_HArray1OfHAsciiString(1, num);
222   for ( i = 1; i <= num; i++ )
223     tempFlowNames->SetValue
224       (i, new TCollection_HAsciiString(another->FlowName(i)));
225
226   num = another->NbTextDisplayTemplates();
227   Handle(IGESGraph_HArray1OfTextDisplayTemplate) tempTextDisplayTemplates;
228   if (num > 0) tempTextDisplayTemplates =
229     new IGESGraph_HArray1OfTextDisplayTemplate(1, num);
230   for ( i = 1; i <= num; i++ )
231     {
232       DeclareAndCast(IGESGraph_TextDisplayTemplate, new_item,
233                      TC.Transferred(another->TextDisplayTemplate(i)));
234       tempTextDisplayTemplates->SetValue(i, new_item);
235     }
236
237   num = another->NbContFlowAssociativities();
238   Handle(IGESData_HArray1OfIGESEntity) tempContFlowAssocs;
239   if (num > 0) tempContFlowAssocs = new IGESData_HArray1OfIGESEntity(1, num);
240   for ( i = 1; i <= num; i++ )
241     {
242       DeclareAndCast(IGESData_IGESEntity, new_item,
243                      TC.Transferred(another->ContFlowAssociativity(i)));
244       tempContFlowAssocs->SetValue(i, new_item);
245     }
246
247   ent->Init (tempNbContextFlags, tempTypeOfFlow, tempFunctionFlag,
248              tempFlowAssocs, tempConnectPoints, tempJoins, tempFlowNames,
249              tempTextDisplayTemplates, tempContFlowAssocs);
250 }
251
252 Standard_Boolean  IGESAppli_ToolFlow::OwnCorrect
253   (const Handle(IGESAppli_Flow)& ent) const
254 {
255   return ent->OwnCorrect();    // nbcontextflags = 2
256 }
257
258 IGESData_DirChecker  IGESAppli_ToolFlow::DirChecker
259   (const Handle(IGESAppli_Flow)& /* ent */ ) const
260 {
261   IGESData_DirChecker DC(402, 18);
262   DC.Structure(IGESData_DefVoid);
263   DC.GraphicsIgnored();
264   DC.LineFont(IGESData_DefVoid);
265   DC.LineWeight(IGESData_DefVoid);
266   DC.Color(IGESData_DefVoid);
267   DC.BlankStatusIgnored();
268   DC.UseFlagRequired(3);
269   DC.HierarchyStatusIgnored();
270   return DC;
271 }
272
273 void  IGESAppli_ToolFlow::OwnCheck
274   (const Handle(IGESAppli_Flow)& ent,
275    const Interface_ShareTool& , Handle(Interface_Check)& ach) const
276 {
277   if (ent->NbContextFlags() != 2)
278     ach->AddFail("Number of Context Flags != 2");
279   if ((ent->TypeOfFlow() < 0) || (ent->TypeOfFlow() > 2))
280     ach->AddFail("Type of Flow != 0,1,2");
281   if ((ent->FunctionFlag() < 0) || (ent->FunctionFlag() > 2))
282     ach->AddFail("Function Flag != 0,1,2");
283 }
284
285 void  IGESAppli_ToolFlow::OwnDump
286   (const Handle(IGESAppli_Flow)& ent, const IGESData_IGESDumper& dumper,
287    const Handle(Message_Messenger)& S, const Standard_Integer level) const
288 {
289   S << "IGESAppli_Flow" << endl;
290   S << "Number of Context Flags : " << ent->NbContextFlags() << endl;
291   Standard_Integer tf = ent->TypeOfFlow();
292   S << "Type of Flow : " << tf;
293   if      (tf == 1) S << " (logical)" << endl;
294   else if (tf == 2) S << " (physical)" << endl;
295   else              S << " (not specified)" << endl;
296   tf = ent->FunctionFlag();
297   S << "Function Flag : " << tf;
298   if      (tf == 1) S << " (electrical signal)" << endl;
299   else if (tf == 2) S << " (fluid flow path)" << endl;
300   else              S << " (not specified)" << endl;
301   S << "Flow Associativities : ";
302   IGESData_DumpEntities(S,dumper ,level,1, ent->NbFlowAssociativities(),
303                         ent->FlowAssociativity);
304   S << endl << "Connect Points : ";
305   IGESData_DumpEntities(S,dumper ,level,1, ent->NbConnectPoints(),
306                         ent->ConnectPoint);
307   S << endl << "Joins : ";
308   IGESData_DumpEntities(S,dumper ,level,1, ent->NbJoins(),ent->Join);
309   S << endl << "Flow Names : ";
310   IGESData_DumpStrings(S ,level,1, ent->NbFlowNames(),ent->FlowName);
311   S << endl << "Text Display Templates : ";
312   IGESData_DumpEntities(S,dumper ,level,1, ent->NbTextDisplayTemplates(),
313                         ent->TextDisplayTemplate);
314   S << endl << "Continuation Flow Associativities : ";
315   IGESData_DumpEntities(S,dumper ,level,1, ent->NbContFlowAssociativities(),
316                         ent->ContFlowAssociativity);
317   S << endl;
318 }
319