0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / IGESDefs / IGESDefs_ToolUnitsData.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_ToolUnitsData.hxx>
27 #include <IGESDefs_UnitsData.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 #include <TColStd_HArray1OfReal.hxx>
38
39 IGESDefs_ToolUnitsData::IGESDefs_ToolUnitsData ()    {  }
40
41
42 void  IGESDefs_ToolUnitsData::ReadOwnParams
43   (const Handle(IGESDefs_UnitsData)& ent,
44    const Handle(IGESData_IGESReaderData)& /* IR */, IGESData_ParamReader& PR) const
45
46   //Standard_Boolean st; //szv#4:S4163:12Mar99 moved down
47
48   Standard_Integer nbval;
49   Handle(Interface_HArray1OfHAsciiString) unitTypes;
50   Handle(Interface_HArray1OfHAsciiString) unitValues;
51   Handle(TColStd_HArray1OfReal) unitScales;
52
53   Standard_Boolean st = PR.ReadInteger(PR.Current(), "Number of Units", nbval);
54   if (st && nbval > 0)
55     {
56       unitTypes = new Interface_HArray1OfHAsciiString(1, nbval); 
57       unitValues = new Interface_HArray1OfHAsciiString(1, nbval); 
58       unitScales = new TColStd_HArray1OfReal(1, nbval); 
59     }
60   else  PR.AddFail("Number of Units: Less than or Equal or zero");
61
62   if (! unitTypes.IsNull())
63     for (Standard_Integer i = 1; i <= nbval; i++)
64       {
65         Handle(TCollection_HAsciiString) unitType;
66         Handle(TCollection_HAsciiString) unitValue;
67         Standard_Real unitScale;
68
69         //st = PR.ReadText(PR.Current(), "Type of Unit", unitType); //szv#4:S4163:12Mar99 moved in if
70         if (PR.ReadText(PR.Current(), "Type of Unit", unitType))
71           unitTypes->SetValue(i, unitType);
72
73         //st = PR.ReadText(PR.Current(), "Value of Unit", unitValue); //szv#4:S4163:12Mar99 moved in if
74         if (PR.ReadText(PR.Current(), "Value of Unit", unitValue))
75           unitValues->SetValue(i, unitValue);
76
77         //st = PR.ReadReal(PR.Current(), "Scale of Unit", unitScale); //szv#4:S4163:12Mar99 moved in if
78         if (PR.ReadReal(PR.Current(), "Scale of Unit", unitScale))
79           unitScales->SetValue(i, unitScale);
80       }
81
82   DirChecker(ent).CheckTypeAndForm(PR.CCheck(),ent);
83   ent->Init(unitTypes, unitValues, unitScales);
84 }
85
86 void  IGESDefs_ToolUnitsData::WriteOwnParams
87   (const Handle(IGESDefs_UnitsData)& ent, IGESData_IGESWriter& IW) const 
88
89   Standard_Integer upper = ent->NbUnits();
90   IW.Send(upper);
91
92   for (Standard_Integer i = 1; i <= upper; i++)
93     {
94       IW.Send(ent->UnitType(i));
95       IW.Send(ent->UnitValue(i));
96       IW.Send(ent->ScaleFactor(i));
97     }
98 }
99
100 void  IGESDefs_ToolUnitsData::OwnShared
101   (const Handle(IGESDefs_UnitsData)& /* ent */, Interface_EntityIterator& /* iter */) const
102 {
103 }
104
105 void  IGESDefs_ToolUnitsData::OwnCopy
106   (const Handle(IGESDefs_UnitsData)& another,
107    const Handle(IGESDefs_UnitsData)& ent, Interface_CopyTool& /* TC */) const
108 {
109   Handle(Interface_HArray1OfHAsciiString) unitTypes;
110   Handle(Interface_HArray1OfHAsciiString) unitValues;
111   Handle(TColStd_HArray1OfReal) unitScales;
112
113   Standard_Integer nbval = another->NbUnits();
114
115   unitTypes  = new Interface_HArray1OfHAsciiString(1, nbval); 
116   unitValues = new Interface_HArray1OfHAsciiString(1, nbval); 
117   unitScales = new TColStd_HArray1OfReal(1, nbval); 
118
119   for (Standard_Integer i = 1; i <= nbval; i++)
120     {
121       Handle(TCollection_HAsciiString) unitType =
122         new TCollection_HAsciiString(another->UnitType(i));
123       unitTypes->SetValue(i, unitType);
124       Handle(TCollection_HAsciiString) unitValue =
125         new TCollection_HAsciiString(another->UnitValue(i));
126       unitValues->SetValue(i, unitValue);
127       Standard_Real unitScale = another->ScaleFactor(i);
128       unitScales->SetValue(i, unitScale);
129     }
130   ent->Init(unitTypes, unitValues, unitScales);
131 }
132
133 IGESData_DirChecker  IGESDefs_ToolUnitsData::DirChecker
134   (const Handle(IGESDefs_UnitsData)& /* ent */ ) const 
135
136   IGESData_DirChecker DC (316, 0);
137   DC.Structure(IGESData_DefVoid);
138   DC.LineFont(IGESData_DefVoid);
139   DC.LineWeight(IGESData_DefVoid);
140   DC.Color(IGESData_DefVoid);
141   DC.BlankStatusIgnored();
142   DC.SubordinateStatusRequired(0);
143   DC.UseFlagRequired(2);
144   DC.HierarchyStatusIgnored();
145   return DC;
146 }
147
148 void  IGESDefs_ToolUnitsData::OwnCheck
149   (const Handle(IGESDefs_UnitsData)& /* ent */,
150    const Interface_ShareTool& , Handle(Interface_Check)& /* ach */) const 
151 {
152 }
153
154 void  IGESDefs_ToolUnitsData::OwnDump
155   (const Handle(IGESDefs_UnitsData)& ent, const IGESData_IGESDumper& /* dumper */,
156    const Handle(Message_Messenger)& S, const Standard_Integer level) const 
157
158   S << "IGESDefs_UnitsData" << endl;
159   S << "Number of Units : " << ent->NbUnits() << endl;
160   S << "Type of Unit : " << endl;
161   S << "Value of Unit : " << endl;
162   S << "Scale Factor : " << endl;
163   IGESData_DumpStrings(S,-level,1, ent->NbUnits(),ent->UnitType);
164   S << endl;
165   if (level > 4)
166     {
167       S << "Details of the Units" << endl;
168       Standard_Integer upper = ent->NbUnits();
169       for (Standard_Integer i = 1; i <= upper; i++)
170         {
171           S << "[" << i << "] Type  : ";
172           IGESData_DumpString(S,ent->UnitType(i));
173           S << endl;
174           S << "     Value : ";
175           IGESData_DumpString(S,ent->UnitValue(i));
176           S << endl;
177           S << "     ScaleFactor: " << ent->ScaleFactor(i) << endl;
178         }
179     }
180   S << endl;
181 }