0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / IGESDefs / IGESDefs_ToolMacroDef.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 <IGESData_DirChecker.hxx>
20 #include <IGESData_Dump.hxx>
21 #include <IGESData_IGESDumper.hxx>
22 #include <IGESData_IGESReaderData.hxx>
23 #include <IGESData_IGESWriter.hxx>
24 #include <IGESData_ParamCursor.hxx>
25 #include <IGESData_ParamReader.hxx>
26 #include <IGESDefs_MacroDef.hxx>
27 #include <IGESDefs_ToolMacroDef.hxx>
28 #include <Interface_Check.hxx>
29 #include <Interface_CopyTool.hxx>
30 #include <Interface_EntityIterator.hxx>
31 #include <Interface_HArray1OfHAsciiString.hxx>
32 #include <Interface_Macros.hxx>
33 #include <Interface_ShareTool.hxx>
34 #include <Message_Messenger.hxx>
35 #include <Standard_DomainError.hxx>
36 #include <TCollection_HAsciiString.hxx>
37
38 IGESDefs_ToolMacroDef::IGESDefs_ToolMacroDef ()    {  }
39
40
41 void  IGESDefs_ToolMacroDef::ReadOwnParams
42   (const Handle(IGESDefs_MacroDef)& ent,
43    const Handle(IGESData_IGESReaderData)& /* IR */, IGESData_ParamReader& PR) const
44
45   //Standard_Boolean st; //szv#4:S4163:12Mar99 not needed
46
47   Handle(TCollection_HAsciiString) macro;
48   Standard_Integer entityTypeID;
49   Handle(Interface_HArray1OfHAsciiString) langStatements;
50   Handle(TCollection_HAsciiString) endMacro;
51
52   PR.ReadText(PR.Current(), "MACRO", macro); //szv#4:S4163:12Mar99 `st=` not needed
53
54   PR.ReadInteger(PR.Current(), "Entity Type ID", entityTypeID); //szv#4:S4163:12Mar99 `st=` not needed
55
56   Standard_Integer tempCurrent = PR.CurrentNumber();
57   // Counting the no. of language statements.
58   Standard_Integer nbval; // svv Jan 10 2000 : porting on DEC
59   for (nbval = 0; PR.CurrentNumber() != PR.NbParams();
60        nbval++, PR.SetCurrentNumber(PR.CurrentNumber() + 1));
61
62   PR.SetCurrentNumber(tempCurrent);
63   if (nbval > 0) langStatements =
64     new Interface_HArray1OfHAsciiString(1, nbval);
65   else  PR.AddFail("Number of Lang. Stats. : Not Positive");
66
67   if (! langStatements.IsNull())
68     {
69       for (Standard_Integer i = 1; i <= nbval; i++)
70         {
71           Handle(TCollection_HAsciiString) langStat;
72           //st = PR.ReadText(PR.Current(), "Language Statement", langStat); //szv#4:S4163:12Mar99 moved in if
73           if (PR.ReadText(PR.Current(), "Language Statement", langStat))
74             langStatements->SetValue(i, langStat);
75         }
76     }
77
78   PR.ReadText(PR.Current(), "END MACRO", endMacro); //szv#4:S4163:12Mar99 `st=` not needed
79
80   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
81   ent->Init (macro, entityTypeID, langStatements, endMacro);
82 }
83
84 void  IGESDefs_ToolMacroDef::WriteOwnParams
85   (const Handle(IGESDefs_MacroDef)& ent, IGESData_IGESWriter& IW) const 
86
87   IW.Send(ent->MACRO());
88   IW.Send(ent->EntityTypeID());
89   Standard_Integer upper = ent->NbStatements();
90   for (Standard_Integer i = 1; i <= upper; i++)
91     IW.Send(ent->LanguageStatement(i));
92   IW.Send(ent->ENDMACRO());
93 }
94
95 void  IGESDefs_ToolMacroDef::OwnShared
96   (const Handle(IGESDefs_MacroDef)& /* ent */, Interface_EntityIterator& /* iter */) const
97 {
98 }
99
100 void  IGESDefs_ToolMacroDef::OwnCopy
101   (const Handle(IGESDefs_MacroDef)& another,
102    const Handle(IGESDefs_MacroDef)& ent, Interface_CopyTool& /* TC */) const
103
104
105   Handle(TCollection_HAsciiString) macro =
106     new TCollection_HAsciiString(another->MACRO());
107   Standard_Integer entityTypeID = another->EntityTypeID();
108   Handle(TCollection_HAsciiString) endMacro =
109     new TCollection_HAsciiString(another->ENDMACRO());
110   Handle(Interface_HArray1OfHAsciiString) langStatements;
111   Standard_Integer nbval = another->NbStatements();
112   langStatements = new Interface_HArray1OfHAsciiString(1, nbval);
113
114   for (Standard_Integer i = 1; i <= nbval; i++)
115     {
116       Handle(TCollection_HAsciiString) langStat =
117         new TCollection_HAsciiString(another->LanguageStatement(i));
118       langStatements->SetValue(i, langStat);
119     }
120   ent->Init(macro, entityTypeID, langStatements, endMacro);
121 }
122
123 IGESData_DirChecker  IGESDefs_ToolMacroDef::DirChecker
124   (const Handle(IGESDefs_MacroDef)& /* ent */ ) const 
125
126   IGESData_DirChecker DC (306, 0);
127   DC.Structure(IGESData_DefVoid);
128   DC.LineFont(IGESData_DefVoid);
129   DC.LineWeight(IGESData_DefVoid);
130   DC.Color(IGESData_DefVoid);
131   DC.BlankStatusIgnored();
132   DC.SubordinateStatusRequired(0);
133   DC.UseFlagRequired(2);
134   DC.HierarchyStatusIgnored();
135   return DC;
136 }
137
138 void  IGESDefs_ToolMacroDef::OwnCheck
139   (const Handle(IGESDefs_MacroDef)& /* ent */,
140    const Interface_ShareTool& , Handle(Interface_Check)& /* ach */) const 
141 {
142 }
143
144 void  IGESDefs_ToolMacroDef::OwnDump
145   (const Handle(IGESDefs_MacroDef)& ent, const IGESData_IGESDumper& /* dumper */,
146    Standard_OStream& S, const Standard_Integer level) const 
147
148   S << "IGESDefs_MacroDef\n"
149     << "MACRO : ";
150   IGESData_DumpString(S,ent->MACRO());
151   S << "\n"
152     << "Entity Type ID : " << ent->EntityTypeID() << "\n"
153     << "Language Statement : ";
154   IGESData_DumpStrings(S,level,1, ent->NbStatements(),ent->LanguageStatement);
155   S << "END MACRO : ";
156   IGESData_DumpString(S,ent->ENDMACRO());
157   S << std::endl;
158 }