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